diff --git a/api/v1beta1/testdata/validating/hpa-specified-but-no-horizontal/deployment.yaml b/api/v1beta1/testdata/validating/hpa-specified-but-no-horizontal/deployment.yaml new file mode 100644 index 00000000..d431d7f5 --- /dev/null +++ b/api/v1beta1/testdata/validating/hpa-specified-but-no-horizontal/deployment.yaml @@ -0,0 +1,26 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: sample + namespace: default + labels: + app: nginx +spec: + replicas: 3 + selector: + matchLabels: + app: nginx + template: + metadata: + labels: + app: nginx + spec: + containers: + - name: istio-proxy + image: istio-proxy:1.0.0 + ports: + - containerPort: 81 + - name: nginx + image: nginx:1.14.2 + ports: + - containerPort: 80 \ No newline at end of file diff --git a/api/v1beta1/testdata/validating/hpa-specified-but-no-horizontal/hpa.yaml b/api/v1beta1/testdata/validating/hpa-specified-but-no-horizontal/hpa.yaml new file mode 100644 index 00000000..f5695111 --- /dev/null +++ b/api/v1beta1/testdata/validating/hpa-specified-but-no-horizontal/hpa.yaml @@ -0,0 +1,12 @@ +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: sample + namespace: default +spec: + maxReplicas: 10 + minReplicas: 3 + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: sample \ No newline at end of file diff --git a/api/v1beta1/testdata/validating/hpa-specified-but-no-horizontal/tortoise.yaml b/api/v1beta1/testdata/validating/hpa-specified-but-no-horizontal/tortoise.yaml new file mode 100644 index 00000000..df9955bf --- /dev/null +++ b/api/v1beta1/testdata/validating/hpa-specified-but-no-horizontal/tortoise.yaml @@ -0,0 +1,23 @@ +apiVersion: autoscaling.mercari.com/v1beta1 +kind: Tortoise +metadata: + name: tortoise-sample + namespace: default +spec: + updateMode: "Off" + deletionPolicy: "DeleteAll" + targetRefs: + # All vertical, but HPA is specified. + horizontalPodAutoscalerName: sample + scaleTargetRef: + kind: Deployment + name: sample + resourcePolicy: + - containerName: istio-proxy + autoscalingPolicy: + cpu: Vertical + memory: Vertical + - containerName: nginx + autoscalingPolicy: + cpu: Vertical + memory: Vertical \ No newline at end of file diff --git a/api/v1beta1/tortoise_types.go b/api/v1beta1/tortoise_types.go index 524c98de..9855600c 100644 --- a/api/v1beta1/tortoise_types.go +++ b/api/v1beta1/tortoise_types.go @@ -150,7 +150,8 @@ type TortoiseStatus struct { } type TargetsStatus struct { - HorizontalPodAutoscaler string `json:"horizontalPodAutoscaler" protobuf:"bytes,1,name=horizontalPodAutoscaler"` + // +optional + HorizontalPodAutoscaler string `json:"horizontalPodAutoscaler" protobuf:"bytes,1,opt,name=horizontalPodAutoscaler"` Deployment string `json:"deployment" protobuf:"bytes,2,name=deployment"` VerticalPodAutoscalers []TargetStatusVerticalPodAutoscaler `json:"verticalPodAutoscalers" protobuf:"bytes,3,name=verticalPodAutoscalers"` } diff --git a/api/v1beta1/tortoise_webhook.go b/api/v1beta1/tortoise_webhook.go index 98638f80..0163fed0 100644 --- a/api/v1beta1/tortoise_webhook.go +++ b/api/v1beta1/tortoise_webhook.go @@ -119,6 +119,17 @@ func (r *Tortoise) Default() { var _ webhook.Validator = &Tortoise{} +func hasHorizontal(tortoise *Tortoise) bool { + for _, r := range tortoise.Spec.ResourcePolicy { + for _, p := range r.AutoscalingPolicy { + if p == AutoscalingTypeHorizontal { + return true + } + } + } + return false +} + func validateTortoise(t *Tortoise) error { fieldPath := field.NewPath("spec") @@ -129,20 +140,16 @@ func validateTortoise(t *Tortoise) error { return fmt.Errorf("%s: shouldn't be empty", fieldPath.Child("targetRefs", "scaleTargetRef", "kind")) } - for _, p := range t.Spec.ResourcePolicy { - for _, ap := range p.AutoscalingPolicy { - if ap == AutoscalingTypeHorizontal { - return nil - } - } - } - if t.Spec.UpdateMode == UpdateModeEmergency && t.Status.TortoisePhase != TortoisePhaseWorking && t.Status.TortoisePhase != TortoisePhaseEmergency && t.Status.TortoisePhase != TortoisePhaseBackToNormal { return fmt.Errorf("%s: emergency mode is only available for tortoises with Running phase", fieldPath.Child("updateMode")) } - return fmt.Errorf("%s: at least one policy should be Horizontal", fieldPath.Child("resourcePolicy", "autoscalingPolicy")) + if !hasHorizontal(t) && t.Spec.TargetRefs.HorizontalPodAutoscalerName != nil { + return fmt.Errorf("%s: at least one policy should be Horizontal when HorizontalPodAutoscalerName isn't nil", fieldPath.Child("resourcePolicy", "autoscalingPolicy")) + } + + return nil } type resourceNameAndContainerName struct { diff --git a/api/v1beta1/tortoise_webhook_test.go b/api/v1beta1/tortoise_webhook_test.go index b66308b4..1d94f224 100644 --- a/api/v1beta1/tortoise_webhook_test.go +++ b/api/v1beta1/tortoise_webhook_test.go @@ -150,5 +150,8 @@ var _ = Describe("MarkdownTortoise Webhook", func() { It("invalid: Tortoise has resource policy for non-existing container", func() { validateTest(filepath.Join("testdata", "validating", "useless-policy", "tortoise.yaml"), filepath.Join("testdata", "validating", "useless-policy", "hpa.yaml"), filepath.Join("testdata", "validating", "useless-policy", "deployment.yaml"), false) }) + It("invalid: Tortoise has HPA specified, but no Horizoltal in autoscalingPolicy", func() { + validateTest(filepath.Join("testdata", "validating", "hpa-specified-but-no-horizontal", "tortoise.yaml"), filepath.Join("testdata", "validating", "hpa-specified-but-no-horizontal", "hpa.yaml"), filepath.Join("testdata", "validating", "hpa-specified-but-no-horizontal", "deployment.yaml"), false) + }) }) }) diff --git a/config/crd/bases/autoscaling.mercari.com_tortoises.yaml b/config/crd/bases/autoscaling.mercari.com_tortoises.yaml index 36a86199..da82a056 100644 --- a/config/crd/bases/autoscaling.mercari.com_tortoises.yaml +++ b/config/crd/bases/autoscaling.mercari.com_tortoises.yaml @@ -731,7 +731,6 @@ spec: type: array required: - deployment - - horizontalPodAutoscaler - verticalPodAutoscalers type: object tortoisePhase: diff --git a/controllers/testdata/deletion-no-delete/before/deployment.yaml b/controllers/testdata/deletion-no-delete/before/deployment.yaml index 1f21e1e3..04ac49e3 100644 --- a/controllers/testdata/deletion-no-delete/before/deployment.yaml +++ b/controllers/testdata/deletion-no-delete/before/deployment.yaml @@ -1,5 +1,4 @@ metadata: - creationTimestamp: null name: mercari-app namespace: default spec: diff --git a/controllers/testdata/deletion-no-delete/before/hpa.yaml b/controllers/testdata/deletion-no-delete/before/hpa.yaml index f76e1169..d4c64cb0 100644 --- a/controllers/testdata/deletion-no-delete/before/hpa.yaml +++ b/controllers/testdata/deletion-no-delete/before/hpa.yaml @@ -2,7 +2,6 @@ metadata: annotations: tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" tortoises.autoscaling.mercari.com/tortoise-name: mercari - creationTimestamp: null name: tortoise-hpa-mercari namespace: default spec: diff --git a/controllers/testdata/deletion-no-delete/before/tortoise.yaml b/controllers/testdata/deletion-no-delete/before/tortoise.yaml index 22ae9abf..0cf9c64c 100644 --- a/controllers/testdata/deletion-no-delete/before/tortoise.yaml +++ b/controllers/testdata/deletion-no-delete/before/tortoise.yaml @@ -1,5 +1,4 @@ metadata: - creationTimestamp: null name: mercari namespace: default spec: diff --git a/controllers/testdata/deletion-no-delete/before/vpa-Monitor.yaml b/controllers/testdata/deletion-no-delete/before/vpa-Monitor.yaml index 8c1b0494..73acfb27 100644 --- a/controllers/testdata/deletion-no-delete/before/vpa-Monitor.yaml +++ b/controllers/testdata/deletion-no-delete/before/vpa-Monitor.yaml @@ -2,7 +2,6 @@ metadata: annotations: tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" tortoises.autoscaling.mercari.com/tortoise-name: mercari - creationTimestamp: null name: tortoise-monitor-mercari namespace: default spec: diff --git a/controllers/testdata/deletion-no-delete/before/vpa-Updater.yaml b/controllers/testdata/deletion-no-delete/before/vpa-Updater.yaml index a1f72d46..28c9ee17 100644 --- a/controllers/testdata/deletion-no-delete/before/vpa-Updater.yaml +++ b/controllers/testdata/deletion-no-delete/before/vpa-Updater.yaml @@ -2,7 +2,6 @@ metadata: annotations: tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" tortoises.autoscaling.mercari.com/tortoise-name: mercari - creationTimestamp: null name: tortoise-updater-mercari namespace: default spec: diff --git a/controllers/testdata/deletion-policy-all/before/deployment.yaml b/controllers/testdata/deletion-policy-all/before/deployment.yaml index 1f21e1e3..04ac49e3 100644 --- a/controllers/testdata/deletion-policy-all/before/deployment.yaml +++ b/controllers/testdata/deletion-policy-all/before/deployment.yaml @@ -1,5 +1,4 @@ metadata: - creationTimestamp: null name: mercari-app namespace: default spec: diff --git a/controllers/testdata/deletion-policy-all/before/hpa.yaml b/controllers/testdata/deletion-policy-all/before/hpa.yaml index f76e1169..d4c64cb0 100644 --- a/controllers/testdata/deletion-policy-all/before/hpa.yaml +++ b/controllers/testdata/deletion-policy-all/before/hpa.yaml @@ -2,7 +2,6 @@ metadata: annotations: tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" tortoises.autoscaling.mercari.com/tortoise-name: mercari - creationTimestamp: null name: tortoise-hpa-mercari namespace: default spec: diff --git a/controllers/testdata/deletion-policy-all/before/tortoise.yaml b/controllers/testdata/deletion-policy-all/before/tortoise.yaml index 165814b9..8e22483e 100644 --- a/controllers/testdata/deletion-policy-all/before/tortoise.yaml +++ b/controllers/testdata/deletion-policy-all/before/tortoise.yaml @@ -1,5 +1,4 @@ metadata: - creationTimestamp: null name: mercari namespace: default spec: diff --git a/controllers/testdata/deletion-policy-all/before/vpa-Monitor.yaml b/controllers/testdata/deletion-policy-all/before/vpa-Monitor.yaml index 8c1b0494..73acfb27 100644 --- a/controllers/testdata/deletion-policy-all/before/vpa-Monitor.yaml +++ b/controllers/testdata/deletion-policy-all/before/vpa-Monitor.yaml @@ -2,7 +2,6 @@ metadata: annotations: tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" tortoises.autoscaling.mercari.com/tortoise-name: mercari - creationTimestamp: null name: tortoise-monitor-mercari namespace: default spec: diff --git a/controllers/testdata/deletion-policy-all/before/vpa-Updater.yaml b/controllers/testdata/deletion-policy-all/before/vpa-Updater.yaml index a1f72d46..28c9ee17 100644 --- a/controllers/testdata/deletion-policy-all/before/vpa-Updater.yaml +++ b/controllers/testdata/deletion-policy-all/before/vpa-Updater.yaml @@ -2,7 +2,6 @@ metadata: annotations: tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" tortoises.autoscaling.mercari.com/tortoise-name: mercari - creationTimestamp: null name: tortoise-updater-mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-off/after/hpa.yaml b/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-off/after/hpa.yaml index 437c5ae0..e9283d94 100644 --- a/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-off/after/hpa.yaml +++ b/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-off/after/hpa.yaml @@ -2,7 +2,6 @@ metadata: annotations: tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" tortoises.autoscaling.mercari.com/tortoise-name: mercari - creationTimestamp: null name: tortoise-hpa-mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-off/after/tortoise.yaml b/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-off/after/tortoise.yaml index 873780cd..4bd71e66 100644 --- a/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-off/after/tortoise.yaml +++ b/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-off/after/tortoise.yaml @@ -1,5 +1,4 @@ metadata: - creationTimestamp: null name: mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-off/after/vpa-Monitor.yaml b/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-off/after/vpa-Monitor.yaml index 8c1b0494..73acfb27 100644 --- a/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-off/after/vpa-Monitor.yaml +++ b/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-off/after/vpa-Monitor.yaml @@ -2,7 +2,6 @@ metadata: annotations: tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" tortoises.autoscaling.mercari.com/tortoise-name: mercari - creationTimestamp: null name: tortoise-monitor-mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-off/after/vpa-Updater.yaml b/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-off/after/vpa-Updater.yaml index 2fde5a6a..940dc36c 100644 --- a/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-off/after/vpa-Updater.yaml +++ b/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-off/after/vpa-Updater.yaml @@ -2,7 +2,6 @@ metadata: annotations: tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" tortoises.autoscaling.mercari.com/tortoise-name: mercari - creationTimestamp: null name: tortoise-updater-mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-off/before/deployment.yaml b/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-off/before/deployment.yaml index 1f21e1e3..04ac49e3 100644 --- a/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-off/before/deployment.yaml +++ b/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-off/before/deployment.yaml @@ -1,5 +1,4 @@ metadata: - creationTimestamp: null name: mercari-app namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-off/before/hpa.yaml b/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-off/before/hpa.yaml index 437c5ae0..e9283d94 100644 --- a/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-off/before/hpa.yaml +++ b/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-off/before/hpa.yaml @@ -2,7 +2,6 @@ metadata: annotations: tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" tortoises.autoscaling.mercari.com/tortoise-name: mercari - creationTimestamp: null name: tortoise-hpa-mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-off/before/tortoise.yaml b/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-off/before/tortoise.yaml index b3a373b9..bf5306f8 100644 --- a/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-off/before/tortoise.yaml +++ b/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-off/before/tortoise.yaml @@ -1,5 +1,4 @@ metadata: - creationTimestamp: null name: mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-off/before/vpa-Monitor.yaml b/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-off/before/vpa-Monitor.yaml index 8c1b0494..73acfb27 100644 --- a/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-off/before/vpa-Monitor.yaml +++ b/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-off/before/vpa-Monitor.yaml @@ -2,7 +2,6 @@ metadata: annotations: tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" tortoises.autoscaling.mercari.com/tortoise-name: mercari - creationTimestamp: null name: tortoise-monitor-mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-off/before/vpa-Updater.yaml b/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-off/before/vpa-Updater.yaml index a1f72d46..28c9ee17 100644 --- a/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-off/before/vpa-Updater.yaml +++ b/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-off/before/vpa-Updater.yaml @@ -2,7 +2,6 @@ metadata: annotations: tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" tortoises.autoscaling.mercari.com/tortoise-name: mercari - creationTimestamp: null name: tortoise-updater-mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-vertical/after/tortoise.yaml b/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-vertical/after/tortoise.yaml new file mode 100644 index 00000000..5978faa0 --- /dev/null +++ b/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-vertical/after/tortoise.yaml @@ -0,0 +1,89 @@ +metadata: + name: mercari + namespace: default +spec: + resourcePolicy: + - autoscalingPolicy: + cpu: "Vertical" + memory: "Vertical" + containerName: app + - autoscalingPolicy: + cpu: "Vertical" + memory: "Vertical" + containerName: istio-proxy + targetRefs: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: mercari-app +status: + conditions: + containerRecommendationFromVPA: + - containerName: app + maxRecommendation: + cpu: + quantity: "3" + updatedAt: null + memory: + quantity: 3Gi + updatedAt: null + recommendation: + cpu: + quantity: "3" + updatedAt: null + memory: + quantity: 3Gi + updatedAt: null + - containerName: istio-proxy + maxRecommendation: + cpu: + quantity: "3" + updatedAt: null + memory: + quantity: 3Gi + updatedAt: null + recommendation: + cpu: + quantity: "3" + updatedAt: null + memory: + quantity: 3Gi + updatedAt: null + tortoiseConditions: null + recommendations: + horizontal: + maxReplicas: + - from: 0 + timezone: Local + to: 24 + updatedAt: "2023-10-06T01:15:47Z" + value: 20 + minReplicas: + - from: 0 + timezone: Local + to: 24 + updatedAt: "2023-10-06T01:15:47Z" + value: 5 + targetUtilizations: + - containerName: app + targetUtilization: {} + - containerName: istio-proxy + targetUtilization: {} + vertical: + containerResourceRecommendation: + - RecommendedResource: + cpu: "3" + memory: 3Gi + containerName: app + - RecommendedResource: + cpu: "3" + memory: 3Gi + containerName: istio-proxy + targets: + deployment: "" + verticalPodAutoscalers: + - name: tortoise-updater-mercari + role: Updater + - name: tortoise-monitor-mercari + role: Monitor + tortoisePhase: Working diff --git a/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-vertical/after/vpa-Monitor.yaml b/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-vertical/after/vpa-Monitor.yaml new file mode 100644 index 00000000..73acfb27 --- /dev/null +++ b/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-vertical/after/vpa-Monitor.yaml @@ -0,0 +1,44 @@ +metadata: + annotations: + tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" + tortoises.autoscaling.mercari.com/tortoise-name: mercari + name: tortoise-monitor-mercari + namespace: default +spec: + resourcePolicy: + containerPolicies: + - containerName: app + - containerName: istio-proxy + targetRef: + apiVersion: apps/v1 + kind: Deployment + name: mercari-app + updatePolicy: + updateMode: "Off" +status: + conditions: + - lastTransitionTime: null + status: "True" + type: RecommendationProvided + recommendation: + containerRecommendations: + - containerName: app + lowerBound: + cpu: "3" + memory: 3Gi + target: + cpu: "3" + memory: 3Gi + upperBound: + cpu: "5" + memory: 5Gi + - containerName: istio-proxy + lowerBound: + cpu: "3" + memory: 3Gi + target: + cpu: "3" + memory: 3Gi + upperBound: + cpu: "5" + memory: 5Gi diff --git a/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-vertical/after/vpa-Updater.yaml b/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-vertical/after/vpa-Updater.yaml new file mode 100644 index 00000000..858222f9 --- /dev/null +++ b/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-vertical/after/vpa-Updater.yaml @@ -0,0 +1,48 @@ +metadata: + annotations: + tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" + tortoises.autoscaling.mercari.com/tortoise-name: mercari + name: tortoise-updater-mercari + namespace: default +spec: + recommenders: + - name: tortoise-controller + resourcePolicy: + containerPolicies: + - containerName: app + - containerName: istio-proxy + targetRef: + apiVersion: apps/v1 + kind: Deployment + name: mercari-app + updatePolicy: + updateMode: Auto +status: + recommendation: + containerRecommendations: + - containerName: app + lowerBound: + cpu: "3" + memory: 3Gi + target: + cpu: "3" + memory: 3Gi + uncappedTarget: + cpu: "3" + memory: 3Gi + upperBound: + cpu: "3" + memory: 3Gi + - containerName: istio-proxy + lowerBound: + cpu: "3" + memory: 3Gi + target: + cpu: "3" + memory: 3Gi + uncappedTarget: + cpu: "3" + memory: 3Gi + upperBound: + cpu: "3" + memory: 3Gi diff --git a/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-vertical/before/deployment.yaml b/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-vertical/before/deployment.yaml new file mode 100644 index 00000000..04ac49e3 --- /dev/null +++ b/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-vertical/before/deployment.yaml @@ -0,0 +1,29 @@ +metadata: + name: mercari-app + namespace: default +spec: + selector: + matchLabels: + app: mercari + strategy: {} + template: + metadata: + creationTimestamp: null + labels: + app: mercari + spec: + containers: + - image: awesome-mercari-app-image + name: app + resources: + requests: + cpu: "10" + memory: 10Gi + - image: awesome-istio-proxy-image + name: istio-proxy + resources: + requests: + cpu: "4" + memory: 4Gi +status: + replicas: 10 diff --git a/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-vertical/before/tortoise.yaml b/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-vertical/before/tortoise.yaml new file mode 100644 index 00000000..078c6ed6 --- /dev/null +++ b/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-vertical/before/tortoise.yaml @@ -0,0 +1,81 @@ +metadata: + name: mercari + namespace: default +spec: + resourcePolicy: + - autoscalingPolicy: + cpu: "Vertical" + memory: "Vertical" + containerName: app + - autoscalingPolicy: + cpu: "Vertical" + memory: "Vertical" + containerName: istio-proxy + targetRefs: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: mercari-app +status: + conditions: + containerRecommendationFromVPA: + - containerName: app + maxRecommendation: + cpu: + quantity: "0" + updatedAt: null + memory: + quantity: "0" + updatedAt: null + recommendation: + cpu: + quantity: "0" + updatedAt: null + memory: + quantity: "0" + updatedAt: null + - containerName: istio-proxy + maxRecommendation: + cpu: + quantity: "0" + updatedAt: null + memory: + quantity: "0" + updatedAt: null + recommendation: + cpu: + quantity: "0" + updatedAt: null + memory: + quantity: "0" + updatedAt: null + tortoiseConditions: null + recommendations: + horizontal: + maxReplicas: + - from: 0 + timezone: Local + to: 24 + updatedAt: "2023-10-06T01:15:47Z" + value: 15 + minReplicas: + - from: 0 + timezone: Local + to: 24 + updatedAt: "2023-10-06T01:15:47Z" + value: 3 + targetUtilizations: + - containerName: app + targetUtilization: {} + - containerName: istio-proxy + targetUtilization: {} + vertical: + containerResourceRecommendation: null + targets: + deployment: "" + verticalPodAutoscalers: + - name: tortoise-updater-mercari + role: Updater + - name: tortoise-monitor-mercari + role: Monitor + tortoisePhase: Working diff --git a/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-vertical/before/vpa-Monitor.yaml b/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-vertical/before/vpa-Monitor.yaml new file mode 100644 index 00000000..73acfb27 --- /dev/null +++ b/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-vertical/before/vpa-Monitor.yaml @@ -0,0 +1,44 @@ +metadata: + annotations: + tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" + tortoises.autoscaling.mercari.com/tortoise-name: mercari + name: tortoise-monitor-mercari + namespace: default +spec: + resourcePolicy: + containerPolicies: + - containerName: app + - containerName: istio-proxy + targetRef: + apiVersion: apps/v1 + kind: Deployment + name: mercari-app + updatePolicy: + updateMode: "Off" +status: + conditions: + - lastTransitionTime: null + status: "True" + type: RecommendationProvided + recommendation: + containerRecommendations: + - containerName: app + lowerBound: + cpu: "3" + memory: 3Gi + target: + cpu: "3" + memory: 3Gi + upperBound: + cpu: "5" + memory: 5Gi + - containerName: istio-proxy + lowerBound: + cpu: "3" + memory: 3Gi + target: + cpu: "3" + memory: 3Gi + upperBound: + cpu: "5" + memory: 5Gi diff --git a/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-vertical/before/vpa-Updater.yaml b/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-vertical/before/vpa-Updater.yaml new file mode 100644 index 00000000..28c9ee17 --- /dev/null +++ b/controllers/testdata/reconcile-for-the-multiple-containers-pod-all-vertical/before/vpa-Updater.yaml @@ -0,0 +1,20 @@ +metadata: + annotations: + tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" + tortoises.autoscaling.mercari.com/tortoise-name: mercari + name: tortoise-updater-mercari + namespace: default +spec: + recommenders: + - name: tortoise-controller + resourcePolicy: + containerPolicies: + - containerName: app + - containerName: istio-proxy + targetRef: + apiVersion: apps/v1 + kind: Deployment + name: mercari-app + updatePolicy: + updateMode: Auto +status: {} diff --git a/controllers/testdata/reconcile-for-the-multiple-containers-pod-emergency/after/hpa.yaml b/controllers/testdata/reconcile-for-the-multiple-containers-pod-emergency/after/hpa.yaml index a1907178..76404051 100644 --- a/controllers/testdata/reconcile-for-the-multiple-containers-pod-emergency/after/hpa.yaml +++ b/controllers/testdata/reconcile-for-the-multiple-containers-pod-emergency/after/hpa.yaml @@ -2,7 +2,6 @@ metadata: annotations: tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" tortoises.autoscaling.mercari.com/tortoise-name: mercari - creationTimestamp: null name: tortoise-hpa-mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-multiple-containers-pod-emergency/after/tortoise.yaml b/controllers/testdata/reconcile-for-the-multiple-containers-pod-emergency/after/tortoise.yaml index 08f8d2a3..979748d0 100644 --- a/controllers/testdata/reconcile-for-the-multiple-containers-pod-emergency/after/tortoise.yaml +++ b/controllers/testdata/reconcile-for-the-multiple-containers-pod-emergency/after/tortoise.yaml @@ -1,5 +1,4 @@ metadata: - creationTimestamp: null name: mercari namespace: default spec: @@ -72,11 +71,9 @@ status: - containerName: app targetUtilization: cpu: 50 - memory: 90 - containerName: istio-proxy targetUtilization: cpu: 75 - memory: 90 vertical: containerResourceRecommendation: - RecommendedResource: diff --git a/controllers/testdata/reconcile-for-the-multiple-containers-pod-emergency/after/vpa-Monitor.yaml b/controllers/testdata/reconcile-for-the-multiple-containers-pod-emergency/after/vpa-Monitor.yaml index 8c1b0494..73acfb27 100644 --- a/controllers/testdata/reconcile-for-the-multiple-containers-pod-emergency/after/vpa-Monitor.yaml +++ b/controllers/testdata/reconcile-for-the-multiple-containers-pod-emergency/after/vpa-Monitor.yaml @@ -2,7 +2,6 @@ metadata: annotations: tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" tortoises.autoscaling.mercari.com/tortoise-name: mercari - creationTimestamp: null name: tortoise-monitor-mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-multiple-containers-pod-emergency/after/vpa-Updater.yaml b/controllers/testdata/reconcile-for-the-multiple-containers-pod-emergency/after/vpa-Updater.yaml index d0cf12b7..07b36468 100644 --- a/controllers/testdata/reconcile-for-the-multiple-containers-pod-emergency/after/vpa-Updater.yaml +++ b/controllers/testdata/reconcile-for-the-multiple-containers-pod-emergency/after/vpa-Updater.yaml @@ -2,7 +2,6 @@ metadata: annotations: tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" tortoises.autoscaling.mercari.com/tortoise-name: mercari - creationTimestamp: null name: tortoise-updater-mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-multiple-containers-pod-emergency/before/deployment.yaml b/controllers/testdata/reconcile-for-the-multiple-containers-pod-emergency/before/deployment.yaml index 1f21e1e3..04ac49e3 100644 --- a/controllers/testdata/reconcile-for-the-multiple-containers-pod-emergency/before/deployment.yaml +++ b/controllers/testdata/reconcile-for-the-multiple-containers-pod-emergency/before/deployment.yaml @@ -1,5 +1,4 @@ metadata: - creationTimestamp: null name: mercari-app namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-multiple-containers-pod-emergency/before/hpa.yaml b/controllers/testdata/reconcile-for-the-multiple-containers-pod-emergency/before/hpa.yaml index f76e1169..d4c64cb0 100644 --- a/controllers/testdata/reconcile-for-the-multiple-containers-pod-emergency/before/hpa.yaml +++ b/controllers/testdata/reconcile-for-the-multiple-containers-pod-emergency/before/hpa.yaml @@ -2,7 +2,6 @@ metadata: annotations: tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" tortoises.autoscaling.mercari.com/tortoise-name: mercari - creationTimestamp: null name: tortoise-hpa-mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-multiple-containers-pod-emergency/before/tortoise.yaml b/controllers/testdata/reconcile-for-the-multiple-containers-pod-emergency/before/tortoise.yaml index adf5ca73..1736892e 100644 --- a/controllers/testdata/reconcile-for-the-multiple-containers-pod-emergency/before/tortoise.yaml +++ b/controllers/testdata/reconcile-for-the-multiple-containers-pod-emergency/before/tortoise.yaml @@ -1,5 +1,4 @@ metadata: - creationTimestamp: null name: mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-multiple-containers-pod-emergency/before/vpa-Monitor.yaml b/controllers/testdata/reconcile-for-the-multiple-containers-pod-emergency/before/vpa-Monitor.yaml index 8c1b0494..73acfb27 100644 --- a/controllers/testdata/reconcile-for-the-multiple-containers-pod-emergency/before/vpa-Monitor.yaml +++ b/controllers/testdata/reconcile-for-the-multiple-containers-pod-emergency/before/vpa-Monitor.yaml @@ -2,7 +2,6 @@ metadata: annotations: tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" tortoises.autoscaling.mercari.com/tortoise-name: mercari - creationTimestamp: null name: tortoise-monitor-mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-multiple-containers-pod-emergency/before/vpa-Updater.yaml b/controllers/testdata/reconcile-for-the-multiple-containers-pod-emergency/before/vpa-Updater.yaml index a1f72d46..28c9ee17 100644 --- a/controllers/testdata/reconcile-for-the-multiple-containers-pod-emergency/before/vpa-Updater.yaml +++ b/controllers/testdata/reconcile-for-the-multiple-containers-pod-emergency/before/vpa-Updater.yaml @@ -2,7 +2,6 @@ metadata: annotations: tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" tortoises.autoscaling.mercari.com/tortoise-name: mercari - creationTimestamp: null name: tortoise-updater-mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-multiple-containers-pod-one-off/after/hpa.yaml b/controllers/testdata/reconcile-for-the-multiple-containers-pod-one-off/after/hpa.yaml index 2059ba34..b76a3d33 100644 --- a/controllers/testdata/reconcile-for-the-multiple-containers-pod-one-off/after/hpa.yaml +++ b/controllers/testdata/reconcile-for-the-multiple-containers-pod-one-off/after/hpa.yaml @@ -2,7 +2,6 @@ metadata: annotations: tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" tortoises.autoscaling.mercari.com/tortoise-name: mercari - creationTimestamp: null name: tortoise-hpa-mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-multiple-containers-pod-one-off/after/tortoise.yaml b/controllers/testdata/reconcile-for-the-multiple-containers-pod-one-off/after/tortoise.yaml index 3c455f28..c6d80a04 100644 --- a/controllers/testdata/reconcile-for-the-multiple-containers-pod-one-off/after/tortoise.yaml +++ b/controllers/testdata/reconcile-for-the-multiple-containers-pod-one-off/after/tortoise.yaml @@ -1,5 +1,4 @@ metadata: - creationTimestamp: null name: mercari namespace: default spec: @@ -71,7 +70,6 @@ status: - containerName: app targetUtilization: cpu: 50 - memory: 90 - containerName: istio-proxy targetUtilization: {} vertical: diff --git a/controllers/testdata/reconcile-for-the-multiple-containers-pod-one-off/after/vpa-Monitor.yaml b/controllers/testdata/reconcile-for-the-multiple-containers-pod-one-off/after/vpa-Monitor.yaml index 8c1b0494..73acfb27 100644 --- a/controllers/testdata/reconcile-for-the-multiple-containers-pod-one-off/after/vpa-Monitor.yaml +++ b/controllers/testdata/reconcile-for-the-multiple-containers-pod-one-off/after/vpa-Monitor.yaml @@ -2,7 +2,6 @@ metadata: annotations: tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" tortoises.autoscaling.mercari.com/tortoise-name: mercari - creationTimestamp: null name: tortoise-monitor-mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-multiple-containers-pod-one-off/after/vpa-Updater.yaml b/controllers/testdata/reconcile-for-the-multiple-containers-pod-one-off/after/vpa-Updater.yaml index 2c0bb8ee..66bc7d20 100644 --- a/controllers/testdata/reconcile-for-the-multiple-containers-pod-one-off/after/vpa-Updater.yaml +++ b/controllers/testdata/reconcile-for-the-multiple-containers-pod-one-off/after/vpa-Updater.yaml @@ -2,7 +2,6 @@ metadata: annotations: tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" tortoises.autoscaling.mercari.com/tortoise-name: mercari - creationTimestamp: null name: tortoise-updater-mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-multiple-containers-pod-one-off/before/deployment.yaml b/controllers/testdata/reconcile-for-the-multiple-containers-pod-one-off/before/deployment.yaml index 1f21e1e3..04ac49e3 100644 --- a/controllers/testdata/reconcile-for-the-multiple-containers-pod-one-off/before/deployment.yaml +++ b/controllers/testdata/reconcile-for-the-multiple-containers-pod-one-off/before/deployment.yaml @@ -1,5 +1,4 @@ metadata: - creationTimestamp: null name: mercari-app namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-multiple-containers-pod-one-off/before/hpa.yaml b/controllers/testdata/reconcile-for-the-multiple-containers-pod-one-off/before/hpa.yaml index 9dc2ee92..2948735a 100644 --- a/controllers/testdata/reconcile-for-the-multiple-containers-pod-one-off/before/hpa.yaml +++ b/controllers/testdata/reconcile-for-the-multiple-containers-pod-one-off/before/hpa.yaml @@ -2,7 +2,6 @@ metadata: annotations: tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" tortoises.autoscaling.mercari.com/tortoise-name: mercari - creationTimestamp: null name: tortoise-hpa-mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-multiple-containers-pod-one-off/before/tortoise.yaml b/controllers/testdata/reconcile-for-the-multiple-containers-pod-one-off/before/tortoise.yaml index 9dbaf756..af182bda 100644 --- a/controllers/testdata/reconcile-for-the-multiple-containers-pod-one-off/before/tortoise.yaml +++ b/controllers/testdata/reconcile-for-the-multiple-containers-pod-one-off/before/tortoise.yaml @@ -1,5 +1,4 @@ metadata: - creationTimestamp: null name: mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-multiple-containers-pod-one-off/before/vpa-Monitor.yaml b/controllers/testdata/reconcile-for-the-multiple-containers-pod-one-off/before/vpa-Monitor.yaml index 8c1b0494..73acfb27 100644 --- a/controllers/testdata/reconcile-for-the-multiple-containers-pod-one-off/before/vpa-Monitor.yaml +++ b/controllers/testdata/reconcile-for-the-multiple-containers-pod-one-off/before/vpa-Monitor.yaml @@ -2,7 +2,6 @@ metadata: annotations: tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" tortoises.autoscaling.mercari.com/tortoise-name: mercari - creationTimestamp: null name: tortoise-monitor-mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-multiple-containers-pod-one-off/before/vpa-Updater.yaml b/controllers/testdata/reconcile-for-the-multiple-containers-pod-one-off/before/vpa-Updater.yaml index a1f72d46..28c9ee17 100644 --- a/controllers/testdata/reconcile-for-the-multiple-containers-pod-one-off/before/vpa-Updater.yaml +++ b/controllers/testdata/reconcile-for-the-multiple-containers-pod-one-off/before/vpa-Updater.yaml @@ -2,7 +2,6 @@ metadata: annotations: tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" tortoises.autoscaling.mercari.com/tortoise-name: mercari - creationTimestamp: null name: tortoise-updater-mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-multiple-containers-pod-working/after/hpa.yaml b/controllers/testdata/reconcile-for-the-multiple-containers-pod-working/after/hpa.yaml index 818c8f0b..b760bbc8 100644 --- a/controllers/testdata/reconcile-for-the-multiple-containers-pod-working/after/hpa.yaml +++ b/controllers/testdata/reconcile-for-the-multiple-containers-pod-working/after/hpa.yaml @@ -2,7 +2,6 @@ metadata: annotations: tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" tortoises.autoscaling.mercari.com/tortoise-name: mercari - creationTimestamp: null name: tortoise-hpa-mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-multiple-containers-pod-working/after/tortoise.yaml b/controllers/testdata/reconcile-for-the-multiple-containers-pod-working/after/tortoise.yaml index c98ee031..26b9a676 100644 --- a/controllers/testdata/reconcile-for-the-multiple-containers-pod-working/after/tortoise.yaml +++ b/controllers/testdata/reconcile-for-the-multiple-containers-pod-working/after/tortoise.yaml @@ -1,5 +1,4 @@ metadata: - creationTimestamp: null name: mercari namespace: default spec: @@ -71,11 +70,9 @@ status: - containerName: app targetUtilization: cpu: 50 - memory: 90 - containerName: istio-proxy targetUtilization: cpu: 75 - memory: 90 vertical: containerResourceRecommendation: - RecommendedResource: diff --git a/controllers/testdata/reconcile-for-the-multiple-containers-pod-working/after/vpa-Monitor.yaml b/controllers/testdata/reconcile-for-the-multiple-containers-pod-working/after/vpa-Monitor.yaml index 8c1b0494..73acfb27 100644 --- a/controllers/testdata/reconcile-for-the-multiple-containers-pod-working/after/vpa-Monitor.yaml +++ b/controllers/testdata/reconcile-for-the-multiple-containers-pod-working/after/vpa-Monitor.yaml @@ -2,7 +2,6 @@ metadata: annotations: tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" tortoises.autoscaling.mercari.com/tortoise-name: mercari - creationTimestamp: null name: tortoise-monitor-mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-multiple-containers-pod-working/after/vpa-Updater.yaml b/controllers/testdata/reconcile-for-the-multiple-containers-pod-working/after/vpa-Updater.yaml index d0cf12b7..07b36468 100644 --- a/controllers/testdata/reconcile-for-the-multiple-containers-pod-working/after/vpa-Updater.yaml +++ b/controllers/testdata/reconcile-for-the-multiple-containers-pod-working/after/vpa-Updater.yaml @@ -2,7 +2,6 @@ metadata: annotations: tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" tortoises.autoscaling.mercari.com/tortoise-name: mercari - creationTimestamp: null name: tortoise-updater-mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-multiple-containers-pod-working/before/deployment.yaml b/controllers/testdata/reconcile-for-the-multiple-containers-pod-working/before/deployment.yaml index 1f21e1e3..04ac49e3 100644 --- a/controllers/testdata/reconcile-for-the-multiple-containers-pod-working/before/deployment.yaml +++ b/controllers/testdata/reconcile-for-the-multiple-containers-pod-working/before/deployment.yaml @@ -1,5 +1,4 @@ metadata: - creationTimestamp: null name: mercari-app namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-multiple-containers-pod-working/before/hpa.yaml b/controllers/testdata/reconcile-for-the-multiple-containers-pod-working/before/hpa.yaml index f76e1169..d4c64cb0 100644 --- a/controllers/testdata/reconcile-for-the-multiple-containers-pod-working/before/hpa.yaml +++ b/controllers/testdata/reconcile-for-the-multiple-containers-pod-working/before/hpa.yaml @@ -2,7 +2,6 @@ metadata: annotations: tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" tortoises.autoscaling.mercari.com/tortoise-name: mercari - creationTimestamp: null name: tortoise-hpa-mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-multiple-containers-pod-working/before/tortoise.yaml b/controllers/testdata/reconcile-for-the-multiple-containers-pod-working/before/tortoise.yaml index 41d27e55..7b7b5ec8 100644 --- a/controllers/testdata/reconcile-for-the-multiple-containers-pod-working/before/tortoise.yaml +++ b/controllers/testdata/reconcile-for-the-multiple-containers-pod-working/before/tortoise.yaml @@ -1,5 +1,4 @@ metadata: - creationTimestamp: null name: mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-multiple-containers-pod-working/before/vpa-Monitor.yaml b/controllers/testdata/reconcile-for-the-multiple-containers-pod-working/before/vpa-Monitor.yaml index 8c1b0494..73acfb27 100644 --- a/controllers/testdata/reconcile-for-the-multiple-containers-pod-working/before/vpa-Monitor.yaml +++ b/controllers/testdata/reconcile-for-the-multiple-containers-pod-working/before/vpa-Monitor.yaml @@ -2,7 +2,6 @@ metadata: annotations: tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" tortoises.autoscaling.mercari.com/tortoise-name: mercari - creationTimestamp: null name: tortoise-monitor-mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-multiple-containers-pod-working/before/vpa-Updater.yaml b/controllers/testdata/reconcile-for-the-multiple-containers-pod-working/before/vpa-Updater.yaml index a1f72d46..28c9ee17 100644 --- a/controllers/testdata/reconcile-for-the-multiple-containers-pod-working/before/vpa-Updater.yaml +++ b/controllers/testdata/reconcile-for-the-multiple-containers-pod-working/before/vpa-Updater.yaml @@ -2,7 +2,6 @@ metadata: annotations: tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" tortoises.autoscaling.mercari.com/tortoise-name: mercari - creationTimestamp: null name: tortoise-updater-mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-single-container-pod-dryrun/after/hpa.yaml b/controllers/testdata/reconcile-for-the-single-container-pod-dryrun/after/hpa.yaml index 9dc2ee92..2948735a 100644 --- a/controllers/testdata/reconcile-for-the-single-container-pod-dryrun/after/hpa.yaml +++ b/controllers/testdata/reconcile-for-the-single-container-pod-dryrun/after/hpa.yaml @@ -2,7 +2,6 @@ metadata: annotations: tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" tortoises.autoscaling.mercari.com/tortoise-name: mercari - creationTimestamp: null name: tortoise-hpa-mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-single-container-pod-dryrun/after/tortoise.yaml b/controllers/testdata/reconcile-for-the-single-container-pod-dryrun/after/tortoise.yaml index f2c8eb17..cc2243ec 100644 --- a/controllers/testdata/reconcile-for-the-single-container-pod-dryrun/after/tortoise.yaml +++ b/controllers/testdata/reconcile-for-the-single-container-pod-dryrun/after/tortoise.yaml @@ -1,5 +1,4 @@ metadata: - creationTimestamp: null name: mercari namespace: default spec: @@ -53,7 +52,6 @@ status: - containerName: app targetUtilization: cpu: 75 - memory: 90 vertical: containerResourceRecommendation: - RecommendedResource: diff --git a/controllers/testdata/reconcile-for-the-single-container-pod-dryrun/after/vpa-Monitor.yaml b/controllers/testdata/reconcile-for-the-single-container-pod-dryrun/after/vpa-Monitor.yaml index bdfec85e..b618edf9 100644 --- a/controllers/testdata/reconcile-for-the-single-container-pod-dryrun/after/vpa-Monitor.yaml +++ b/controllers/testdata/reconcile-for-the-single-container-pod-dryrun/after/vpa-Monitor.yaml @@ -2,7 +2,6 @@ metadata: annotations: tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" tortoises.autoscaling.mercari.com/tortoise-name: mercari - creationTimestamp: null name: tortoise-monitor-mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-single-container-pod-dryrun/after/vpa-Updater.yaml b/controllers/testdata/reconcile-for-the-single-container-pod-dryrun/after/vpa-Updater.yaml index dd038af1..20b213cc 100644 --- a/controllers/testdata/reconcile-for-the-single-container-pod-dryrun/after/vpa-Updater.yaml +++ b/controllers/testdata/reconcile-for-the-single-container-pod-dryrun/after/vpa-Updater.yaml @@ -2,7 +2,6 @@ metadata: annotations: tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" tortoises.autoscaling.mercari.com/tortoise-name: mercari - creationTimestamp: null name: tortoise-updater-mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-single-container-pod-dryrun/before/deployment.yaml b/controllers/testdata/reconcile-for-the-single-container-pod-dryrun/before/deployment.yaml index 1f9c23a6..34693daa 100644 --- a/controllers/testdata/reconcile-for-the-single-container-pod-dryrun/before/deployment.yaml +++ b/controllers/testdata/reconcile-for-the-single-container-pod-dryrun/before/deployment.yaml @@ -1,5 +1,4 @@ metadata: - creationTimestamp: null name: mercari-app namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-single-container-pod-dryrun/before/hpa.yaml b/controllers/testdata/reconcile-for-the-single-container-pod-dryrun/before/hpa.yaml index 9dc2ee92..2948735a 100644 --- a/controllers/testdata/reconcile-for-the-single-container-pod-dryrun/before/hpa.yaml +++ b/controllers/testdata/reconcile-for-the-single-container-pod-dryrun/before/hpa.yaml @@ -2,7 +2,6 @@ metadata: annotations: tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" tortoises.autoscaling.mercari.com/tortoise-name: mercari - creationTimestamp: null name: tortoise-hpa-mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-single-container-pod-dryrun/before/tortoise.yaml b/controllers/testdata/reconcile-for-the-single-container-pod-dryrun/before/tortoise.yaml index 26e954a6..b7f0f882 100644 --- a/controllers/testdata/reconcile-for-the-single-container-pod-dryrun/before/tortoise.yaml +++ b/controllers/testdata/reconcile-for-the-single-container-pod-dryrun/before/tortoise.yaml @@ -1,5 +1,4 @@ metadata: - creationTimestamp: null name: mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-single-container-pod-dryrun/before/vpa-Monitor.yaml b/controllers/testdata/reconcile-for-the-single-container-pod-dryrun/before/vpa-Monitor.yaml index bdfec85e..b618edf9 100644 --- a/controllers/testdata/reconcile-for-the-single-container-pod-dryrun/before/vpa-Monitor.yaml +++ b/controllers/testdata/reconcile-for-the-single-container-pod-dryrun/before/vpa-Monitor.yaml @@ -2,7 +2,6 @@ metadata: annotations: tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" tortoises.autoscaling.mercari.com/tortoise-name: mercari - creationTimestamp: null name: tortoise-monitor-mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-single-container-pod-dryrun/before/vpa-Updater.yaml b/controllers/testdata/reconcile-for-the-single-container-pod-dryrun/before/vpa-Updater.yaml index dd038af1..20b213cc 100644 --- a/controllers/testdata/reconcile-for-the-single-container-pod-dryrun/before/vpa-Updater.yaml +++ b/controllers/testdata/reconcile-for-the-single-container-pod-dryrun/before/vpa-Updater.yaml @@ -2,7 +2,6 @@ metadata: annotations: tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" tortoises.autoscaling.mercari.com/tortoise-name: mercari - creationTimestamp: null name: tortoise-updater-mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-single-container-pod-emergency/after/hpa.yaml b/controllers/testdata/reconcile-for-the-single-container-pod-emergency/after/hpa.yaml index 256af6f4..06c66f92 100644 --- a/controllers/testdata/reconcile-for-the-single-container-pod-emergency/after/hpa.yaml +++ b/controllers/testdata/reconcile-for-the-single-container-pod-emergency/after/hpa.yaml @@ -2,7 +2,6 @@ metadata: annotations: tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" tortoises.autoscaling.mercari.com/tortoise-name: mercari - creationTimestamp: null name: tortoise-hpa-mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-single-container-pod-emergency/after/tortoise.yaml b/controllers/testdata/reconcile-for-the-single-container-pod-emergency/after/tortoise.yaml index 5dc1fc21..35813f7b 100644 --- a/controllers/testdata/reconcile-for-the-single-container-pod-emergency/after/tortoise.yaml +++ b/controllers/testdata/reconcile-for-the-single-container-pod-emergency/after/tortoise.yaml @@ -1,5 +1,4 @@ metadata: - creationTimestamp: null name: mercari namespace: default spec: @@ -53,7 +52,6 @@ status: - containerName: app targetUtilization: cpu: 75 - memory: 90 vertical: containerResourceRecommendation: - RecommendedResource: diff --git a/controllers/testdata/reconcile-for-the-single-container-pod-emergency/after/vpa-Monitor.yaml b/controllers/testdata/reconcile-for-the-single-container-pod-emergency/after/vpa-Monitor.yaml index bdfec85e..b618edf9 100644 --- a/controllers/testdata/reconcile-for-the-single-container-pod-emergency/after/vpa-Monitor.yaml +++ b/controllers/testdata/reconcile-for-the-single-container-pod-emergency/after/vpa-Monitor.yaml @@ -2,7 +2,6 @@ metadata: annotations: tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" tortoises.autoscaling.mercari.com/tortoise-name: mercari - creationTimestamp: null name: tortoise-monitor-mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-single-container-pod-emergency/after/vpa-Updater.yaml b/controllers/testdata/reconcile-for-the-single-container-pod-emergency/after/vpa-Updater.yaml index 2bf3ec83..68d3f56a 100644 --- a/controllers/testdata/reconcile-for-the-single-container-pod-emergency/after/vpa-Updater.yaml +++ b/controllers/testdata/reconcile-for-the-single-container-pod-emergency/after/vpa-Updater.yaml @@ -2,7 +2,6 @@ metadata: annotations: tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" tortoises.autoscaling.mercari.com/tortoise-name: mercari - creationTimestamp: null name: tortoise-updater-mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-single-container-pod-emergency/before/deployment.yaml b/controllers/testdata/reconcile-for-the-single-container-pod-emergency/before/deployment.yaml index 1f9c23a6..34693daa 100644 --- a/controllers/testdata/reconcile-for-the-single-container-pod-emergency/before/deployment.yaml +++ b/controllers/testdata/reconcile-for-the-single-container-pod-emergency/before/deployment.yaml @@ -1,5 +1,4 @@ metadata: - creationTimestamp: null name: mercari-app namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-single-container-pod-emergency/before/hpa.yaml b/controllers/testdata/reconcile-for-the-single-container-pod-emergency/before/hpa.yaml index 9dc2ee92..2948735a 100644 --- a/controllers/testdata/reconcile-for-the-single-container-pod-emergency/before/hpa.yaml +++ b/controllers/testdata/reconcile-for-the-single-container-pod-emergency/before/hpa.yaml @@ -2,7 +2,6 @@ metadata: annotations: tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" tortoises.autoscaling.mercari.com/tortoise-name: mercari - creationTimestamp: null name: tortoise-hpa-mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-single-container-pod-emergency/before/tortoise.yaml b/controllers/testdata/reconcile-for-the-single-container-pod-emergency/before/tortoise.yaml index a253ea1c..eee4eec0 100644 --- a/controllers/testdata/reconcile-for-the-single-container-pod-emergency/before/tortoise.yaml +++ b/controllers/testdata/reconcile-for-the-single-container-pod-emergency/before/tortoise.yaml @@ -1,5 +1,4 @@ metadata: - creationTimestamp: null name: mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-single-container-pod-emergency/before/vpa-Monitor.yaml b/controllers/testdata/reconcile-for-the-single-container-pod-emergency/before/vpa-Monitor.yaml index bdfec85e..b618edf9 100644 --- a/controllers/testdata/reconcile-for-the-single-container-pod-emergency/before/vpa-Monitor.yaml +++ b/controllers/testdata/reconcile-for-the-single-container-pod-emergency/before/vpa-Monitor.yaml @@ -2,7 +2,6 @@ metadata: annotations: tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" tortoises.autoscaling.mercari.com/tortoise-name: mercari - creationTimestamp: null name: tortoise-monitor-mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-single-container-pod-emergency/before/vpa-Updater.yaml b/controllers/testdata/reconcile-for-the-single-container-pod-emergency/before/vpa-Updater.yaml index dd038af1..20b213cc 100644 --- a/controllers/testdata/reconcile-for-the-single-container-pod-emergency/before/vpa-Updater.yaml +++ b/controllers/testdata/reconcile-for-the-single-container-pod-emergency/before/vpa-Updater.yaml @@ -2,7 +2,6 @@ metadata: annotations: tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" tortoises.autoscaling.mercari.com/tortoise-name: mercari - creationTimestamp: null name: tortoise-updater-mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-single-container-pod-working/after/hpa.yaml b/controllers/testdata/reconcile-for-the-single-container-pod-working/after/hpa.yaml index 8df603d2..96c8dedd 100644 --- a/controllers/testdata/reconcile-for-the-single-container-pod-working/after/hpa.yaml +++ b/controllers/testdata/reconcile-for-the-single-container-pod-working/after/hpa.yaml @@ -2,7 +2,6 @@ metadata: annotations: tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" tortoises.autoscaling.mercari.com/tortoise-name: mercari - creationTimestamp: null name: tortoise-hpa-mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-single-container-pod-working/after/tortoise.yaml b/controllers/testdata/reconcile-for-the-single-container-pod-working/after/tortoise.yaml index 6064cd6f..5a5846ae 100644 --- a/controllers/testdata/reconcile-for-the-single-container-pod-working/after/tortoise.yaml +++ b/controllers/testdata/reconcile-for-the-single-container-pod-working/after/tortoise.yaml @@ -1,5 +1,4 @@ metadata: - creationTimestamp: null name: mercari namespace: default spec: @@ -52,7 +51,6 @@ status: - containerName: app targetUtilization: cpu: 75 - memory: 90 vertical: containerResourceRecommendation: - RecommendedResource: diff --git a/controllers/testdata/reconcile-for-the-single-container-pod-working/after/vpa-Monitor.yaml b/controllers/testdata/reconcile-for-the-single-container-pod-working/after/vpa-Monitor.yaml index bdfec85e..b618edf9 100644 --- a/controllers/testdata/reconcile-for-the-single-container-pod-working/after/vpa-Monitor.yaml +++ b/controllers/testdata/reconcile-for-the-single-container-pod-working/after/vpa-Monitor.yaml @@ -2,7 +2,6 @@ metadata: annotations: tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" tortoises.autoscaling.mercari.com/tortoise-name: mercari - creationTimestamp: null name: tortoise-monitor-mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-single-container-pod-working/after/vpa-Updater.yaml b/controllers/testdata/reconcile-for-the-single-container-pod-working/after/vpa-Updater.yaml index 2bf3ec83..68d3f56a 100644 --- a/controllers/testdata/reconcile-for-the-single-container-pod-working/after/vpa-Updater.yaml +++ b/controllers/testdata/reconcile-for-the-single-container-pod-working/after/vpa-Updater.yaml @@ -2,7 +2,6 @@ metadata: annotations: tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" tortoises.autoscaling.mercari.com/tortoise-name: mercari - creationTimestamp: null name: tortoise-updater-mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-single-container-pod-working/before/deployment.yaml b/controllers/testdata/reconcile-for-the-single-container-pod-working/before/deployment.yaml index 1f9c23a6..34693daa 100644 --- a/controllers/testdata/reconcile-for-the-single-container-pod-working/before/deployment.yaml +++ b/controllers/testdata/reconcile-for-the-single-container-pod-working/before/deployment.yaml @@ -1,5 +1,4 @@ metadata: - creationTimestamp: null name: mercari-app namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-single-container-pod-working/before/hpa.yaml b/controllers/testdata/reconcile-for-the-single-container-pod-working/before/hpa.yaml index 9dc2ee92..2948735a 100644 --- a/controllers/testdata/reconcile-for-the-single-container-pod-working/before/hpa.yaml +++ b/controllers/testdata/reconcile-for-the-single-container-pod-working/before/hpa.yaml @@ -2,7 +2,6 @@ metadata: annotations: tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" tortoises.autoscaling.mercari.com/tortoise-name: mercari - creationTimestamp: null name: tortoise-hpa-mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-single-container-pod-working/before/tortoise.yaml b/controllers/testdata/reconcile-for-the-single-container-pod-working/before/tortoise.yaml index ebfcf3c9..6b6f622d 100644 --- a/controllers/testdata/reconcile-for-the-single-container-pod-working/before/tortoise.yaml +++ b/controllers/testdata/reconcile-for-the-single-container-pod-working/before/tortoise.yaml @@ -1,5 +1,4 @@ metadata: - creationTimestamp: null name: mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-single-container-pod-working/before/vpa-Monitor.yaml b/controllers/testdata/reconcile-for-the-single-container-pod-working/before/vpa-Monitor.yaml index bdfec85e..b618edf9 100644 --- a/controllers/testdata/reconcile-for-the-single-container-pod-working/before/vpa-Monitor.yaml +++ b/controllers/testdata/reconcile-for-the-single-container-pod-working/before/vpa-Monitor.yaml @@ -2,7 +2,6 @@ metadata: annotations: tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" tortoises.autoscaling.mercari.com/tortoise-name: mercari - creationTimestamp: null name: tortoise-monitor-mercari namespace: default spec: diff --git a/controllers/testdata/reconcile-for-the-single-container-pod-working/before/vpa-Updater.yaml b/controllers/testdata/reconcile-for-the-single-container-pod-working/before/vpa-Updater.yaml index dd038af1..20b213cc 100644 --- a/controllers/testdata/reconcile-for-the-single-container-pod-working/before/vpa-Updater.yaml +++ b/controllers/testdata/reconcile-for-the-single-container-pod-working/before/vpa-Updater.yaml @@ -2,7 +2,6 @@ metadata: annotations: tortoise.autoscaling.mercari.com/managed-by-tortoise: "true" tortoises.autoscaling.mercari.com/tortoise-name: mercari - creationTimestamp: null name: tortoise-updater-mercari namespace: default spec: diff --git a/controllers/tortoise_controller.go b/controllers/tortoise_controller.go index 30b95560..a7d9e4dc 100644 --- a/controllers/tortoise_controller.go +++ b/controllers/tortoise_controller.go @@ -118,12 +118,6 @@ func (r *TortoiseReconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ } }() - _, err = r.HpaService.UpdateHPASpecFromTortoiseAutoscalingPolicy(ctx, tortoise) - if err != nil { - logger.Error(err, "update HPA spec from Tortoise autoscaling policy", "tortoise", req.NamespacedName) - return ctrl.Result{}, err - } - dm, err := r.DeploymentService.GetDeploymentOnTortoise(ctx, tortoise) if err != nil { logger.Error(err, "failed to get deployment", "tortoise", req.NamespacedName) @@ -141,6 +135,27 @@ func (r *TortoiseReconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ return ctrl.Result{RequeueAfter: r.Interval}, nil } + _, err = r.HpaService.UpdateHPASpecFromTortoiseAutoscalingPolicy(ctx, tortoise) + if err != nil { + if !apierrors.IsNotFound(err) { + logger.Error(err, "update HPA spec from Tortoise autoscaling policy", "tortoise", req.NamespacedName) + return ctrl.Result{}, err + } + + // If not found, it's one of: + // - the user don't specify Horizontal in any autoscalingPolicy. + // - In that case, we don't need to create an initial HPA. + // - the user didn't specify Horizontal in any autoscalingPolicy previously, + // but just updated tortoise to have Horizontal in some. + // - In that case, we need to create an initial HPA. + // + // In both cases, we just need to call `InitializeHPA` and it handles both cases. + tortoise, err = r.HpaService.InitializeHPA(ctx, tortoise, dm) + if err != nil { + return ctrl.Result{}, err + } + } + vpa, ready, err := r.VpaService.GetTortoiseMonitorVPA(ctx, tortoise) if err != nil { logger.Error(err, "failed to get tortoise VPA", "tortoise", req.NamespacedName) diff --git a/controllers/tortoise_controller_test.go b/controllers/tortoise_controller_test.go index 853fbe4e..87725057 100644 --- a/controllers/tortoise_controller_test.go +++ b/controllers/tortoise_controller_test.go @@ -43,12 +43,6 @@ func newResource(path string) resources { err = yaml.Unmarshal(y, tortoise) Expect(err).NotTo(HaveOccurred()) - y, err = os.ReadFile(hpaPath) - Expect(err).NotTo(HaveOccurred()) - hpa := &v2.HorizontalPodAutoscaler{} - err = yaml.Unmarshal(y, hpa) - Expect(err).NotTo(HaveOccurred()) - y, err = os.ReadFile(updaterVPAPath) Expect(err).NotTo(HaveOccurred()) vpa := &autoscalingv1.VerticalPodAutoscaler{} @@ -63,12 +57,23 @@ func newResource(path string) resources { var deploy *v1.Deployment y, err = os.ReadFile(deploymentPath) + // maybe deployment file is not exist if err == nil { deploy = &v1.Deployment{} err = yaml.Unmarshal(y, deploy) Expect(err).NotTo(HaveOccurred()) } + var hpa *v2.HorizontalPodAutoscaler + y, err = os.ReadFile(hpaPath) + // maybe hpa file is not exist + if err == nil { + Expect(err).NotTo(HaveOccurred()) + hpa = &v2.HorizontalPodAutoscaler{} + err = yaml.Unmarshal(y, hpa) + Expect(err).NotTo(HaveOccurred()) + } + return resources{ tortoise: tortoise, hpa: hpa, @@ -121,8 +126,10 @@ func createTortoiseWithStatus(ctx context.Context, k8sClient client.Client, tort func initializeResourcesFromFiles(ctx context.Context, k8sClient client.Client, path string) resources { resource := newResource(path) - err := k8sClient.Create(ctx, resource.hpa) - Expect(err).NotTo(HaveOccurred()) + if resource.hpa != nil { + err := k8sClient.Create(ctx, resource.hpa) + Expect(err).NotTo(HaveOccurred()) + } createDeploymentWithStatus(ctx, k8sClient, resource.deployment) createVPAWithStatus(ctx, k8sClient, resource.vpa[v1beta1.VerticalPodAutoscalerRoleUpdater]) @@ -201,9 +208,12 @@ var _ = Describe("Test TortoiseController", func() { gotTortoise := &v1beta1.Tortoise{} err := k8sClient.Get(ctx, client.ObjectKey{Namespace: "default", Name: "mercari"}, gotTortoise) g.Expect(err).ShouldNot(HaveOccurred()) - gotHPA := &v2.HorizontalPodAutoscaler{} - err = k8sClient.Get(ctx, client.ObjectKey{Namespace: "default", Name: "tortoise-hpa-mercari"}, gotHPA) - g.Expect(err).ShouldNot(HaveOccurred()) + var gotHPA *v2.HorizontalPodAutoscaler + if tc.want.hpa != nil { + gotHPA = &v2.HorizontalPodAutoscaler{} + err = k8sClient.Get(ctx, client.ObjectKey{Namespace: "default", Name: "tortoise-hpa-mercari"}, gotHPA) + g.Expect(err).ShouldNot(HaveOccurred()) + } gotUpdaterVPA := &autoscalingv1.VerticalPodAutoscaler{} err = k8sClient.Get(ctx, client.ObjectKey{Namespace: "default", Name: "tortoise-updater-mercari"}, gotUpdaterVPA) g.Expect(err).ShouldNot(HaveOccurred()) @@ -216,6 +226,8 @@ var _ = Describe("Test TortoiseController", func() { v1beta1.VerticalPodAutoscalerRoleMonitor: gotMonitorVPA, }}) g.Expect(err).ShouldNot(HaveOccurred()) + + cleanUp() }).Should(Succeed()) } @@ -257,6 +269,9 @@ var _ = Describe("Test TortoiseController", func() { It("TortoisePhaseWorking (include AutoscalingTypeOff)", func() { runTest(filepath.Join("testdata", "reconcile-for-the-multiple-containers-pod-one-off")) }) + It("TortoisePhaseWorking (All AutoscalingTypeVertical)", func() { + runTest(filepath.Join("testdata", "reconcile-for-the-multiple-containers-pod-all-vertical")) + }) It("TortoisePhaseWorking (All AutoscalingTypeOff)", func() { runTest(filepath.Join("testdata", "reconcile-for-the-multiple-containers-pod-all-off")) }) @@ -335,11 +350,6 @@ func (t *testCase) compare(got resources) error { } } - if t.want.deployment != nil { - if d := cmp.Diff(t.want.deployment, got.deployment, cmpopts.IgnoreFields(v1.Deployment{}, "ObjectMeta"), cmpopts.IgnoreTypes(metav1.Time{})); d != "" { - return fmt.Errorf("unexpected deployment: diff = %s", d) - } - } return nil } diff --git a/manifests/crd/apiextensions.k8s.io_v1_customresourcedefinition_tortoises.autoscaling.mercari.com.yaml b/manifests/crd/apiextensions.k8s.io_v1_customresourcedefinition_tortoises.autoscaling.mercari.com.yaml index cdb7d16f..8454814d 100644 --- a/manifests/crd/apiextensions.k8s.io_v1_customresourcedefinition_tortoises.autoscaling.mercari.com.yaml +++ b/manifests/crd/apiextensions.k8s.io_v1_customresourcedefinition_tortoises.autoscaling.mercari.com.yaml @@ -602,7 +602,6 @@ spec: type: array required: - deployment - - horizontalPodAutoscaler - verticalPodAutoscalers type: object tortoisePhase: diff --git a/manifests/default/apiextensions.k8s.io_v1_customresourcedefinition_tortoises.autoscaling.mercari.com.yaml b/manifests/default/apiextensions.k8s.io_v1_customresourcedefinition_tortoises.autoscaling.mercari.com.yaml index 19bf76c8..73cd3fb1 100644 --- a/manifests/default/apiextensions.k8s.io_v1_customresourcedefinition_tortoises.autoscaling.mercari.com.yaml +++ b/manifests/default/apiextensions.k8s.io_v1_customresourcedefinition_tortoises.autoscaling.mercari.com.yaml @@ -602,7 +602,6 @@ spec: type: array required: - deployment - - horizontalPodAutoscaler - verticalPodAutoscalers type: object tortoisePhase: diff --git a/pkg/hpa/service.go b/pkg/hpa/service.go index 341a7f0f..56029151 100644 --- a/pkg/hpa/service.go +++ b/pkg/hpa/service.go @@ -43,6 +43,11 @@ func New(c client.Client, recorder record.EventRecorder, replicaReductionFactor } func (c *Service) InitializeHPA(ctx context.Context, tortoise *autoscalingv1beta1.Tortoise, dm *v1.Deployment) (*autoscalingv1beta1.Tortoise, error) { + // if all policy is off or Vertical, we don't need HPA. + if !hasHorizontal(tortoise) { + return tortoise, nil + } + if tortoise.Spec.TargetRefs.HorizontalPodAutoscalerName != nil { // update the existing HPA that the user set on tortoise. tortoise, err := c.giveAnnotationsOnExistingHPA(ctx, tortoise) @@ -84,9 +89,9 @@ func (c *Service) giveAnnotationsOnExistingHPA(ctx context.Context, tortoise *au } hpa.Annotations[annotation.TortoiseNameAnnotation] = tortoise.Name hpa.Annotations[annotation.ManagedByTortoiseAnnotation] = "true" - tortoise.Status.Targets.HorizontalPodAutoscaler = hpa.Name return c.c.Update(ctx, hpa) } + tortoise.Status.Targets.HorizontalPodAutoscaler = *tortoise.Spec.TargetRefs.HorizontalPodAutoscalerName return tortoise, retry.RetryOnConflict(retry.DefaultRetry, updateFn) } @@ -189,6 +194,10 @@ func (c *Service) addHPAMetricsFromTortoiseAutoscalingPolicy(ctx context.Context } func (c *Service) CreateHPA(ctx context.Context, tortoise *autoscalingv1beta1.Tortoise, dm *v1.Deployment) (*v2.HorizontalPodAutoscaler, *autoscalingv1beta1.Tortoise, error) { + if !hasHorizontal(tortoise) { + // no need to create HPA + return nil, tortoise, nil + } if tortoise.Spec.TargetRefs.HorizontalPodAutoscalerName != nil { // we don't have to create HPA as the user specified the existing HPA. return nil, tortoise, nil @@ -243,6 +252,10 @@ func (c *Service) CreateHPA(ctx context.Context, tortoise *autoscalingv1beta1.To } func (c *Service) GetHPAOnTortoise(ctx context.Context, tortoise *autoscalingv1beta1.Tortoise) (*v2.HorizontalPodAutoscaler, error) { + if !hasHorizontal(tortoise) { + // there should be no HPA + return nil, nil + } hpa := &v2.HorizontalPodAutoscaler{} if err := c.c.Get(ctx, types.NamespacedName{Namespace: tortoise.Namespace, Name: tortoise.Status.Targets.HorizontalPodAutoscaler}, hpa); err != nil { return nil, fmt.Errorf("failed to get hpa on tortoise: %w", err) @@ -323,18 +336,20 @@ func (c *Service) UpdateHPASpecFromTortoiseAutoscalingPolicy(ctx context.Context return hpa, nil } -func (c *Service) UpdateHPAFromTortoiseRecommendation(ctx context.Context, tortoise *autoscalingv1beta1.Tortoise, now time.Time) (*v2.HorizontalPodAutoscaler, *autoscalingv1beta1.Tortoise, error) { - // if all policy is off or Vertical, we don't update HPA. - foundHorizontal := false +func hasHorizontal(tortoise *autoscalingv1beta1.Tortoise) bool { for _, r := range tortoise.Spec.ResourcePolicy { for _, p := range r.AutoscalingPolicy { if p == autoscalingv1beta1.AutoscalingTypeHorizontal { - foundHorizontal = true - break + return true } } } - if !foundHorizontal { + return false +} + +func (c *Service) UpdateHPAFromTortoiseRecommendation(ctx context.Context, tortoise *autoscalingv1beta1.Tortoise, now time.Time) (*v2.HorizontalPodAutoscaler, *autoscalingv1beta1.Tortoise, error) { + // if all policy is off or Vertical, we don't update HPA. + if !hasHorizontal(tortoise) { return nil, tortoise, nil } diff --git a/pkg/hpa/service_test.go b/pkg/hpa/service_test.go index ed4c7730..09445da1 100644 --- a/pkg/hpa/service_test.go +++ b/pkg/hpa/service_test.go @@ -963,6 +963,15 @@ func TestService_InitializeHPA(t *testing.T) { Name: "deployment", }, }, + ResourcePolicy: []autoscalingv1beta1.ContainerResourcePolicy{ + { + ContainerName: "app", + AutoscalingPolicy: map[v1.ResourceName]v1beta1.AutoscalingType{ + v1.ResourceMemory: v1beta1.AutoscalingTypeVertical, + v1.ResourceCPU: v1beta1.AutoscalingTypeHorizontal, + }, + }, + }, }, }, dm: &appv1.Deployment{ diff --git a/pkg/recommender/recommender.go b/pkg/recommender/recommender.go index 021607b6..6ffaaafa 100644 --- a/pkg/recommender/recommender.go +++ b/pkg/recommender/recommender.go @@ -269,14 +269,10 @@ func (s *Service) updateHPATargetUtilizationRecommendations(ctx context.Context, continue } for k, p := range r.AutoscalingPolicy { - if p == v1beta1.AutoscalingTypeOff { + if p != v1beta1.AutoscalingTypeHorizontal { // nothing to do. continue } - if p == v1beta1.AutoscalingTypeVertical { - targetMap[k] = s.upperTargetResourceUtilization - continue - } req, ok := reqmap[k] if !ok { diff --git a/pkg/recommender/recommender_test.go b/pkg/recommender/recommender_test.go index 357b0ad9..a8620b5f 100644 --- a/pkg/recommender/recommender_test.go +++ b/pkg/recommender/recommender_test.go @@ -178,15 +178,13 @@ func TestUpdateRecommendation(t *testing.T) { { ContainerName: "app", TargetUtilization: map[corev1.ResourceName]int32{ - corev1.ResourceCPU: 90, corev1.ResourceMemory: 80, }, }, { ContainerName: "istio-proxy", TargetUtilization: map[corev1.ResourceName]int32{ - corev1.ResourceCPU: 90, - corev1.ResourceMemory: 90, + corev1.ResourceCPU: 90, }, }, }, @@ -358,16 +356,13 @@ func TestUpdateRecommendation(t *testing.T) { Horizontal: v1beta1.HorizontalRecommendations{ TargetUtilizations: []v1beta1.HPATargetUtilizationRecommendationPerContainer{ { - ContainerName: "app", - TargetUtilization: map[corev1.ResourceName]int32{ - corev1.ResourceCPU: 90, - }, + ContainerName: "app", + TargetUtilization: map[corev1.ResourceName]int32{}, }, { ContainerName: "istio-proxy", TargetUtilization: map[corev1.ResourceName]int32{ - corev1.ResourceCPU: 90, - corev1.ResourceMemory: 90, + corev1.ResourceCPU: 90, }, }, },