diff --git a/api/autoscaling/v2/horizontalpodautoscaler_webhook_test.go b/api/autoscaling/v2/horizontalpodautoscaler_webhook_test.go index 72d86398..5d9cf2ac 100644 --- a/api/autoscaling/v2/horizontalpodautoscaler_webhook_test.go +++ b/api/autoscaling/v2/horizontalpodautoscaler_webhook_test.go @@ -50,15 +50,18 @@ func mutateTest(before, after, torotise string) { err = yaml.NewYAMLOrJSONDecoder(bytes.NewReader(y), 4096).Decode(tor) status := tor.Status Expect(err).NotTo(HaveOccurred()) - err = k8sClient.Create(ctx, tor) + err = k8sClient.Create(ctx, tor.DeepCopy()) Expect(err).NotTo(HaveOccurred()) defer func() { err = k8sClient.Delete(ctx, tor) Expect(err).NotTo(HaveOccurred()) }() + + err = k8sClient.Get(ctx, types.NamespacedName{Name: tor.GetName(), Namespace: tor.GetNamespace()}, tor) + Expect(err).NotTo(HaveOccurred()) tor.Status = status - //nolint:errcheck - k8sClient.Status().Update(ctx, tor) + err = k8sClient.Status().Update(ctx, tor) + Expect(err).NotTo(HaveOccurred()) y, err = os.ReadFile(before) Expect(err).NotTo(HaveOccurred()) @@ -87,9 +90,6 @@ func mutateTest(before, after, torotise string) { var _ = Describe("v2.HPA Webhook", func() { Context("mutating", func() { - It("nothing to do", func() { - mutateTest(filepath.Join("testdata", "mutating", "nothing-to-do", "before.yaml"), filepath.Join("testdata", "mutating", "nothing-to-do", "after.yaml"), filepath.Join("testdata", "mutating", "nothing-to-do", "tortoise.yaml")) - }) It("HPA is mutated based on the recommendation", func() { mutateTest(filepath.Join("testdata", "mutating", "mutate-by-recommendations", "before.yaml"), filepath.Join("testdata", "mutating", "mutate-by-recommendations", "after.yaml"), filepath.Join("testdata", "mutating", "mutate-by-recommendations", "tortoise.yaml")) }) diff --git a/api/autoscaling/v2/testdata/mutating/has-annotation-but-invalid1/tortoise.yaml b/api/autoscaling/v2/testdata/mutating/has-annotation-but-invalid1/tortoise.yaml index f7a45a80..e342e242 100644 --- a/api/autoscaling/v2/testdata/mutating/has-annotation-but-invalid1/tortoise.yaml +++ b/api/autoscaling/v2/testdata/mutating/has-annotation-but-invalid1/tortoise.yaml @@ -22,6 +22,15 @@ spec: memory: Vertical status: tortoisePhase: Working + containerResourcePhases: + - containerName: "nginx" + resourcePhases: + cpu: Working + memory: Working + - containerName: "istio-proxy" + resourcePhases: + cpu: Working + memory: Working targets: deployment: sample horizontalPodAutoscaler: sample diff --git a/api/autoscaling/v2/testdata/mutating/has-annotation-but-invalid2/tortoise.yaml b/api/autoscaling/v2/testdata/mutating/has-annotation-but-invalid2/tortoise.yaml index 67276304..e7cbfd74 100644 --- a/api/autoscaling/v2/testdata/mutating/has-annotation-but-invalid2/tortoise.yaml +++ b/api/autoscaling/v2/testdata/mutating/has-annotation-but-invalid2/tortoise.yaml @@ -22,6 +22,15 @@ spec: memory: Vertical status: tortoisePhase: Working + containerResourcePhases: + - containerName: "nginx" + resourcePhases: + cpu: Working + memory: Working + - containerName: "istio-proxy" + resourcePhases: + cpu: Working + memory: Working targets: deployment: sample horizontalPodAutoscaler: sample2 diff --git a/api/autoscaling/v2/testdata/mutating/mutate-by-recommendations/tortoise.yaml b/api/autoscaling/v2/testdata/mutating/mutate-by-recommendations/tortoise.yaml index f7a45a80..e342e242 100644 --- a/api/autoscaling/v2/testdata/mutating/mutate-by-recommendations/tortoise.yaml +++ b/api/autoscaling/v2/testdata/mutating/mutate-by-recommendations/tortoise.yaml @@ -22,6 +22,15 @@ spec: memory: Vertical status: tortoisePhase: Working + containerResourcePhases: + - containerName: "nginx" + resourcePhases: + cpu: Working + memory: Working + - containerName: "istio-proxy" + resourcePhases: + cpu: Working + memory: Working targets: deployment: sample horizontalPodAutoscaler: sample diff --git a/api/autoscaling/v2/testdata/mutating/nothing-to-do/after.yaml b/api/autoscaling/v2/testdata/mutating/nothing-to-do/after.yaml deleted file mode 100644 index fa1875c6..00000000 --- a/api/autoscaling/v2/testdata/mutating/nothing-to-do/after.yaml +++ /dev/null @@ -1,27 +0,0 @@ -apiVersion: autoscaling/v2 -kind: HorizontalPodAutoscaler -metadata: - name: sample - namespace: default -spec: - maxReplicas: 10 - metrics: - - type: ContainerResource - containerResource: - name: cpu - container: nginx - target: - type: Utilization - averageUtilization: 60 - - type: ContainerResource - containerResource: - name: cpu - container: istio-proxy - target: - type: Utilization - averageUtilization: 60 - minReplicas: 3 - scaleTargetRef: - apiVersion: apps/v1 - kind: Deployment - name: sample \ No newline at end of file diff --git a/api/autoscaling/v2/testdata/mutating/nothing-to-do/before.yaml b/api/autoscaling/v2/testdata/mutating/nothing-to-do/before.yaml deleted file mode 100644 index fa1875c6..00000000 --- a/api/autoscaling/v2/testdata/mutating/nothing-to-do/before.yaml +++ /dev/null @@ -1,27 +0,0 @@ -apiVersion: autoscaling/v2 -kind: HorizontalPodAutoscaler -metadata: - name: sample - namespace: default -spec: - maxReplicas: 10 - metrics: - - type: ContainerResource - containerResource: - name: cpu - container: nginx - target: - type: Utilization - averageUtilization: 60 - - type: ContainerResource - containerResource: - name: cpu - container: istio-proxy - target: - type: Utilization - averageUtilization: 60 - minReplicas: 3 - scaleTargetRef: - apiVersion: apps/v1 - kind: Deployment - name: sample \ No newline at end of file diff --git a/api/autoscaling/v2/testdata/mutating/nothing-to-do/tortoise.yaml b/api/autoscaling/v2/testdata/mutating/nothing-to-do/tortoise.yaml deleted file mode 100644 index feb5dd5e..00000000 --- a/api/autoscaling/v2/testdata/mutating/nothing-to-do/tortoise.yaml +++ /dev/null @@ -1,22 +0,0 @@ -apiVersion: autoscaling.mercari.com/v1beta1 -kind: Tortoise -metadata: - name: tortoise-sample - namespace: default -spec: - updateMode: "Off" - deletionPolicy: "DeleteAll" - targetRefs: - horizontalPodAutoscalerName: sample - scaleTargetRef: - kind: Deployment - name: sample - resourcePolicy: - - containerName: istio-proxy - autoscalingPolicy: - cpu: Horizontal - memory: Vertical - - containerName: nginx - autoscalingPolicy: - cpu: Horizontal - memory: Vertical \ No newline at end of file diff --git a/api/v1beta1/tortoise_types.go b/api/v1beta1/tortoise_types.go index 9d632486..c670a0d8 100644 --- a/api/v1beta1/tortoise_types.go +++ b/api/v1beta1/tortoise_types.go @@ -118,7 +118,7 @@ type TargetRefs struct { // It should be the same as the target of HPA. ScaleTargetRef CrossVersionObjectReference `json:"scaleTargetRef" protobuf:"bytes,1,name=scaleTargetRef"` // HorizontalPodAutoscalerName is the name of the target HPA. - // The target of this HPA should be the same as the DeploymentName above. + // The target of this HPA should be the same as the ScaleTargetRef above. // The target HPA should have the ContainerResource type metric or the external metric refers to the container resource utilization. // Please check out the document for more detail: https://github.com/mercari/tortoise/blob/master/docs/horizontal.md#supported-metrics-in-hpa // @@ -143,12 +143,45 @@ type CrossVersionObjectReference struct { // TortoiseStatus defines the observed state of Tortoise type TortoiseStatus struct { - TortoisePhase TortoisePhase `json:"tortoisePhase" protobuf:"bytes,1,name=tortoisePhase"` - Conditions Conditions `json:"conditions" protobuf:"bytes,2,name=conditions"` - Recommendations Recommendations `json:"recommendations" protobuf:"bytes,3,name=recommendations"` - Targets TargetsStatus `json:"targets" protobuf:"bytes,4,name=targets"` + TortoisePhase TortoisePhase `json:"tortoisePhase" protobuf:"bytes,1,name=tortoisePhase"` + Conditions Conditions `json:"conditions" protobuf:"bytes,2,name=conditions"` + Recommendations Recommendations `json:"recommendations" protobuf:"bytes,3,name=recommendations"` + Targets TargetsStatus `json:"targets" protobuf:"bytes,4,name=targets"` + ContainerResourcePhases []ContainerResourcePhases `json:"containerResourcePhases" protobuf:"bytes,5,name=containerResourcePhases"` } +type ContainerResourcePhases struct { + // ContainerName is the name of target container. + ContainerName string `json:"containerName" protobuf:"bytes,1,name=containerName"` + // ResourcePhases is the phase of each resource of this container. + ResourceePhases map[v1.ResourceName]ContainerResourcePhase `json:"resourcePhases" protobuf:"bytes,2,name=resourcePhases"` +} + +type ContainerResourcePhase string + +const ( + ContainerResourcePhaseGatheringData ContainerResourcePhase = "GatheringData" + ContainerResourcePhaseWorking ContainerResourcePhase = "Working" +) + +type TortoisePhase string + +const ( + // TortoisePhaseInitializing means tortoise is just created and initializing some components (HPA and VPAs), + // and wait for those components to be ready. + TortoisePhaseInitializing TortoisePhase = "Initializing" + // TortoisePhaseGatheringData means tortoise is now gathering data and cannot make the accurate recommendations. + TortoisePhaseGatheringData TortoisePhase = "GatheringData" + // TortoisePhaseWorking means tortoise is making the recommendations, + // and applying the recommendation values. + TortoisePhaseWorking TortoisePhase = "Working" + // TortoisePhaseEmergency means tortoise is in the emergency mode. + TortoisePhaseEmergency TortoisePhase = "Emergency" + // TortoisePhaseBackToNormal means tortoise was in the emergency mode, and now it's coming back to the normal operation. + // During TortoisePhaseBackToNormal, the number of replicas of workloads are gradually reduced to the usual value. + TortoisePhaseBackToNormal TortoisePhase = "BackToNormal" +) + type TargetsStatus struct { // +optional HorizontalPodAutoscaler string `json:"horizontalPodAutoscaler" protobuf:"bytes,1,opt,name=horizontalPodAutoscaler"` @@ -223,24 +256,6 @@ type ReplicasRecommendation struct { UpdatedAt metav1.Time `json:"updatedAt,omitempty" protobuf:"bytes,6,opt,name=updatedAt"` } -type TortoisePhase string - -const ( - // TortoisePhaseInitializing means tortoise is just created and initializing some components (HPA and VPAs), - // and wait for those components to be ready. - TortoisePhaseInitializing TortoisePhase = "Initializing" - // TortoisePhaseGatheringData means tortoise is now gathering data and cannot make the accurate recommendations. - TortoisePhaseGatheringData TortoisePhase = "GatheringData" - // TortoisePhaseWorking means tortoise is making the recommendations, - // and applying the recommendation values. - TortoisePhaseWorking TortoisePhase = "Working" - // TortoisePhaseEmergency means tortoise is in the emergency mode. - TortoisePhaseEmergency TortoisePhase = "Emergency" - // TortoisePhaseBackToNormal means tortoise was in the emergency mode, and now it's coming back to the normal operation. - // During TortoisePhaseBackToNormal, the number of replicas of workloads are gradually reduced to the usual value. - TortoisePhaseBackToNormal TortoisePhase = "BackToNormal" -) - type HPATargetUtilizationRecommendationPerContainer struct { // ContainerName is the name of target container. ContainerName string `json:"containerName" protobuf:"bytes,1,name=containerName"` diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index 1dd02545..ec0ba3df 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -92,6 +92,28 @@ func (in *ContainerRecommendationFromVPA) DeepCopy() *ContainerRecommendationFro return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ContainerResourcePhases) DeepCopyInto(out *ContainerResourcePhases) { + *out = *in + if in.ResourceePhases != nil { + in, out := &in.ResourceePhases, &out.ResourceePhases + *out = make(map[v1.ResourceName]ContainerResourcePhase, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ContainerResourcePhases. +func (in *ContainerResourcePhases) DeepCopy() *ContainerResourcePhases { + if in == nil { + return nil + } + out := new(ContainerResourcePhases) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ContainerResourcePolicy) DeepCopyInto(out *ContainerResourcePolicy) { *out = *in @@ -432,6 +454,13 @@ func (in *TortoiseStatus) DeepCopyInto(out *TortoiseStatus) { in.Conditions.DeepCopyInto(&out.Conditions) in.Recommendations.DeepCopyInto(&out.Recommendations) in.Targets.DeepCopyInto(&out.Targets) + if in.ContainerResourcePhases != nil { + in, out := &in.ContainerResourcePhases, &out.ContainerResourcePhases + *out = make([]ContainerResourcePhases, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TortoiseStatus. diff --git a/config/crd/bases/autoscaling.mercari.com_tortoises.yaml b/config/crd/bases/autoscaling.mercari.com_tortoises.yaml index 95d4d6f3..026a75c5 100644 --- a/config/crd/bases/autoscaling.mercari.com_tortoises.yaml +++ b/config/crd/bases/autoscaling.mercari.com_tortoises.yaml @@ -447,7 +447,7 @@ spec: properties: horizontalPodAutoscalerName: description: "HorizontalPodAutoscalerName is the name of the target - HPA. The target of this HPA should be the same as the DeploymentName + HPA. The target of this HPA should be the same as the ScaleTargetRef above. The target HPA should have the ContainerResource type metric or the external metric refers to the container resource utilization. Please check out the document for more detail: @@ -585,6 +585,23 @@ spec: - type x-kubernetes-list-type: map type: object + containerResourcePhases: + items: + properties: + containerName: + description: ContainerName is the name of target container. + type: string + resourcePhases: + additionalProperties: + type: string + description: ResourcePhases is the phase of each resource of + this container. + type: object + required: + - containerName + - resourcePhases + type: object + type: array recommendations: properties: horizontal: @@ -737,6 +754,7 @@ spec: type: string required: - conditions + - containerResourcePhases - recommendations - targets - tortoisePhase diff --git a/controllers/testdata/deletion-no-delete/before/tortoise.yaml b/controllers/testdata/deletion-no-delete/before/tortoise.yaml index 45c47157..c3ef11ba 100644 --- a/controllers/testdata/deletion-no-delete/before/tortoise.yaml +++ b/controllers/testdata/deletion-no-delete/before/tortoise.yaml @@ -83,3 +83,12 @@ status: - name: tortoise-monitor-mercari role: Monitor tortoisePhase: Working + containerResourcePhases: + - containerName: "nginx" + resourcePhases: + cpu: Working + memory: Working + - containerName: "istio-proxy" + resourcePhases: + cpu: Working + memory: Working diff --git a/controllers/testdata/deletion-policy-all/before/tortoise.yaml b/controllers/testdata/deletion-policy-all/before/tortoise.yaml index c73cc9e4..b62a9d0f 100644 --- a/controllers/testdata/deletion-policy-all/before/tortoise.yaml +++ b/controllers/testdata/deletion-policy-all/before/tortoise.yaml @@ -83,3 +83,12 @@ status: - name: tortoise-monitor-mercari role: Monitor tortoisePhase: Working + containerResourcePhases: + - containerName: "nginx" + resourcePhases: + cpu: Working + memory: Working + - containerName: "istio-proxy" + resourcePhases: + cpu: Working + memory: Working diff --git a/controllers/testdata/mutable-autoscalingpolicy-add-another-horizontal/after/tortoise.yaml b/controllers/testdata/mutable-autoscalingpolicy-add-another-horizontal/after/tortoise.yaml index 7871be02..796883c4 100644 --- a/controllers/testdata/mutable-autoscalingpolicy-add-another-horizontal/after/tortoise.yaml +++ b/controllers/testdata/mutable-autoscalingpolicy-add-another-horizontal/after/tortoise.yaml @@ -91,3 +91,12 @@ status: - name: tortoise-monitor-mercari role: Monitor tortoisePhase: Working + containerResourcePhases: + - containerName: "nginx" + resourcePhases: + cpu: Working + memory: Working + - containerName: "istio-proxy" + resourcePhases: + cpu: Working + memory: Working diff --git a/controllers/testdata/mutable-autoscalingpolicy-add-another-horizontal/before/tortoise.yaml b/controllers/testdata/mutable-autoscalingpolicy-add-another-horizontal/before/tortoise.yaml index 5369d4cf..19af0db3 100644 --- a/controllers/testdata/mutable-autoscalingpolicy-add-another-horizontal/before/tortoise.yaml +++ b/controllers/testdata/mutable-autoscalingpolicy-add-another-horizontal/before/tortoise.yaml @@ -82,3 +82,12 @@ status: - name: tortoise-monitor-mercari role: Monitor tortoisePhase: Working + containerResourcePhases: + - containerName: "nginx" + resourcePhases: + cpu: Working + memory: Working + - containerName: "istio-proxy" + resourcePhases: + cpu: Working + memory: Working diff --git a/controllers/testdata/mutable-autoscalingpolicy-no-hpa-and-add-horizontal/after/tortoise.yaml b/controllers/testdata/mutable-autoscalingpolicy-no-hpa-and-add-horizontal/after/tortoise.yaml index 902c0442..f534b8c5 100644 --- a/controllers/testdata/mutable-autoscalingpolicy-no-hpa-and-add-horizontal/after/tortoise.yaml +++ b/controllers/testdata/mutable-autoscalingpolicy-no-hpa-and-add-horizontal/after/tortoise.yaml @@ -89,3 +89,12 @@ status: - name: tortoise-monitor-mercari role: Monitor tortoisePhase: Working + containerResourcePhases: + - containerName: "nginx" + resourcePhases: + cpu: Working + memory: Working + - containerName: "istio-proxy" + resourcePhases: + cpu: Working + memory: Working diff --git a/controllers/testdata/mutable-autoscalingpolicy-no-hpa-and-add-horizontal/before/tortoise.yaml b/controllers/testdata/mutable-autoscalingpolicy-no-hpa-and-add-horizontal/before/tortoise.yaml index 24c54b34..910d6027 100644 --- a/controllers/testdata/mutable-autoscalingpolicy-no-hpa-and-add-horizontal/before/tortoise.yaml +++ b/controllers/testdata/mutable-autoscalingpolicy-no-hpa-and-add-horizontal/before/tortoise.yaml @@ -87,3 +87,12 @@ status: - name: tortoise-monitor-mercari role: Monitor tortoisePhase: Working + containerResourcePhases: + - containerName: "nginx" + resourcePhases: + cpu: Working + memory: Working + - containerName: "istio-proxy" + resourcePhases: + cpu: Working + memory: Working diff --git a/controllers/testdata/mutable-autoscalingpolicy-remove-horizontal/after/tortoise.yaml b/controllers/testdata/mutable-autoscalingpolicy-remove-horizontal/after/tortoise.yaml index d2c249f4..33454c45 100644 --- a/controllers/testdata/mutable-autoscalingpolicy-remove-horizontal/after/tortoise.yaml +++ b/controllers/testdata/mutable-autoscalingpolicy-remove-horizontal/after/tortoise.yaml @@ -88,3 +88,12 @@ status: - name: tortoise-monitor-mercari role: Monitor tortoisePhase: Working + containerResourcePhases: + - containerName: "nginx" + resourcePhases: + cpu: Working + memory: Working + - containerName: "istio-proxy" + resourcePhases: + cpu: Working + memory: Working diff --git a/controllers/testdata/mutable-autoscalingpolicy-remove-horizontal/before/tortoise.yaml b/controllers/testdata/mutable-autoscalingpolicy-remove-horizontal/before/tortoise.yaml index 6bedb0a6..7a97cd9d 100644 --- a/controllers/testdata/mutable-autoscalingpolicy-remove-horizontal/before/tortoise.yaml +++ b/controllers/testdata/mutable-autoscalingpolicy-remove-horizontal/before/tortoise.yaml @@ -82,3 +82,12 @@ status: - name: tortoise-monitor-mercari role: Monitor tortoisePhase: Working + containerResourcePhases: + - containerName: "nginx" + resourcePhases: + cpu: Working + memory: Working + - containerName: "istio-proxy" + resourcePhases: + cpu: Working + memory: Working 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 7797b75f..f26dfbe6 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 @@ -86,3 +86,12 @@ status: - name: tortoise-monitor-mercari role: Monitor tortoisePhase: Working + containerResourcePhases: + - containerName: "nginx" + resourcePhases: + cpu: Working + memory: Working + - containerName: "istio-proxy" + resourcePhases: + cpu: Working + memory: Working 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 238f072a..0a1b5ce8 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 @@ -78,3 +78,12 @@ status: - name: tortoise-monitor-mercari role: Monitor tortoisePhase: Working + containerResourcePhases: + - containerName: "nginx" + resourcePhases: + cpu: Working + memory: Working + - containerName: "istio-proxy" + resourcePhases: + cpu: Working + memory: Working 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 index 5978faa0..4c11b8b3 100644 --- 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 @@ -87,3 +87,12 @@ status: - name: tortoise-monitor-mercari role: Monitor tortoisePhase: Working + containerResourcePhases: + - containerName: "nginx" + resourcePhases: + cpu: Working + memory: Working + - containerName: "istio-proxy" + resourcePhases: + cpu: Working + memory: Working 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 index 078c6ed6..eb6a5868 100644 --- 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 @@ -79,3 +79,12 @@ status: - name: tortoise-monitor-mercari role: Monitor tortoisePhase: Working + containerResourcePhases: + - containerName: "nginx" + resourcePhases: + cpu: Working + memory: Working + - containerName: "istio-proxy" + resourcePhases: + cpu: Working + memory: Working 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 614d1646..f9c4fafd 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 @@ -91,3 +91,12 @@ status: - name: tortoise-monitor-mercari role: Monitor tortoisePhase: Emergency + containerResourcePhases: + - containerName: "nginx" + resourcePhases: + cpu: Working + memory: Working + - containerName: "istio-proxy" + resourcePhases: + cpu: Working + memory: Working 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 c78e6991..b6403b24 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 @@ -83,3 +83,12 @@ status: - name: tortoise-monitor-mercari role: Monitor tortoisePhase: Working + containerResourcePhases: + - containerName: "nginx" + resourcePhases: + cpu: Working + memory: Working + - containerName: "istio-proxy" + resourcePhases: + cpu: Working + memory: Working 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 04b48143..799e60c0 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 @@ -89,3 +89,12 @@ status: - name: tortoise-monitor-mercari role: Monitor tortoisePhase: Working + containerResourcePhases: + - containerName: "nginx" + resourcePhases: + cpu: Working + memory: Working + - containerName: "istio-proxy" + resourcePhases: + cpu: Working + memory: Working 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 8b22c9af..3d6113eb 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 @@ -82,3 +82,12 @@ status: - name: tortoise-monitor-mercari role: Monitor tortoisePhase: Working + containerResourcePhases: + - containerName: "nginx" + resourcePhases: + cpu: Working + memory: Working + - containerName: "istio-proxy" + resourcePhases: + cpu: Working + memory: Working 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 c9beeacf..68bae4e1 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 @@ -90,3 +90,12 @@ status: - name: tortoise-monitor-mercari role: Monitor tortoisePhase: Working + containerResourcePhases: + - containerName: "nginx" + resourcePhases: + cpu: Working + memory: Working + - containerName: "istio-proxy" + resourcePhases: + cpu: Working + memory: Working 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 4d1bb9d7..c7ee5a6b 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 @@ -82,3 +82,12 @@ status: - name: tortoise-monitor-mercari role: Monitor tortoisePhase: Working + containerResourcePhases: + - containerName: "nginx" + resourcePhases: + cpu: Working + memory: Working + - containerName: "istio-proxy" + resourcePhases: + cpu: Working + memory: Working 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 f85db2a2..b571a8ce 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 @@ -65,3 +65,12 @@ status: - name: tortoise-monitor-mercari role: Monitor tortoisePhase: Working + containerResourcePhases: + - containerName: "nginx" + resourcePhases: + cpu: Working + memory: Working + - containerName: "istio-proxy" + resourcePhases: + cpu: Working + memory: Working 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 f8c05329..304eb0ca 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 @@ -61,3 +61,12 @@ status: - name: tortoise-monitor-mercari role: Monitor tortoisePhase: Working + containerResourcePhases: + - containerName: "nginx" + resourcePhases: + cpu: Working + memory: Working + - containerName: "istio-proxy" + resourcePhases: + cpu: Working + memory: Working 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 ab0fa1a2..cdfe52d2 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 @@ -65,3 +65,12 @@ status: - name: tortoise-monitor-mercari role: Monitor tortoisePhase: Emergency + containerResourcePhases: + - containerName: "nginx" + resourcePhases: + cpu: Working + memory: Working + - containerName: "istio-proxy" + resourcePhases: + cpu: Working + memory: Working 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 30ca62b1..4527c364 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 @@ -61,3 +61,12 @@ status: - name: tortoise-monitor-mercari role: Monitor tortoisePhase: Working + containerResourcePhases: + - containerName: "nginx" + resourcePhases: + cpu: Working + memory: Working + - containerName: "istio-proxy" + resourcePhases: + cpu: Working + memory: Working 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 62369bdf..bc3a573f 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 @@ -64,3 +64,12 @@ status: - name: tortoise-monitor-mercari role: Monitor tortoisePhase: Working + containerResourcePhases: + - containerName: "nginx" + resourcePhases: + cpu: Working + memory: Working + - containerName: "istio-proxy" + resourcePhases: + cpu: Working + memory: Working 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 1eecdb27..fafecbf0 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 @@ -60,3 +60,12 @@ status: - name: tortoise-monitor-mercari role: Monitor tortoisePhase: Working + containerResourcePhases: + - containerName: "nginx" + resourcePhases: + cpu: Working + memory: Working + - containerName: "istio-proxy" + resourcePhases: + cpu: Working + memory: Working 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 73c574be..4d8ad511 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 @@ -363,7 +363,7 @@ spec: description: TargetRefs has reference to involved resources. properties: horizontalPodAutoscalerName: - description: "HorizontalPodAutoscalerName is the name of the target HPA. The target of this HPA should be the same as the DeploymentName above. The target HPA should have the ContainerResource type metric or the external metric refers to the container resource utilization. Please check out the document for more detail: https://github.com/mercari/tortoise/blob/master/docs/horizontal.md#supported-metrics-in-hpa \n You can specify either of existing HPA only. This is an optional field, and if you don't specify this field, tortoise will create a new default HPA named `tortoise-hpa-{tortoise name}`." + description: "HorizontalPodAutoscalerName is the name of the target HPA. The target of this HPA should be the same as the ScaleTargetRef above. The target HPA should have the ContainerResource type metric or the external metric refers to the container resource utilization. Please check out the document for more detail: https://github.com/mercari/tortoise/blob/master/docs/horizontal.md#supported-metrics-in-hpa \n You can specify either of existing HPA only. This is an optional field, and if you don't specify this field, tortoise will create a new default HPA named `tortoise-hpa-{tortoise name}`." type: string scaleTargetRef: description: ScaleTargetRef is the target of scaling. It should be the same as the target of HPA. @@ -475,6 +475,22 @@ spec: - type x-kubernetes-list-type: map type: object + containerResourcePhases: + items: + properties: + containerName: + description: ContainerName is the name of target container. + type: string + resourcePhases: + additionalProperties: + type: string + description: ResourcePhases is the phase of each resource of this container. + type: object + required: + - containerName + - resourcePhases + type: object + type: array recommendations: properties: horizontal: @@ -608,6 +624,7 @@ spec: type: string required: - conditions + - containerResourcePhases - recommendations - targets - 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 06dbcfa4..0a4a74d0 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 @@ -363,7 +363,7 @@ spec: description: TargetRefs has reference to involved resources. properties: horizontalPodAutoscalerName: - description: "HorizontalPodAutoscalerName is the name of the target HPA. The target of this HPA should be the same as the DeploymentName above. The target HPA should have the ContainerResource type metric or the external metric refers to the container resource utilization. Please check out the document for more detail: https://github.com/mercari/tortoise/blob/master/docs/horizontal.md#supported-metrics-in-hpa \n You can specify either of existing HPA only. This is an optional field, and if you don't specify this field, tortoise will create a new default HPA named `tortoise-hpa-{tortoise name}`." + description: "HorizontalPodAutoscalerName is the name of the target HPA. The target of this HPA should be the same as the ScaleTargetRef above. The target HPA should have the ContainerResource type metric or the external metric refers to the container resource utilization. Please check out the document for more detail: https://github.com/mercari/tortoise/blob/master/docs/horizontal.md#supported-metrics-in-hpa \n You can specify either of existing HPA only. This is an optional field, and if you don't specify this field, tortoise will create a new default HPA named `tortoise-hpa-{tortoise name}`." type: string scaleTargetRef: description: ScaleTargetRef is the target of scaling. It should be the same as the target of HPA. @@ -475,6 +475,22 @@ spec: - type x-kubernetes-list-type: map type: object + containerResourcePhases: + items: + properties: + containerName: + description: ContainerName is the name of target container. + type: string + resourcePhases: + additionalProperties: + type: string + description: ResourcePhases is the phase of each resource of this container. + type: object + required: + - containerName + - resourcePhases + type: object + type: array recommendations: properties: horizontal: @@ -608,6 +624,7 @@ spec: type: string required: - conditions + - containerResourcePhases - recommendations - targets - tortoisePhase