@@ -14,6 +14,7 @@ import (
14
14
"github.com/pkg/errors"
15
15
tsuruErrors "github.com/tsuru/tsuru/errors"
16
16
"github.com/tsuru/tsuru/provision"
17
+ provTypes "github.com/tsuru/tsuru/types/provision"
17
18
appsv1 "k8s.io/api/apps/v1"
18
19
autoscalingv1 "k8s.io/api/autoscaling/v1"
19
20
autoscalingv2 "k8s.io/api/autoscaling/v2"
@@ -32,7 +33,7 @@ const (
32
33
33
34
var errNoDeploy = errors .New ("no routable version found for app, at least one deploy is required before configuring autoscale" )
34
35
35
- func (p * kubernetesProvisioner ) GetVerticalAutoScaleRecommendations (ctx context.Context , a provision.App ) ([]provision .RecommendedResources , error ) {
36
+ func (p * kubernetesProvisioner ) GetVerticalAutoScaleRecommendations (ctx context.Context , a provision.App ) ([]provTypes .RecommendedResources , error ) {
36
37
client , err := clusterForPool (ctx , a .GetPool ())
37
38
if err != nil {
38
39
return nil , err
@@ -74,16 +75,16 @@ func (p *kubernetesProvisioner) GetVerticalAutoScaleRecommendations(ctx context.
74
75
return nil , errors .WithStack (err )
75
76
}
76
77
77
- var specs []provision .RecommendedResources
78
+ var specs []provTypes .RecommendedResources
78
79
for _ , vpa := range vpas {
79
80
specs = append (specs , vpaToRecommended (* vpa ))
80
81
}
81
82
return specs , nil
82
83
}
83
84
84
- func vpaToRecommended (vpa vpav1.VerticalPodAutoscaler ) provision .RecommendedResources {
85
+ func vpaToRecommended (vpa vpav1.VerticalPodAutoscaler ) provTypes .RecommendedResources {
85
86
ls := labelSetFromMeta (& vpa .ObjectMeta )
86
- rec := provision .RecommendedResources {
87
+ rec := provTypes .RecommendedResources {
87
88
Process : ls .AppProcess (),
88
89
}
89
90
if vpa .Status .Recommendation == nil {
@@ -93,22 +94,22 @@ func vpaToRecommended(vpa vpav1.VerticalPodAutoscaler) provision.RecommendedReso
93
94
if contRec .ContainerName != vpa .Name {
94
95
continue
95
96
}
96
- rec .Recommendations = append (rec .Recommendations , provision .RecommendedProcessResources {
97
+ rec .Recommendations = append (rec .Recommendations , provTypes .RecommendedProcessResources {
97
98
Type : "target" ,
98
99
CPU : contRec .Target .Cpu ().String (),
99
100
Memory : contRec .Target .Memory ().String (),
100
101
})
101
- rec .Recommendations = append (rec .Recommendations , provision .RecommendedProcessResources {
102
+ rec .Recommendations = append (rec .Recommendations , provTypes .RecommendedProcessResources {
102
103
Type : "uncappedTarget" ,
103
104
CPU : contRec .UncappedTarget .Cpu ().String (),
104
105
Memory : contRec .UncappedTarget .Memory ().String (),
105
106
})
106
- rec .Recommendations = append (rec .Recommendations , provision .RecommendedProcessResources {
107
+ rec .Recommendations = append (rec .Recommendations , provTypes .RecommendedProcessResources {
107
108
Type : "lowerBound" ,
108
109
CPU : contRec .LowerBound .Cpu ().String (),
109
110
Memory : contRec .LowerBound .Memory ().String (),
110
111
})
111
- rec .Recommendations = append (rec .Recommendations , provision .RecommendedProcessResources {
112
+ rec .Recommendations = append (rec .Recommendations , provTypes .RecommendedProcessResources {
112
113
Type : "upperBound" ,
113
114
CPU : contRec .UpperBound .Cpu ().String (),
114
115
Memory : contRec .UpperBound .Memory ().String (),
@@ -117,7 +118,7 @@ func vpaToRecommended(vpa vpav1.VerticalPodAutoscaler) provision.RecommendedReso
117
118
return rec
118
119
}
119
120
120
- func (p * kubernetesProvisioner ) GetAutoScale (ctx context.Context , a provision.App ) ([]provision .AutoScaleSpec , error ) {
121
+ func (p * kubernetesProvisioner ) GetAutoScale (ctx context.Context , a provision.App ) ([]provTypes .AutoScaleSpec , error ) {
121
122
client , err := clusterForPool (ctx , a .GetPool ())
122
123
if err != nil {
123
124
return nil , err
@@ -153,7 +154,7 @@ func (p *kubernetesProvisioner) GetAutoScale(ctx context.Context, a provision.Ap
153
154
return nil , err
154
155
}
155
156
156
- var specs []provision .AutoScaleSpec
157
+ var specs []provTypes .AutoScaleSpec
157
158
158
159
hpas , err := hpaInformer .Lister ().HorizontalPodAutoscalers (ns ).List (labels .SelectorFromSet (labels .Set (ls .ToHPASelector ())))
159
160
if err != nil {
@@ -179,9 +180,9 @@ func kedaScaledObjectName(hpa autoscalingv2.HorizontalPodAutoscaler) string {
179
180
return hpa .Labels ["scaledobject.keda.sh/name" ]
180
181
}
181
182
182
- func scaledObjectToSpec (scaledObject kedav1alpha1.ScaledObject ) provision .AutoScaleSpec {
183
+ func scaledObjectToSpec (scaledObject kedav1alpha1.ScaledObject ) provTypes .AutoScaleSpec {
183
184
ls := labelSetFromMeta (& scaledObject .ObjectMeta )
184
- spec := provision .AutoScaleSpec {
185
+ spec := provTypes .AutoScaleSpec {
185
186
MaxUnits : uint (* scaledObject .Spec .MaxReplicaCount ),
186
187
MinUnits : uint (* scaledObject .Spec .MinReplicaCount ),
187
188
Process : ls .AppProcess (),
@@ -192,7 +193,7 @@ func scaledObjectToSpec(scaledObject kedav1alpha1.ScaledObject) provision.AutoSc
192
193
if metric .Type == "cron" {
193
194
minReplicas , _ := strconv .Atoi (metric .Metadata ["desiredReplicas" ])
194
195
195
- spec .Schedules = append (spec .Schedules , provision .AutoScaleSchedule {
196
+ spec .Schedules = append (spec .Schedules , provTypes .AutoScaleSchedule {
196
197
MinReplicas : minReplicas ,
197
198
Start : metric .Metadata ["start" ],
198
199
End : metric .Metadata ["end" ],
@@ -213,9 +214,9 @@ func scaledObjectToSpec(scaledObject kedav1alpha1.ScaledObject) provision.AutoSc
213
214
return spec
214
215
}
215
216
216
- func hpaToSpec (hpa autoscalingv2.HorizontalPodAutoscaler ) provision .AutoScaleSpec {
217
+ func hpaToSpec (hpa autoscalingv2.HorizontalPodAutoscaler ) provTypes .AutoScaleSpec {
217
218
ls := labelSetFromMeta (& hpa .ObjectMeta )
218
- spec := provision .AutoScaleSpec {
219
+ spec := provTypes .AutoScaleSpec {
219
220
MaxUnits : uint (hpa .Spec .MaxReplicas ),
220
221
Process : ls .AppProcess (),
221
222
Version : ls .AppVersion (),
@@ -316,15 +317,15 @@ func removeKEDAScaleObject(ctx context.Context, client *ClusterClient, ns string
316
317
return nil
317
318
}
318
319
319
- func (p * kubernetesProvisioner ) SetAutoScale (ctx context.Context , a provision.App , spec provision .AutoScaleSpec ) error {
320
+ func (p * kubernetesProvisioner ) SetAutoScale (ctx context.Context , a provision.App , spec provTypes .AutoScaleSpec ) error {
320
321
client , err := clusterForPool (ctx , a .GetPool ())
321
322
if err != nil {
322
323
return err
323
324
}
324
325
return setAutoScale (ctx , client , a , spec )
325
326
}
326
327
327
- func setAutoScale (ctx context.Context , client * ClusterClient , a provision.App , spec provision .AutoScaleSpec ) error {
328
+ func setAutoScale (ctx context.Context , client * ClusterClient , a provision.App , spec provTypes .AutoScaleSpec ) error {
328
329
depInfo , err := minimumAutoScaleVersion (ctx , client , a , spec .Process )
329
330
if err != nil {
330
331
return err
@@ -356,7 +357,7 @@ func setAutoScale(ctx context.Context, client *ClusterClient, a provision.App, s
356
357
357
358
minUnits := int32 (spec .MinUnits )
358
359
359
- cpuValue , err := spec . ToCPUValue ( a )
360
+ cpuValue , err := provision . CPUValueOfAutoScaleSpec ( & spec , a )
360
361
if err != nil {
361
362
return errors .WithStack (err )
362
363
}
@@ -433,7 +434,7 @@ func setAutoScale(ctx context.Context, client *ClusterClient, a provision.App, s
433
434
return nil
434
435
}
435
436
436
- func setKEDAAutoscale (ctx context.Context , client * ClusterClient , spec provision .AutoScaleSpec , a provision.App , depInfo * deploymentInfo , hpaName string , labels * provision.LabelSet ) error {
437
+ func setKEDAAutoscale (ctx context.Context , client * ClusterClient , spec provTypes .AutoScaleSpec , a provision.App , depInfo * deploymentInfo , hpaName string , labels * provision.LabelSet ) error {
437
438
kedaClient , err := KEDAClientForConfig (client .restConfig )
438
439
if err != nil {
439
440
return err
@@ -469,11 +470,11 @@ func setKEDAAutoscale(ctx context.Context, client *ClusterClient, spec provision
469
470
return err
470
471
}
471
472
472
- func newKEDAScaledObject (ctx context.Context , spec provision .AutoScaleSpec , a provision.App , depInfo * deploymentInfo , ns string , hpaName string , labels * provision.LabelSet ) (* kedav1alpha1.ScaledObject , error ) {
473
+ func newKEDAScaledObject (ctx context.Context , spec provTypes .AutoScaleSpec , a provision.App , depInfo * deploymentInfo , ns string , hpaName string , labels * provision.LabelSet ) (* kedav1alpha1.ScaledObject , error ) {
473
474
kedaTriggers := []kedav1alpha1.ScaleTriggers {}
474
475
475
476
if spec .AverageCPU != "" {
476
- cpu , err := spec . ToCPUValue ( a )
477
+ cpu , err := provision . CPUValueOfAutoScaleSpec ( & spec , a )
477
478
if err != nil {
478
479
return nil , err
479
480
}
@@ -743,7 +744,7 @@ func ensureHPA(ctx context.Context, client *ClusterClient, a provision.App, proc
743
744
return multiErr .ToError ()
744
745
}
745
746
746
- func getAutoScale (ctx context.Context , client * ClusterClient , a provision.App , process string ) ([]provision .AutoScaleSpec , error ) {
747
+ func getAutoScale (ctx context.Context , client * ClusterClient , a provision.App , process string ) ([]provTypes .AutoScaleSpec , error ) {
747
748
ns , err := client .AppNamespace (ctx , a )
748
749
if err != nil {
749
750
return nil , err
@@ -768,7 +769,7 @@ func getAutoScale(ctx context.Context, client *ClusterClient, a provision.App, p
768
769
return nil , errors .WithStack (err )
769
770
}
770
771
771
- var specs []provision .AutoScaleSpec
772
+ var specs []provTypes .AutoScaleSpec
772
773
for _ , hpa := range hpas .Items {
773
774
scaledObjectName := kedaScaledObjectName (hpa )
774
775
if scaledObjectName != "" {
0 commit comments