From 1f18c4bdca9ce0fbb689dfc4f6bee5e5e445824e Mon Sep 17 00:00:00 2001 From: Vincent Boulineau Date: Thu, 6 Feb 2025 14:15:13 +0100 Subject: [PATCH] Share common types between Autoscaler versions --- .github/CODEOWNERS | 5 +- .../common/datadogpodautoscaler_types.go | 427 +++++++++++++++++ api/datadoghq/common/zz_generated.deepcopy.go | 436 +++++++++++++++++ .../v1alpha1/datadogpodautoscaler_types.go | 420 +--------------- .../v1alpha1/zz_generated.deepcopy.go | 445 +---------------- .../v1alpha2/datadogpodautoscaler_types.go | 403 +--------------- .../v1alpha2/zz_generated.deepcopy.go | 447 +----------------- .../datadoghq.com_datadogpodautoscalers.yaml | 102 ++-- ...hq.com_datadogpodautoscalers_v1alpha1.json | 143 +----- ...hq.com_datadogpodautoscalers_v1alpha2.json | 18 +- 10 files changed, 956 insertions(+), 1890 deletions(-) create mode 100644 api/datadoghq/common/datadogpodautoscaler_types.go diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index a7aace7cb..e05d7956d 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -3,7 +3,7 @@ # and another the rest of the directory. # All your base -* @DataDog/container-ecosystems +/.* @DataDog/container-ecosystems # Dev Container /.devcontainer @DataDog/container-ecosystems @DataDog/container-platform @@ -21,5 +21,4 @@ README.md @DataDog/documentation @DataDog/container-ecosystems /internal/controller/datadogagent/feature/helmcheck/* @DataDog/container-integrations -/api/datadoghq/v1alpha2/datadogpodautoscaler_types.go @DataDog/container-autoscaling -/api/datadoghq/v1alpha1/datadogpodautoscaler_types.go @DataDog/container-autoscaling +/api/**/datadogpodautoscaler*.go @DataDog/container-autoscaling diff --git a/api/datadoghq/common/datadogpodautoscaler_types.go b/api/datadoghq/common/datadogpodautoscaler_types.go new file mode 100644 index 000000000..a0c472a65 --- /dev/null +++ b/api/datadoghq/common/datadogpodautoscaler_types.go @@ -0,0 +1,427 @@ +// Unless explicitly stated otherwise all files in this repository are licensed +// under the Apache License Version 2.0. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2016-present Datadog, Inc. + +package common + +import ( + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// DatadogPodAutoscalerOwner defines the source of truth for this object (local or remote) +// +kubebuilder:validation:Enum:=Local;Remote +type DatadogPodAutoscalerOwner string + +const ( + // DatadogPodAutoscalerLocalOwner states that this `DatadogPodAutoscaler` object is created/managed outside of the Datadog app. + DatadogPodAutoscalerLocalOwner DatadogPodAutoscalerOwner = "Local" + + // DatadogPodAutoscalerRemoteOwner states that this `DatadogPodAutoscaler` object is created/managed in the Datadog app. + DatadogPodAutoscalerRemoteOwner DatadogPodAutoscalerOwner = "Remote" +) + +// DatadogPodAutoscalerUpdateStrategy defines the mode of the update policy. +// +kubebuilder:validation:Enum:=Auto;Disabled +type DatadogPodAutoscalerUpdateStrategy string + +const ( + // DatadogPodAutoscalerAutoUpdateStrategy is the default mode. + DatadogPodAutoscalerAutoUpdateStrategy DatadogPodAutoscalerUpdateStrategy = "Auto" + + // DatadogPodAutoscalerDisabledUpdateStrategy will disable the update of the target resource. + DatadogPodAutoscalerDisabledUpdateStrategy DatadogPodAutoscalerUpdateStrategy = "Disabled" +) + +// DatadogPodAutoscalerUpdatePolicy defines the policy to update the target resource. +// +kubebuilder:object:generate=true +type DatadogPodAutoscalerUpdatePolicy struct { + // Strategy defines the mode of the update policy. + Strategy DatadogPodAutoscalerUpdateStrategy `json:"strategy,omitempty"` +} + +// +// Scaling policy is inspired by the HorizontalPodAutoscalerV2 +// https://github.com/kubernetes/api/blob/master/autoscaling/v2/types.go +// Copyright 2021 The Kubernetes Authors. +// + +// DatadogPodAutoscalerScalingStrategySelect is used to specify which policy should be used while scaling in a certain direction +// +kubebuilder:validation:Enum:=Max;Min;Disabled +type DatadogPodAutoscalerScalingStrategySelect string + +const ( + // DatadogPodAutoscalerMaxChangeStrategySelect selects the policy with the highest possible change. + DatadogPodAutoscalerMaxChangeStrategySelect DatadogPodAutoscalerScalingStrategySelect = "Max" + + // DatadogPodAutoscalerMinChangeStrategySelect selects the policy with the lowest possible change. + DatadogPodAutoscalerMinChangeStrategySelect DatadogPodAutoscalerScalingStrategySelect = "Min" + + // DatadogPodAutoscalerDisabledStrategySelect disables the scaling in this direction. + DatadogPodAutoscalerDisabledStrategySelect DatadogPodAutoscalerScalingStrategySelect = "Disabled" +) + +// DatadogPodAutoscalerScalingPolicy defines the policy to scale the target resource. +// +kubebuilder:object:generate=true +type DatadogPodAutoscalerScalingPolicy struct { + // Strategy is used to specify which policy should be used. + // If not set, the default value Max is used. + // +optional + Strategy *DatadogPodAutoscalerScalingStrategySelect `json:"strategy,omitempty"` + + // Rules is a list of potential scaling polices which can be used during scaling. + // At least one policy must be specified, otherwise the DatadogPodAutoscalerScalingPolicy will be discarded as invalid + // +listType=atomic + // +optional + Rules []DatadogPodAutoscalerScalingRule `json:"rules,omitempty"` + + // StabilizationWindowSeconds is the number of seconds the controller should lookback at previous recommendations + // before deciding to apply a new one. Defaults to 0. + // +optional + // +kubebuilder:validation:Minimum=0 + // +kubebuilder:validation:Maximum=1800 + StabilizationWindowSeconds int32 `json:"stabilizationWindowSeconds,omitempty"` +} + +// DatadogPodAutoscalerScalingRuleType defines how a scaling rule value should be interpreted. +// +kubebuilder:validation:Enum:=Pods;Percent +type DatadogPodAutoscalerScalingRuleType string + +const ( + // DatadogPodAutoscalerPodsScalingRuleType specifies a change in the absolute number of pods compared to the starting number of pods. + DatadogPodAutoscalerPodsScalingRuleType DatadogPodAutoscalerScalingRuleType = "Pods" + + // DatadogPodAutoscalerPercentScalingRuleType specifies a relative amount of change compared to the starting number of pods. + DatadogPodAutoscalerPercentScalingRuleType DatadogPodAutoscalerScalingRuleType = "Percent" +) + +// DatadogPodAutoscalerScalingRule defines rules for horizontal scaling that should be true for a certain amount of time. +// +kubebuilder:object:generate=true +type DatadogPodAutoscalerScalingRule struct { + // Type is used to specify the scaling policy. + Type DatadogPodAutoscalerScalingRuleType `json:"type"` + + // Value contains the amount of change which is permitted by the policy. + // Setting it to 0 will prevent any scaling in this direction. + // +kubebuilder:validation:Minimum=0 + Value int32 `json:"value"` + + // PeriodSeconds specifies the window of time for which the policy should hold true. + // PeriodSeconds must be greater than zero and less than or equal to 1800 (30 min). + // +kubebuilder:validation:Minimum=1 + // +kubebuilder:validation:Maximum=1800 + PeriodSeconds int32 `json:"periodSeconds"` +} + +// DatadogPodAutoscalerTargetType defines the type of the target. +// +kubebuilder:validation:Enum:=PodResource;ContainerResource +type DatadogPodAutoscalerTargetType string + +const ( + // DatadogPodAutoscalerResourceTargetType allows to set pod-level resource targets. + DatadogPodAutoscalerResourceTargetType DatadogPodAutoscalerTargetType = "PodResource" + + // DatadogPodAutoscalerContainerResourceTargetType allows to set container-level resource targets. + DatadogPodAutoscalerContainerResourceTargetType DatadogPodAutoscalerTargetType = "ContainerResource" +) + +// DatadogPodAutoscalerObjective defines the objectives to reach and maintain for the target resource. +// +kubebuilder:object:generate=true +type DatadogPodAutoscalerObjective struct { + // Type sets the type of the target. + Type DatadogPodAutoscalerTargetType `json:"type"` + + // PodResource allows to set a pod-level resource target. + PodResource *DatadogPodAutoscalerResourceTarget `json:"podResource,omitempty"` + + // ContainerResource allows to set a container-level resource target. + ContainerResource *DatadogPodAutoscalerContainerResourceTarget `json:"containerResource,omitempty"` +} + +// DatadogPodAutoscalerResourceTarget defines a pod-level resource target (for instance, CPU Utilization at 80%) +// For pod-level targets, resources are the sum of all containers resources. +// Utilization is computed from sum(usage) / sum(requests). +// +kubebuilder:object:generate=true +type DatadogPodAutoscalerResourceTarget struct { + // Name is the name of the resource. + // +kubebuilder:validation:Enum:=cpu + Name corev1.ResourceName `json:"name"` + + // Value is the value of the target. + Value DatadogPodAutoscalerTargetValue `json:"value"` +} + +// DatadogPodAutoscalerContainerResourceTarget defines a container-level resource target (for instance, CPU Utilization for container named "foo" at 80%) +// +kubebuilder:object:generate=true +type DatadogPodAutoscalerContainerResourceTarget struct { + // Name is the name of the resource. + // +kubebuilder:validation:Enum:=cpu + Name corev1.ResourceName `json:"name"` + + // Value is the value of the target. + Value DatadogPodAutoscalerTargetValue `json:"value"` + + // Container is the name of the container. + Container string `json:"container"` +} + +// DatadogPodAutoscalerTargetValueType specifies the type of metric being targeted, and should be either +// kubebuilder:validation:Enum:=Utilization +type DatadogPodAutoscalerTargetValueType string + +const ( + // DatadogPodAutoscalerUtilizationTargetValueType declares a MetricTarget is an AverageUtilization value + DatadogPodAutoscalerUtilizationTargetValueType DatadogPodAutoscalerTargetValueType = "Utilization" +) + +// DatadogPodAutoscalerTargetValue defines the value of the target. +// +kubebuilder:object:generate=true +type DatadogPodAutoscalerTargetValue struct { + // Type specifies how the value is expressed (Absolute or Utilization). + Type DatadogPodAutoscalerTargetValueType `json:"type"` + + // Utilization defines a percentage of the target compared to requested resource + // +kubebuilder:validation:Minimum=0 + // +kubebuilder:validation:Maximum=100 + Utilization *int32 `json:"utilization,omitempty"` +} + +// DatadogPodAutoscalerConstraints defines constraints that should always be respected. +// +kubebuilder:object:generate=true +type DatadogPodAutoscalerConstraints struct { + // MinReplicas is the lower limit for the number of pod replicas. Needs to be >= 1. Defaults to 1. + // +kubebuilder:validation:Minimum=1 + MinReplicas *int32 `json:"minReplicas,omitempty"` + + // MaxReplicas is the upper limit for the number of POD replicas. Needs to be >= minReplicas. + MaxReplicas int32 `json:"maxReplicas"` + + // Containers defines constraints for the containers. + Containers []DatadogPodAutoscalerContainerConstraints `json:"containers,omitempty"` +} + +// DatadogPodAutoscalerContainerConstraints defines constraints that should always be respected for a container. +// If no constraints are set, it enables resource scaling for all containers without any constraints. +// +kubebuilder:object:generate=true +type DatadogPodAutoscalerContainerConstraints struct { + // Name is the name of the container. Can be "*" to apply to all containers. + Name string `json:"name"` + + // Enabled, if false, allows one to disable resource autoscaling for the container. Defaults to true. + Enabled *bool `json:"enabled,omitempty"` + + // Requests defines the constraints for the requests of the container. + Requests *DatadogPodAutoscalerContainerResourceConstraints `json:"requests,omitempty"` +} + +// DatadogPodAutoscalerContainerResourceConstraints defines constraints for the resources recommended for a container. +// +kubebuilder:object:generate=true +type DatadogPodAutoscalerContainerResourceConstraints struct { + // MinAllowed is the lower limit for the requests of the container. + // +optional + MinAllowed corev1.ResourceList `json:"minAllowed,omitempty"` + + // MaxAllowed is the upper limit for the requests of the container. + // +optional + MaxAllowed corev1.ResourceList `json:"maxAllowed,omitempty"` +} + +// DatadogPodAutoscalerStatus defines the observed state of DatadogPodAutoscaler +// +kubebuilder:object:generate=true +type DatadogPodAutoscalerStatus struct { + // Vertical is the status of the vertical scaling, if activated. + // +optional + Vertical *DatadogPodAutoscalerVerticalStatus `json:"vertical,omitempty"` + + // Horizontal is the status of the horizontal scaling, if activated. + // +optional + Horizontal *DatadogPodAutoscalerHorizontalStatus `json:"horizontal,omitempty"` + + // CurrentReplicas is the current number of pods for the targetRef observed by the controller. + // +optional + CurrentReplicas *int32 `json:"currentReplicas,omitempty"` + + // Conditions describe the current state of the DatadogPodAutoscaler operations. + // +patchMergeKey=type + // +patchStrategy=merge + // +listType=map + // +listMapKey=type + // +optional + Conditions []DatadogPodAutoscalerCondition `json:"conditions,omitempty"` +} + +// DatadogPodAutoscalerValueSource defines the source of the value used to scale the target resource. +type DatadogPodAutoscalerValueSource string + +const ( + // DatadogPodAutoscalerAutoscalingValueSource is a recommendation that comes from active autoscaling. + DatadogPodAutoscalerAutoscalingValueSource DatadogPodAutoscalerValueSource = "Autoscaling" + + // DatadogPodAutoscalerManualValueSource is a recommendation that comes from manually applying a recommendation. + DatadogPodAutoscalerManualValueSource DatadogPodAutoscalerValueSource = "Manual" + + // DatadogPodAutoscalerLocalValueSource is a recommendation that comes from the local fallback. + DatadogPodAutoscalerLocalValueSource DatadogPodAutoscalerValueSource = "Local" +) + +// DatadogPodAutoscalerHorizontalStatus defines the status of the horizontal scaling +// +kubebuilder:object:generate=true +type DatadogPodAutoscalerHorizontalStatus struct { + // Target is the current target of the horizontal scaling + Target *DatadogPodAutoscalerHorizontalTargetStatus `json:"target,omitempty"` + + // LastActions are the last successful actions done by the controller + LastActions []DatadogPodAutoscalerHorizontalAction `json:"lastActions,omitempty"` +} + +// DatadogPodAutoscalerHorizontalTargetStatus defines the current target of the horizontal scaling +// +kubebuilder:object:generate=true +type DatadogPodAutoscalerHorizontalTargetStatus struct { + // Source is the source of the value used to scale the target resource + Source DatadogPodAutoscalerValueSource `json:"source"` + + // GeneratedAt is the timestamp at which the recommendation was generated + GeneratedAt metav1.Time `json:"generatedAt,omitempty"` + + // Replicas is the desired number of replicas for the resource + Replicas int32 `json:"desiredReplicas"` +} + +// DatadogPodAutoscalerHorizontalAction represents a horizontal action done by the controller +// +kubebuilder:object:generate=true +type DatadogPodAutoscalerHorizontalAction struct { + // Time is the timestamp of the action + Time metav1.Time `json:"time"` + + // FromReplicas is the number of replicas before the action + FromReplicas int32 `json:"replicas"` + + // ToReplicas is the effective number of replicas after the action + ToReplicas int32 `json:"toReplicas"` + + // RecommendedReplicas is the original number of replicas recommended by Datadog + RecommendedReplicas *int32 `json:"recommendedReplicas,omitempty"` + + // LimitedReason is the reason why the action was limited (that is ToReplicas != RecommendedReplicas) + LimitedReason *string `json:"limitedReason,omitempty"` +} + +// DatadogPodAutoscalerVerticalStatus defines the status of the vertical scaling +// +kubebuilder:object:generate=true +type DatadogPodAutoscalerVerticalStatus struct { + // Target is the current target of the vertical scaling + Target *DatadogPodAutoscalerVerticalTargetStatus `json:"target,omitempty"` + + // LastAction is the last successful action done by the controller + LastAction *DatadogPodAutoscalerVerticalAction `json:"lastAction,omitempty"` +} + +// DatadogPodAutoscalerVerticalTargetStatus defines the current target of the vertical scaling +// +kubebuilder:object:generate=true +type DatadogPodAutoscalerVerticalTargetStatus struct { + // Source is the source of the value used to scale the target resource + Source DatadogPodAutoscalerValueSource `json:"source"` + + // GeneratedAt is the timestamp at which the recommendation was generated + GeneratedAt metav1.Time `json:"generatedAt,omitempty"` + + // Version is the current version of the received recommendation + Version string `json:"version"` + + // Scaled is the current number of pods having desired resources + Scaled *int32 `json:"scaled,omitempty"` + + // DesiredResources is the desired resources for containers + DesiredResources []DatadogPodAutoscalerContainerResources `json:"desiredResources"` + + // PodCPURequest is the sum of CPU requests for all containers (used for display) + PodCPURequest resource.Quantity `json:"podCPURequest"` + + // PodMemoryRequest is the sum of memory requests for all containers (used for display) + PodMemoryRequest resource.Quantity `json:"podMemoryRequest"` +} + +// DatadogPodAutoscalerVerticalActionType represents the type of action done by the controller +type DatadogPodAutoscalerVerticalActionType string + +const ( + // DatadogPodAutoscalerRolloutTriggeredVerticalActionType is the action when the controller triggers a rollout of the targetRef + DatadogPodAutoscalerRolloutTriggeredVerticalActionType DatadogPodAutoscalerVerticalActionType = "RolloutTriggered" +) + +// DatadogPodAutoscalerVerticalAction represents a vertical action done by the controller +// +kubebuilder:object:generate=true +type DatadogPodAutoscalerVerticalAction struct { + // Time is the timestamp of the action + Time metav1.Time `json:"time"` + + // Version is the version of the recommendation used for the action + Version string `json:"version"` + + // Type is the type of action + Type DatadogPodAutoscalerVerticalActionType `json:"type"` +} + +// +kubebuilder:object:generate=true +type DatadogPodAutoscalerContainerResources struct { + // Name is the name of the container + Name string `json:"name"` + + // Limits describes the maximum amount of compute resources allowed. + // +optional + Limits corev1.ResourceList `json:"limits,omitempty"` + + // Requests describes the requested amount of compute resources. + // +optional + Requests corev1.ResourceList `json:"requests,omitempty"` +} + +// DatadogPodAutoscalerConditionType is the type used to represent a DatadogPodAutoscaler condition +type DatadogPodAutoscalerConditionType string + +const ( + // DatadogPodAutoscalerErrorCondition is true when a global error is encountered processing this DatadogPodAutoscaler. + DatadogPodAutoscalerErrorCondition DatadogPodAutoscalerConditionType = "Error" + + // DatadogPodAutoscalerActiveCondition is true when the DatadogPodAutoscaler can be used for autoscaling. + DatadogPodAutoscalerActiveCondition DatadogPodAutoscalerConditionType = "Active" + + // DatadogPodAutoscalerHorizontalAbleToRecommendCondition is true when a horizontal recommendation can be received from Datadog. + DatadogPodAutoscalerHorizontalAbleToRecommendCondition DatadogPodAutoscalerConditionType = "HorizontalAbleToRecommend" + + // DatadogPodAutoscalerHorizontalAbleToScaleCondition is true when horizontal scaling is working correctly. + DatadogPodAutoscalerHorizontalAbleToScaleCondition DatadogPodAutoscalerConditionType = "HorizontalAbleToScale" + + // DatadogPodAutoscalerHorizontalScalingLimitedCondition is true when horizontal scaling is limited by constraints. + DatadogPodAutoscalerHorizontalScalingLimitedCondition DatadogPodAutoscalerConditionType = "HorizontalScalingLimited" + + // DatadogPodAutoscalerVerticalAbleToRecommendCondition is true when a vertical recommendation can be received from Datadog. + DatadogPodAutoscalerVerticalAbleToRecommendCondition DatadogPodAutoscalerConditionType = "VerticalAbleToRecommend" + + // DatadogPodAutoscalerVerticalAbleToApply is true when the targetRef can be rolled out to pick up new resources. + DatadogPodAutoscalerVerticalAbleToApply DatadogPodAutoscalerConditionType = "VerticalAbleToApply" +) + +// DatadogPodAutoscalerCondition describes the state of DatadogPodAutoscaler. +// +kubebuilder:object:generate=true +type DatadogPodAutoscalerCondition struct { + // DatadogPodAutoscalerConditionType is the type of DatadogPodAutoscaler condition. + Type DatadogPodAutoscalerConditionType `json:"type"` + + // Status of the condition, one of True, False, Unknown. + Status corev1.ConditionStatus `json:"status"` + + // Last time the condition transitioned from one status to another. + // +optional + LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"` + + // The reason for the condition's last transition. + // +optional + Reason string `json:"reason,omitempty"` + + // A human readable message indicating details about the transition. + // +optional + Message string `json:"message,omitempty"` +} diff --git a/api/datadoghq/common/zz_generated.deepcopy.go b/api/datadoghq/common/zz_generated.deepcopy.go index f799a91d6..524aa1a7d 100644 --- a/api/datadoghq/common/zz_generated.deepcopy.go +++ b/api/datadoghq/common/zz_generated.deepcopy.go @@ -10,9 +10,445 @@ package common import ( + "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/util/intstr" ) +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DatadogPodAutoscalerCondition) DeepCopyInto(out *DatadogPodAutoscalerCondition) { + *out = *in + in.LastTransitionTime.DeepCopyInto(&out.LastTransitionTime) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerCondition. +func (in *DatadogPodAutoscalerCondition) DeepCopy() *DatadogPodAutoscalerCondition { + if in == nil { + return nil + } + out := new(DatadogPodAutoscalerCondition) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DatadogPodAutoscalerConstraints) DeepCopyInto(out *DatadogPodAutoscalerConstraints) { + *out = *in + if in.MinReplicas != nil { + in, out := &in.MinReplicas, &out.MinReplicas + *out = new(int32) + **out = **in + } + if in.Containers != nil { + in, out := &in.Containers, &out.Containers + *out = make([]DatadogPodAutoscalerContainerConstraints, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerConstraints. +func (in *DatadogPodAutoscalerConstraints) DeepCopy() *DatadogPodAutoscalerConstraints { + if in == nil { + return nil + } + out := new(DatadogPodAutoscalerConstraints) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DatadogPodAutoscalerContainerConstraints) DeepCopyInto(out *DatadogPodAutoscalerContainerConstraints) { + *out = *in + if in.Enabled != nil { + in, out := &in.Enabled, &out.Enabled + *out = new(bool) + **out = **in + } + if in.Requests != nil { + in, out := &in.Requests, &out.Requests + *out = new(DatadogPodAutoscalerContainerResourceConstraints) + (*in).DeepCopyInto(*out) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerContainerConstraints. +func (in *DatadogPodAutoscalerContainerConstraints) DeepCopy() *DatadogPodAutoscalerContainerConstraints { + if in == nil { + return nil + } + out := new(DatadogPodAutoscalerContainerConstraints) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DatadogPodAutoscalerContainerResourceConstraints) DeepCopyInto(out *DatadogPodAutoscalerContainerResourceConstraints) { + *out = *in + if in.MinAllowed != nil { + in, out := &in.MinAllowed, &out.MinAllowed + *out = make(v1.ResourceList, len(*in)) + for key, val := range *in { + (*out)[key] = val.DeepCopy() + } + } + if in.MaxAllowed != nil { + in, out := &in.MaxAllowed, &out.MaxAllowed + *out = make(v1.ResourceList, len(*in)) + for key, val := range *in { + (*out)[key] = val.DeepCopy() + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerContainerResourceConstraints. +func (in *DatadogPodAutoscalerContainerResourceConstraints) DeepCopy() *DatadogPodAutoscalerContainerResourceConstraints { + if in == nil { + return nil + } + out := new(DatadogPodAutoscalerContainerResourceConstraints) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DatadogPodAutoscalerContainerResourceTarget) DeepCopyInto(out *DatadogPodAutoscalerContainerResourceTarget) { + *out = *in + in.Value.DeepCopyInto(&out.Value) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerContainerResourceTarget. +func (in *DatadogPodAutoscalerContainerResourceTarget) DeepCopy() *DatadogPodAutoscalerContainerResourceTarget { + if in == nil { + return nil + } + out := new(DatadogPodAutoscalerContainerResourceTarget) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DatadogPodAutoscalerContainerResources) DeepCopyInto(out *DatadogPodAutoscalerContainerResources) { + *out = *in + if in.Limits != nil { + in, out := &in.Limits, &out.Limits + *out = make(v1.ResourceList, len(*in)) + for key, val := range *in { + (*out)[key] = val.DeepCopy() + } + } + if in.Requests != nil { + in, out := &in.Requests, &out.Requests + *out = make(v1.ResourceList, len(*in)) + for key, val := range *in { + (*out)[key] = val.DeepCopy() + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerContainerResources. +func (in *DatadogPodAutoscalerContainerResources) DeepCopy() *DatadogPodAutoscalerContainerResources { + if in == nil { + return nil + } + out := new(DatadogPodAutoscalerContainerResources) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DatadogPodAutoscalerHorizontalAction) DeepCopyInto(out *DatadogPodAutoscalerHorizontalAction) { + *out = *in + in.Time.DeepCopyInto(&out.Time) + if in.RecommendedReplicas != nil { + in, out := &in.RecommendedReplicas, &out.RecommendedReplicas + *out = new(int32) + **out = **in + } + if in.LimitedReason != nil { + in, out := &in.LimitedReason, &out.LimitedReason + *out = new(string) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerHorizontalAction. +func (in *DatadogPodAutoscalerHorizontalAction) DeepCopy() *DatadogPodAutoscalerHorizontalAction { + if in == nil { + return nil + } + out := new(DatadogPodAutoscalerHorizontalAction) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DatadogPodAutoscalerHorizontalStatus) DeepCopyInto(out *DatadogPodAutoscalerHorizontalStatus) { + *out = *in + if in.Target != nil { + in, out := &in.Target, &out.Target + *out = new(DatadogPodAutoscalerHorizontalTargetStatus) + (*in).DeepCopyInto(*out) + } + if in.LastActions != nil { + in, out := &in.LastActions, &out.LastActions + *out = make([]DatadogPodAutoscalerHorizontalAction, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerHorizontalStatus. +func (in *DatadogPodAutoscalerHorizontalStatus) DeepCopy() *DatadogPodAutoscalerHorizontalStatus { + if in == nil { + return nil + } + out := new(DatadogPodAutoscalerHorizontalStatus) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DatadogPodAutoscalerHorizontalTargetStatus) DeepCopyInto(out *DatadogPodAutoscalerHorizontalTargetStatus) { + *out = *in + in.GeneratedAt.DeepCopyInto(&out.GeneratedAt) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerHorizontalTargetStatus. +func (in *DatadogPodAutoscalerHorizontalTargetStatus) DeepCopy() *DatadogPodAutoscalerHorizontalTargetStatus { + if in == nil { + return nil + } + out := new(DatadogPodAutoscalerHorizontalTargetStatus) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DatadogPodAutoscalerObjective) DeepCopyInto(out *DatadogPodAutoscalerObjective) { + *out = *in + if in.PodResource != nil { + in, out := &in.PodResource, &out.PodResource + *out = new(DatadogPodAutoscalerResourceTarget) + (*in).DeepCopyInto(*out) + } + if in.ContainerResource != nil { + in, out := &in.ContainerResource, &out.ContainerResource + *out = new(DatadogPodAutoscalerContainerResourceTarget) + (*in).DeepCopyInto(*out) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerObjective. +func (in *DatadogPodAutoscalerObjective) DeepCopy() *DatadogPodAutoscalerObjective { + if in == nil { + return nil + } + out := new(DatadogPodAutoscalerObjective) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DatadogPodAutoscalerResourceTarget) DeepCopyInto(out *DatadogPodAutoscalerResourceTarget) { + *out = *in + in.Value.DeepCopyInto(&out.Value) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerResourceTarget. +func (in *DatadogPodAutoscalerResourceTarget) DeepCopy() *DatadogPodAutoscalerResourceTarget { + if in == nil { + return nil + } + out := new(DatadogPodAutoscalerResourceTarget) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DatadogPodAutoscalerScalingPolicy) DeepCopyInto(out *DatadogPodAutoscalerScalingPolicy) { + *out = *in + if in.Strategy != nil { + in, out := &in.Strategy, &out.Strategy + *out = new(DatadogPodAutoscalerScalingStrategySelect) + **out = **in + } + if in.Rules != nil { + in, out := &in.Rules, &out.Rules + *out = make([]DatadogPodAutoscalerScalingRule, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerScalingPolicy. +func (in *DatadogPodAutoscalerScalingPolicy) DeepCopy() *DatadogPodAutoscalerScalingPolicy { + if in == nil { + return nil + } + out := new(DatadogPodAutoscalerScalingPolicy) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DatadogPodAutoscalerScalingRule) DeepCopyInto(out *DatadogPodAutoscalerScalingRule) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerScalingRule. +func (in *DatadogPodAutoscalerScalingRule) DeepCopy() *DatadogPodAutoscalerScalingRule { + if in == nil { + return nil + } + out := new(DatadogPodAutoscalerScalingRule) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DatadogPodAutoscalerStatus) DeepCopyInto(out *DatadogPodAutoscalerStatus) { + *out = *in + if in.Vertical != nil { + in, out := &in.Vertical, &out.Vertical + *out = new(DatadogPodAutoscalerVerticalStatus) + (*in).DeepCopyInto(*out) + } + if in.Horizontal != nil { + in, out := &in.Horizontal, &out.Horizontal + *out = new(DatadogPodAutoscalerHorizontalStatus) + (*in).DeepCopyInto(*out) + } + if in.CurrentReplicas != nil { + in, out := &in.CurrentReplicas, &out.CurrentReplicas + *out = new(int32) + **out = **in + } + if in.Conditions != nil { + in, out := &in.Conditions, &out.Conditions + *out = make([]DatadogPodAutoscalerCondition, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerStatus. +func (in *DatadogPodAutoscalerStatus) DeepCopy() *DatadogPodAutoscalerStatus { + if in == nil { + return nil + } + out := new(DatadogPodAutoscalerStatus) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DatadogPodAutoscalerTargetValue) DeepCopyInto(out *DatadogPodAutoscalerTargetValue) { + *out = *in + if in.Utilization != nil { + in, out := &in.Utilization, &out.Utilization + *out = new(int32) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerTargetValue. +func (in *DatadogPodAutoscalerTargetValue) DeepCopy() *DatadogPodAutoscalerTargetValue { + if in == nil { + return nil + } + out := new(DatadogPodAutoscalerTargetValue) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DatadogPodAutoscalerUpdatePolicy) DeepCopyInto(out *DatadogPodAutoscalerUpdatePolicy) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerUpdatePolicy. +func (in *DatadogPodAutoscalerUpdatePolicy) DeepCopy() *DatadogPodAutoscalerUpdatePolicy { + if in == nil { + return nil + } + out := new(DatadogPodAutoscalerUpdatePolicy) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DatadogPodAutoscalerVerticalAction) DeepCopyInto(out *DatadogPodAutoscalerVerticalAction) { + *out = *in + in.Time.DeepCopyInto(&out.Time) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerVerticalAction. +func (in *DatadogPodAutoscalerVerticalAction) DeepCopy() *DatadogPodAutoscalerVerticalAction { + if in == nil { + return nil + } + out := new(DatadogPodAutoscalerVerticalAction) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DatadogPodAutoscalerVerticalStatus) DeepCopyInto(out *DatadogPodAutoscalerVerticalStatus) { + *out = *in + if in.Target != nil { + in, out := &in.Target, &out.Target + *out = new(DatadogPodAutoscalerVerticalTargetStatus) + (*in).DeepCopyInto(*out) + } + if in.LastAction != nil { + in, out := &in.LastAction, &out.LastAction + *out = new(DatadogPodAutoscalerVerticalAction) + (*in).DeepCopyInto(*out) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerVerticalStatus. +func (in *DatadogPodAutoscalerVerticalStatus) DeepCopy() *DatadogPodAutoscalerVerticalStatus { + if in == nil { + return nil + } + out := new(DatadogPodAutoscalerVerticalStatus) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DatadogPodAutoscalerVerticalTargetStatus) DeepCopyInto(out *DatadogPodAutoscalerVerticalTargetStatus) { + *out = *in + in.GeneratedAt.DeepCopyInto(&out.GeneratedAt) + if in.Scaled != nil { + in, out := &in.Scaled, &out.Scaled + *out = new(int32) + **out = **in + } + if in.DesiredResources != nil { + in, out := &in.DesiredResources, &out.DesiredResources + *out = make([]DatadogPodAutoscalerContainerResources, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + out.PodCPURequest = in.PodCPURequest.DeepCopy() + out.PodMemoryRequest = in.PodMemoryRequest.DeepCopy() +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerVerticalTargetStatus. +func (in *DatadogPodAutoscalerVerticalTargetStatus) DeepCopy() *DatadogPodAutoscalerVerticalTargetStatus { + if in == nil { + return nil + } + out := new(DatadogPodAutoscalerVerticalTargetStatus) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *RollingUpdate) DeepCopyInto(out *RollingUpdate) { *out = *in diff --git a/api/datadoghq/v1alpha1/datadogpodautoscaler_types.go b/api/datadoghq/v1alpha1/datadogpodautoscaler_types.go index 44b392f5d..0b8eaea74 100644 --- a/api/datadoghq/v1alpha1/datadogpodautoscaler_types.go +++ b/api/datadoghq/v1alpha1/datadogpodautoscaler_types.go @@ -6,9 +6,8 @@ package v1alpha1 import ( + "github.com/DataDog/datadog-operator/api/datadoghq/common" autoscalingv2 "k8s.io/api/autoscaling/v2" - corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -63,18 +62,6 @@ import ( // minAllowed: // maxAllowed: -// DatadogPodAutoscalerOwner defines the source of truth for this object (local or remote) -// +kubebuilder:validation:Enum:=Local;Remote -type DatadogPodAutoscalerOwner string - -const ( - // DatadogPodAutoscalerLocalOwner states that this `DatadogPodAutoscaler` object is created/managed outside of Datadog app. - DatadogPodAutoscalerLocalOwner DatadogPodAutoscalerOwner = "Local" - - // DatadogPodAutoscalerLocalOwner states that this `DatadogPodAutoscaler` object is created/managed in Datadog app. - DatadogPodAutoscalerRemoteOwner DatadogPodAutoscalerOwner = "Remote" -) - // DatadogPodAutoscalerSpec defines the desired state of DatadogPodAutoscaler type DatadogPodAutoscalerSpec struct { // TargetRef is the reference to the resource to scale. @@ -82,7 +69,7 @@ type DatadogPodAutoscalerSpec struct { // Owner defines the source of truth for this object (local or remote) // Value needs to be set when a DatadogPodAutoscaler object is created. - Owner DatadogPodAutoscalerOwner `json:"owner"` + Owner common.DatadogPodAutoscalerOwner `json:"owner"` // RemoteVersion is the version of the .Spec currently store in this object. // Only set if the owner is Remote. @@ -97,10 +84,10 @@ type DatadogPodAutoscalerSpec struct { // Default to a single target to maintain 80% POD CPU utilization. // +listType=atomic // +optional - Targets []DatadogPodAutoscalerTarget `json:"targets,omitempty"` + Targets []common.DatadogPodAutoscalerObjective `json:"targets,omitempty"` // Constraints defines constraints that should always be respected. - Constraints *DatadogPodAutoscalerConstraints `json:"constraints,omitempty"` + Constraints *common.DatadogPodAutoscalerConstraints `json:"constraints,omitempty"` } // DatadogPodAutoscalerOwner defines the source of truth for this object (local or remote) @@ -134,10 +121,10 @@ type DatadogPodAutoscalerPolicy struct { Update *DatadogPodAutoscalerUpdatePolicy `json:"update,omitempty"` // Upscale defines the policy to scale up the target resource. - Upscale *DatadogPodAutoscalerScalingPolicy `json:"upscale,omitempty"` + Upscale *common.DatadogPodAutoscalerScalingPolicy `json:"upscale,omitempty"` // Downscale defines the policy to scale down the target resource. - Downscale *DatadogPodAutoscalerScalingPolicy `json:"downscale,omitempty"` + Downscale *common.DatadogPodAutoscalerScalingPolicy `json:"downscale,omitempty"` } // DatadogPodAutoscalerUpdateStrategy defines the mode of the update policy. @@ -158,397 +145,6 @@ type DatadogPodAutoscalerUpdatePolicy struct { Strategy DatadogPodAutoscalerUpdateStrategy `json:"strategy,omitempty"` } -// -// Scaling policy is inspired by the HorizontalPodAutoscalerV2 -// https://github.com/kubernetes/api/blob/master/autoscaling/v2/types.go -// Copyright 2021 The Kubernetes Authors. -// - -// DatadogPodAutoscalerScalingStrategySelect is used to specify which policy should be used while scaling in a certain direction -// +kubebuilder:validation:Enum:=Max;Min;Disabled -type DatadogPodAutoscalerScalingStrategySelect string - -const ( - // DatadogPodAutoscalerMaxChangeStrategySelect selects the policy with the highest possible change. - DatadogPodAutoscalerMaxChangeStrategySelect DatadogPodAutoscalerScalingStrategySelect = "Max" - - // DatadogPodAutoscalerMinChangeStrategySelect selects the policy with the lowest possible change. - DatadogPodAutoscalerMinChangeStrategySelect DatadogPodAutoscalerScalingStrategySelect = "Min" - - // DatadogPodAutoscalerDisabledStrategySelect disables the scaling in this direction. - DatadogPodAutoscalerDisabledStrategySelect DatadogPodAutoscalerScalingStrategySelect = "Disabled" -) - -// DatadogPodAutoscalerScalingPolicy defines the policy to scale the target resource. -type DatadogPodAutoscalerScalingPolicy struct { - // Strategy is used to specify which policy should be used. - // If not set, the default value Max is used. - // +optional - Strategy *DatadogPodAutoscalerScalingStrategySelect `json:"strategy,omitempty"` - - // Rules is a list of potential scaling polices which can be used during scaling. - // At least one policy must be specified, otherwise the DatadogPodAutoscalerScalingPolicy will be discarded as invalid - // +listType=atomic - // +optional - Rules []DatadogPodAutoscalerScalingRule `json:"rules,omitempty"` - - // StabilizationWindowSeconds is the number of seconds the controller should lookback at previous recommendations - // before deciding to apply a new one. Defaults to 0. - // +optional - // +kubebuilder:validation:Minimum=0 - // +kubebuilder:validation:Maximum=1800 - StabilizationWindowSeconds int32 `json:"stabilizationWindowSeconds,omitempty"` -} - -// DatadogPodAutoscalerScalingRuleType defines how scaling rule value should be interpreted. -// +kubebuilder:validation:Enum:=Pods;Percent -type DatadogPodAutoscalerScalingRuleType string - -const ( - // DatadogPodAutoscalerPodsScalingRuleType specifies a change in absolute number of pods compared to the starting number of PODs. - DatadogPodAutoscalerPodsScalingRuleType DatadogPodAutoscalerScalingRuleType = "Pods" - - // DatadogPodAutoscalerPercentScalingRuleType specifies a relative amount of change compared to the starting number of PODs. - DatadogPodAutoscalerPercentScalingRuleType DatadogPodAutoscalerScalingRuleType = "Percent" -) - -// DatadogPodAutoscalerScalingRuleMatch -// +kubebuilder:validation:Enum:=Always;IfScalingEvent -type DatadogPodAutoscalerScalingRuleMatch string - -const ( - // DatadogPodAutoscalerAlwaysScalingRuleMatch defines that the rule should always be considered in the calculation. - DatadogPodAutoscalerAlwaysScalingRuleMatch DatadogPodAutoscalerScalingRuleMatch = "Always" - - // DatadogPodAutoscalerIfScalingEventRuleMatch defines that rule should only be considered if at least one scaling event occurred. - // It allows to define behaviors such as forbidden windows (e.g. allow 0 PODs (Value) to be created in the next 5m (PeriodSeconds) after a scaling events). - DatadogPodAutoscalerIfScalingEventRuleMatch DatadogPodAutoscalerScalingRuleMatch = "IfScalingEvent" -) - -// DatadogPodAutoscalerScalingRule define rules for horizontal that should be true for a certain amount of time. -type DatadogPodAutoscalerScalingRule struct { - // Type is used to specify the scaling policy. - Type DatadogPodAutoscalerScalingRuleType `json:"type"` - - // Value contains the amount of change which is permitted by the policy. - // Setting it to 0 will prevent any scaling in this direction and should not be used unless Match is set to IfScalingEvent. - // +kubebuilder:validation:Minimum=0 - Value int32 `json:"value"` - - // PeriodSeconds specifies the window of time for which the policy should hold true. - // PeriodSeconds must be greater than zero and less than or equal to 1800 (30 min). - // +kubebuilder:validation:Minimum=1 - // +kubebuilder:validation:Maximum=1800 - PeriodSeconds int32 `json:"periodSeconds"` - - // Match defines if the rule should be considered or not in the calculation. - // Default to Always if not set. - Match *DatadogPodAutoscalerScalingRuleMatch `json:"match,omitempty"` -} - -// DatadogPodAutoscalerTargetType defines the type of the target. -// +kubebuilder:validation:Enum:=PodResource;ContainerResource -type DatadogPodAutoscalerTargetType string - -const ( - // DatadogPodAutoscalerResourceTargetType allows to set POD-level resources targets. - DatadogPodAutoscalerResourceTargetType DatadogPodAutoscalerTargetType = "PodResource" - - // DatadogPodAutoscalerContainerResourceTargetType allows to set container-level resources targets. - DatadogPodAutoscalerContainerResourceTargetType DatadogPodAutoscalerTargetType = "ContainerResource" -) - -// DatadogPodAutoscalerTarget defines the objectives to reach and maintain for the target resource. -type DatadogPodAutoscalerTarget struct { - // Type sets the type of the target. - Type DatadogPodAutoscalerTargetType `json:"type"` - - // PodResource allows to set a POD-level resource target. - PodResource *DatadogPodAutoscalerResourceTarget `json:"podResource,omitempty"` - - // ContainerResource allows to set a container-level resource target. - ContainerResource *DatadogPodAutoscalerContainerResourceTarget `json:"containerResource,omitempty"` -} - -// DatadogPodAutoscalerResourceTarget defines a POD-level resource target (for instance, CPU Utilization at 80%) -// For POD-level targets, resources are the sum of all containers resources. -// Utilization is computed from sum(usage) / sum(requests). -type DatadogPodAutoscalerResourceTarget struct { - // Name is the name of the resource. - // +kubebuilder:validation:Enum:=cpu - Name corev1.ResourceName `json:"name"` - - // Value is the value of the target. - Value DatadogPodAutoscalerTargetValue `json:"value"` -} - -// DatadogPodAutoscalerContainerResourceTarget defines a Container level resource target (for instance, CPU Utilization for container named "foo" at 80%) -type DatadogPodAutoscalerContainerResourceTarget struct { - // Name is the name of the resource. - // +kubebuilder:validation:Enum:=cpu - Name corev1.ResourceName `json:"name"` - - // Value is the value of the target. - Value DatadogPodAutoscalerTargetValue `json:"value"` - - // Container is the name of the container. - Container string `json:"container"` -} - -// DatadogPodAutoscalerTargetValue defines the value of the target. -type DatadogPodAutoscalerTargetValue struct { - // Type specifies how the value is expressed (Absolute or Utilization). - Type DatadogPodAutoscalerTargetValueType `json:"type"` - - // Absolute defines the absolute value of the target (for instance 500 millicores). - Absolute *resource.Quantity `json:"absolute,omitempty"` - - // Utilization defines a percentage of the target compared to requested resource - // +kubebuilder:validation:Minimum=0 - // +kubebuilder:validation:Maximum=100 - Utilization *int32 `json:"utilization,omitempty"` -} - -// DatadogPodAutoscalerTargetValueType specifies the type of metric being targeted, and should be either -// kubebuilder:validation:Enum:=Absolute;Utilization -type DatadogPodAutoscalerTargetValueType string - -const ( - // DatadogPodAutoscalerAbsoluteTargetValueType is the target type for absolute values - DatadogPodAutoscalerAbsoluteTargetValueType DatadogPodAutoscalerTargetValueType = "Absolute" - - // DatadogPodAutoscalerUtilizationTargetValueType declares a MetricTarget is an AverageUtilization value - DatadogPodAutoscalerUtilizationTargetValueType DatadogPodAutoscalerTargetValueType = "Utilization" -) - -// DatadogPodAutoscalerConstraints defines constraints that should always be respected. -type DatadogPodAutoscalerConstraints struct { - // MinReplicas is the lower limit for the number of POD replicas. Needs to be >= 1. Default to 1. - // +kubebuilder:validation:Minimum=1 - MinReplicas *int32 `json:"minReplicas,omitempty"` - - // MaxReplicas is the upper limit for the number of POD replicas. Needs to be >= minReplicas. - MaxReplicas int32 `json:"maxReplicas"` - - // Containers defines constraints for the containers. - Containers []DatadogPodAutoscalerContainerConstraints `json:"containers,omitempty"` -} - -// DatadogPodAutoscalerContainerConstraints defines constraints that should always be respected for a container. -// If no constraints are set, it enables resources scaling for all containers without any constraints. -type DatadogPodAutoscalerContainerConstraints struct { - // Name is the name of the container. Can be "*" to apply to all containers. - Name string `json:"name"` - - // Enabled false allows to disable resources autoscaling for the container. Default to true. - Enabled *bool `json:"enabled,omitempty"` - - // Requests defines the constraints for the requests of the container. - Requests *DatadogPodAutoscalerContainerResourceConstraints `json:"requests,omitempty"` - - // Limits defines the constraints for the limits of the container. - Limits *DatadogPodAutoscalerContainerResourceConstraints `json:"limits,omitempty"` -} - -type DatadogPodAutoscalerContainerResourceConstraints struct { - // MinAllowed is the lower limit for the requests of the container. - // +optional - MinAllowed corev1.ResourceList `json:"minAllowed,omitempty"` - - // MaxAllowed is the upper limit for the requests of the container. - // +optional - MaxAllowed corev1.ResourceList `json:"maxAllowed,omitempty"` -} - -// DatadogPodAutoscalerStatus defines the observed state of DatadogPodAutoscaler -type DatadogPodAutoscalerStatus struct { - // Vertical is the status of the vertical scaling, if activated. - // +optional - Vertical *DatadogPodAutoscalerVerticalStatus `json:"vertical,omitempty"` - - // Horizontal is the status of the horizontal scaling, if activated. - // +optional - Horizontal *DatadogPodAutoscalerHorizontalStatus `json:"horizontal,omitempty"` - - // CurrentReplicas is the current number of PODs for the targetRef observed by the controller. - // +optional - CurrentReplicas *int32 `json:"currentReplicas,omitempty"` - - // Conditions describe the current state of the DatadogPodAutoscaler operations. - // +patchMergeKey=type - // +patchStrategy=merge - // +listType=map - // +listMapKey=type - // +optional - Conditions []DatadogPodAutoscalerCondition `json:"conditions,omitempty"` -} - -// DatadogPodAutoscalerValueSource defines the source of the value used to scale the target resource. -type DatadogPodAutoscalerValueSource string - -const ( - // DatadogPodAutoscalerAutoscalingValueSource is a recommendation that comes from active autoscaling. - DatadogPodAutoscalerAutoscalingValueSource DatadogPodAutoscalerValueSource = "Autoscaling" - - // DatadogPodAutoscalerManualValueSource is a recommendation that comes from manually applying a recommendation. - DatadogPodAutoscalerManualValueSource DatadogPodAutoscalerValueSource = "Manual" - - // DatadogPodAutoscalerLocalValueSource is a recommendation that comes from local fallback. - DatadogPodAutoscalerLocalValueSource DatadogPodAutoscalerValueSource = "Local" -) - -// DatadogPodAutoscalerHorizontalStatus defines the status of the horizontal scaling -type DatadogPodAutoscalerHorizontalStatus struct { - // Target is the current target of the horizontal scaling - Target *DatadogPodAutoscalerHorizontalTargetStatus `json:"target,omitempty"` - - // LastActions are the last successful actions done by the controller - LastActions []DatadogPodAutoscalerHorizontalAction `json:"lastActions,omitempty"` -} - -// DatadogPodAutoscalerHorizontalTargetStatus defines the current target of the horizontal scaling -type DatadogPodAutoscalerHorizontalTargetStatus struct { - // Source is the source of the value used to scale the target resource - Source DatadogPodAutoscalerValueSource `json:"source"` - - // GeneratedAt is the timestamp at which the recommendation was generated - GeneratedAt metav1.Time `json:"generatedAt,omitempty"` - - // Replicas is the desired number of replicas for the resource - Replicas int32 `json:"desiredReplicas"` -} - -// DatadogPodAutoscalerHorizontalAction represents an horizontal action done by the controller -type DatadogPodAutoscalerHorizontalAction struct { - // Time is the timestamp of the action - Time metav1.Time `json:"time"` - - // FromReplicas is the number of replicas before the action - FromReplicas int32 `json:"replicas"` - - // ToReplicas is the effective number of replicas after the action - ToReplicas int32 `json:"toReplicas"` - - // RecommendedReplicas is the original number of replicas recommended by Datadog - RecommendedReplicas *int32 `json:"recommendedReplicas,omitempty"` - - // LimitedReason is the reason why the action was limited (ToReplicas != RecommendedReplicas) - LimitedReason *string `json:"limitedReason,omitempty"` -} - -// DatadogPodAutoscalerVerticalStatus defines the status of the vertical scaling -type DatadogPodAutoscalerVerticalStatus struct { - // Target is the current target of the vertical scaling - Target *DatadogPodAutoscalerVerticalTargetStatus `json:"target,omitempty"` - - // LastAction is the last successful action done by the controller - LastAction *DatadogPodAutoscalerVerticalAction `json:"lastAction,omitempty"` -} - -// DatadogPodAutoscalerVerticalTargetStatus defines the current target of the vertical scaling -type DatadogPodAutoscalerVerticalTargetStatus struct { - // Source is the source of the value used to scale the target resource - Source DatadogPodAutoscalerValueSource `json:"source"` - - // GeneratedAt is the timestamp at which the recommendation was generated - GeneratedAt metav1.Time `json:"generatedAt,omitempty"` - - // Version is the current version of the received recommendation - Version string `json:"version"` - - // Scaled is the current number of PODs having desired resources - Scaled *int32 `json:"scaled,omitempty"` - - // DesiredResources is the desired resources for containers - DesiredResources []DatadogPodAutoscalerContainerResources `json:"desiredResources"` - - // PODCPURequest is the sum of CPU requests for all containers (used for display) - PODCPURequest resource.Quantity `json:"podCPURequest"` - - // PODMemoryRequest is the sum of memory requests for all containers (used for display) - PODMemoryRequest resource.Quantity `json:"podMemoryRequest"` -} - -// DatadogPodAutoscalerVerticalActionType represents the type of action done by the controller -type DatadogPodAutoscalerVerticalActionType string - -const ( - // DatadogPodAutoscalerRolloutTriggeredVerticalActionType is the action when the controller triggers a rollout of the targetRef - DatadogPodAutoscalerRolloutTriggeredVerticalActionType DatadogPodAutoscalerVerticalActionType = "RolloutTriggered" -) - -// DatadogPodAutoscalerVerticalAction represents a vertical action done by the controller -type DatadogPodAutoscalerVerticalAction struct { - // Time is the timestamp of the action - Time metav1.Time `json:"time"` - - // Version is the recommendation version used for the action - Version string `json:"version"` - - // Type is the type of action - Type DatadogPodAutoscalerVerticalActionType `json:"type"` -} - -type DatadogPodAutoscalerContainerResources struct { - // Name is the name of the container - Name string `json:"name"` - - // Limits describes the maximum amount of compute resources allowed. - // +optional - Limits corev1.ResourceList `json:"limits,omitempty"` - - // Requests describes target resources of compute resources allowed. - // +optional - Requests corev1.ResourceList `json:"requests,omitempty"` -} - -// DatadogPodAutoscalerConditionType type use to represent a DatadogMetric condition -type DatadogPodAutoscalerConditionType string - -const ( - // DatadogPodAutoscalerErrorCondition is true when a global error is encountered processing this DatadogPodAutoscaler. - DatadogPodAutoscalerErrorCondition DatadogPodAutoscalerConditionType = "Error" - - // DatadogPodAutoscalerActiveCondition is true when the DatadogPodAutoscaler can be used for autoscaling. - DatadogPodAutoscalerActiveCondition DatadogPodAutoscalerConditionType = "Active" - - // DatadogPodAutoscalerHorizontalAbleToRecommendCondition is true when we can get horizontal recommendation from Datadog. - DatadogPodAutoscalerHorizontalAbleToRecommendCondition DatadogPodAutoscalerConditionType = "HorizontalAbleToRecommend" - - // DatadogPodAutoscalerHorizontalAbleToScaleCondition is true when horizontal scaling is working correctly. - DatadogPodAutoscalerHorizontalAbleToScaleCondition DatadogPodAutoscalerConditionType = "HorizontalAbleToScale" - - // DatadogPodAutoscalerHorizontalScalingLimitedCondition is true when horizontal scaling is limited by constraints. - DatadogPodAutoscalerHorizontalScalingLimitedCondition DatadogPodAutoscalerConditionType = "HorizontalScalingLimited" - - // DatadogPodAutoscalerVerticalAbleToRecommendCondition is true when we can ge vertical recommendation from Datadog. - DatadogPodAutoscalerVerticalAbleToRecommendCondition DatadogPodAutoscalerConditionType = "VerticalAbleToRecommend" - - // DatadogPodAutoscalerVerticalAbleToApply is true when we can rollout the targetRef to pick up new resources. - DatadogPodAutoscalerVerticalAbleToApply DatadogPodAutoscalerConditionType = "VerticalAbleToApply" -) - -// DatadogPodAutoscalerCondition describes the state of DatadogPodAutoscaler. -type DatadogPodAutoscalerCondition struct { - // Type of DatadogMetric condition. - Type DatadogPodAutoscalerConditionType `json:"type"` - - // Status of the condition, one of True, False, Unknown. - Status corev1.ConditionStatus `json:"status"` - - // Last time the condition transitioned from one status to another. - // +optional - LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"` - - // The reason for the condition's last transition. - // +optional - Reason string `json:"reason,omitempty"` - - // A human readable message indicating details about the transition. - // +optional - Message string `json:"message,omitempty"` -} - // +kubebuilder:object:root=true // +kubebuilder:resource:shortName=dpa // +kubebuilder:subresource:status @@ -570,8 +166,8 @@ type DatadogPodAutoscaler struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` - Spec DatadogPodAutoscalerSpec `json:"spec,omitempty"` - Status DatadogPodAutoscalerStatus `json:"status,omitempty"` + Spec DatadogPodAutoscalerSpec `json:"spec,omitempty"` + Status common.DatadogPodAutoscalerStatus `json:"status,omitempty"` } //+kubebuilder:object:root=true diff --git a/api/datadoghq/v1alpha1/zz_generated.deepcopy.go b/api/datadoghq/v1alpha1/zz_generated.deepcopy.go index 7389a8ca4..554c70ada 100644 --- a/api/datadoghq/v1alpha1/zz_generated.deepcopy.go +++ b/api/datadoghq/v1alpha1/zz_generated.deepcopy.go @@ -1049,222 +1049,6 @@ func (in *DatadogPodAutoscaler) DeepCopyObject() runtime.Object { return nil } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DatadogPodAutoscalerCondition) DeepCopyInto(out *DatadogPodAutoscalerCondition) { - *out = *in - in.LastTransitionTime.DeepCopyInto(&out.LastTransitionTime) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerCondition. -func (in *DatadogPodAutoscalerCondition) DeepCopy() *DatadogPodAutoscalerCondition { - if in == nil { - return nil - } - out := new(DatadogPodAutoscalerCondition) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DatadogPodAutoscalerConstraints) DeepCopyInto(out *DatadogPodAutoscalerConstraints) { - *out = *in - if in.MinReplicas != nil { - in, out := &in.MinReplicas, &out.MinReplicas - *out = new(int32) - **out = **in - } - if in.Containers != nil { - in, out := &in.Containers, &out.Containers - *out = make([]DatadogPodAutoscalerContainerConstraints, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerConstraints. -func (in *DatadogPodAutoscalerConstraints) DeepCopy() *DatadogPodAutoscalerConstraints { - if in == nil { - return nil - } - out := new(DatadogPodAutoscalerConstraints) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DatadogPodAutoscalerContainerConstraints) DeepCopyInto(out *DatadogPodAutoscalerContainerConstraints) { - *out = *in - if in.Enabled != nil { - in, out := &in.Enabled, &out.Enabled - *out = new(bool) - **out = **in - } - if in.Requests != nil { - in, out := &in.Requests, &out.Requests - *out = new(DatadogPodAutoscalerContainerResourceConstraints) - (*in).DeepCopyInto(*out) - } - if in.Limits != nil { - in, out := &in.Limits, &out.Limits - *out = new(DatadogPodAutoscalerContainerResourceConstraints) - (*in).DeepCopyInto(*out) - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerContainerConstraints. -func (in *DatadogPodAutoscalerContainerConstraints) DeepCopy() *DatadogPodAutoscalerContainerConstraints { - if in == nil { - return nil - } - out := new(DatadogPodAutoscalerContainerConstraints) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DatadogPodAutoscalerContainerResourceConstraints) DeepCopyInto(out *DatadogPodAutoscalerContainerResourceConstraints) { - *out = *in - if in.MinAllowed != nil { - in, out := &in.MinAllowed, &out.MinAllowed - *out = make(v1.ResourceList, len(*in)) - for key, val := range *in { - (*out)[key] = val.DeepCopy() - } - } - if in.MaxAllowed != nil { - in, out := &in.MaxAllowed, &out.MaxAllowed - *out = make(v1.ResourceList, len(*in)) - for key, val := range *in { - (*out)[key] = val.DeepCopy() - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerContainerResourceConstraints. -func (in *DatadogPodAutoscalerContainerResourceConstraints) DeepCopy() *DatadogPodAutoscalerContainerResourceConstraints { - if in == nil { - return nil - } - out := new(DatadogPodAutoscalerContainerResourceConstraints) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DatadogPodAutoscalerContainerResourceTarget) DeepCopyInto(out *DatadogPodAutoscalerContainerResourceTarget) { - *out = *in - in.Value.DeepCopyInto(&out.Value) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerContainerResourceTarget. -func (in *DatadogPodAutoscalerContainerResourceTarget) DeepCopy() *DatadogPodAutoscalerContainerResourceTarget { - if in == nil { - return nil - } - out := new(DatadogPodAutoscalerContainerResourceTarget) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DatadogPodAutoscalerContainerResources) DeepCopyInto(out *DatadogPodAutoscalerContainerResources) { - *out = *in - if in.Limits != nil { - in, out := &in.Limits, &out.Limits - *out = make(v1.ResourceList, len(*in)) - for key, val := range *in { - (*out)[key] = val.DeepCopy() - } - } - if in.Requests != nil { - in, out := &in.Requests, &out.Requests - *out = make(v1.ResourceList, len(*in)) - for key, val := range *in { - (*out)[key] = val.DeepCopy() - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerContainerResources. -func (in *DatadogPodAutoscalerContainerResources) DeepCopy() *DatadogPodAutoscalerContainerResources { - if in == nil { - return nil - } - out := new(DatadogPodAutoscalerContainerResources) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DatadogPodAutoscalerHorizontalAction) DeepCopyInto(out *DatadogPodAutoscalerHorizontalAction) { - *out = *in - in.Time.DeepCopyInto(&out.Time) - if in.RecommendedReplicas != nil { - in, out := &in.RecommendedReplicas, &out.RecommendedReplicas - *out = new(int32) - **out = **in - } - if in.LimitedReason != nil { - in, out := &in.LimitedReason, &out.LimitedReason - *out = new(string) - **out = **in - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerHorizontalAction. -func (in *DatadogPodAutoscalerHorizontalAction) DeepCopy() *DatadogPodAutoscalerHorizontalAction { - if in == nil { - return nil - } - out := new(DatadogPodAutoscalerHorizontalAction) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DatadogPodAutoscalerHorizontalStatus) DeepCopyInto(out *DatadogPodAutoscalerHorizontalStatus) { - *out = *in - if in.Target != nil { - in, out := &in.Target, &out.Target - *out = new(DatadogPodAutoscalerHorizontalTargetStatus) - (*in).DeepCopyInto(*out) - } - if in.LastActions != nil { - in, out := &in.LastActions, &out.LastActions - *out = make([]DatadogPodAutoscalerHorizontalAction, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerHorizontalStatus. -func (in *DatadogPodAutoscalerHorizontalStatus) DeepCopy() *DatadogPodAutoscalerHorizontalStatus { - if in == nil { - return nil - } - out := new(DatadogPodAutoscalerHorizontalStatus) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DatadogPodAutoscalerHorizontalTargetStatus) DeepCopyInto(out *DatadogPodAutoscalerHorizontalTargetStatus) { - *out = *in - in.GeneratedAt.DeepCopyInto(&out.GeneratedAt) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerHorizontalTargetStatus. -func (in *DatadogPodAutoscalerHorizontalTargetStatus) DeepCopy() *DatadogPodAutoscalerHorizontalTargetStatus { - if in == nil { - return nil - } - out := new(DatadogPodAutoscalerHorizontalTargetStatus) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *DatadogPodAutoscalerList) DeepCopyInto(out *DatadogPodAutoscalerList) { *out = *in @@ -1307,12 +1091,12 @@ func (in *DatadogPodAutoscalerPolicy) DeepCopyInto(out *DatadogPodAutoscalerPoli } if in.Upscale != nil { in, out := &in.Upscale, &out.Upscale - *out = new(DatadogPodAutoscalerScalingPolicy) + *out = new(common.DatadogPodAutoscalerScalingPolicy) (*in).DeepCopyInto(*out) } if in.Downscale != nil { in, out := &in.Downscale, &out.Downscale - *out = new(DatadogPodAutoscalerScalingPolicy) + *out = new(common.DatadogPodAutoscalerScalingPolicy) (*in).DeepCopyInto(*out) } } @@ -1327,69 +1111,6 @@ func (in *DatadogPodAutoscalerPolicy) DeepCopy() *DatadogPodAutoscalerPolicy { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DatadogPodAutoscalerResourceTarget) DeepCopyInto(out *DatadogPodAutoscalerResourceTarget) { - *out = *in - in.Value.DeepCopyInto(&out.Value) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerResourceTarget. -func (in *DatadogPodAutoscalerResourceTarget) DeepCopy() *DatadogPodAutoscalerResourceTarget { - if in == nil { - return nil - } - out := new(DatadogPodAutoscalerResourceTarget) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DatadogPodAutoscalerScalingPolicy) DeepCopyInto(out *DatadogPodAutoscalerScalingPolicy) { - *out = *in - if in.Strategy != nil { - in, out := &in.Strategy, &out.Strategy - *out = new(DatadogPodAutoscalerScalingStrategySelect) - **out = **in - } - if in.Rules != nil { - in, out := &in.Rules, &out.Rules - *out = make([]DatadogPodAutoscalerScalingRule, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerScalingPolicy. -func (in *DatadogPodAutoscalerScalingPolicy) DeepCopy() *DatadogPodAutoscalerScalingPolicy { - if in == nil { - return nil - } - out := new(DatadogPodAutoscalerScalingPolicy) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DatadogPodAutoscalerScalingRule) DeepCopyInto(out *DatadogPodAutoscalerScalingRule) { - *out = *in - if in.Match != nil { - in, out := &in.Match, &out.Match - *out = new(DatadogPodAutoscalerScalingRuleMatch) - **out = **in - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerScalingRule. -func (in *DatadogPodAutoscalerScalingRule) DeepCopy() *DatadogPodAutoscalerScalingRule { - if in == nil { - return nil - } - out := new(DatadogPodAutoscalerScalingRule) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *DatadogPodAutoscalerSpec) DeepCopyInto(out *DatadogPodAutoscalerSpec) { *out = *in @@ -1406,14 +1127,14 @@ func (in *DatadogPodAutoscalerSpec) DeepCopyInto(out *DatadogPodAutoscalerSpec) } if in.Targets != nil { in, out := &in.Targets, &out.Targets - *out = make([]DatadogPodAutoscalerTarget, len(*in)) + *out = make([]common.DatadogPodAutoscalerObjective, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } } if in.Constraints != nil { in, out := &in.Constraints, &out.Constraints - *out = new(DatadogPodAutoscalerConstraints) + *out = new(common.DatadogPodAutoscalerConstraints) (*in).DeepCopyInto(*out) } } @@ -1428,93 +1149,6 @@ func (in *DatadogPodAutoscalerSpec) DeepCopy() *DatadogPodAutoscalerSpec { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DatadogPodAutoscalerStatus) DeepCopyInto(out *DatadogPodAutoscalerStatus) { - *out = *in - if in.Vertical != nil { - in, out := &in.Vertical, &out.Vertical - *out = new(DatadogPodAutoscalerVerticalStatus) - (*in).DeepCopyInto(*out) - } - if in.Horizontal != nil { - in, out := &in.Horizontal, &out.Horizontal - *out = new(DatadogPodAutoscalerHorizontalStatus) - (*in).DeepCopyInto(*out) - } - if in.CurrentReplicas != nil { - in, out := &in.CurrentReplicas, &out.CurrentReplicas - *out = new(int32) - **out = **in - } - if in.Conditions != nil { - in, out := &in.Conditions, &out.Conditions - *out = make([]DatadogPodAutoscalerCondition, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerStatus. -func (in *DatadogPodAutoscalerStatus) DeepCopy() *DatadogPodAutoscalerStatus { - if in == nil { - return nil - } - out := new(DatadogPodAutoscalerStatus) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DatadogPodAutoscalerTarget) DeepCopyInto(out *DatadogPodAutoscalerTarget) { - *out = *in - if in.PodResource != nil { - in, out := &in.PodResource, &out.PodResource - *out = new(DatadogPodAutoscalerResourceTarget) - (*in).DeepCopyInto(*out) - } - if in.ContainerResource != nil { - in, out := &in.ContainerResource, &out.ContainerResource - *out = new(DatadogPodAutoscalerContainerResourceTarget) - (*in).DeepCopyInto(*out) - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerTarget. -func (in *DatadogPodAutoscalerTarget) DeepCopy() *DatadogPodAutoscalerTarget { - if in == nil { - return nil - } - out := new(DatadogPodAutoscalerTarget) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DatadogPodAutoscalerTargetValue) DeepCopyInto(out *DatadogPodAutoscalerTargetValue) { - *out = *in - if in.Absolute != nil { - in, out := &in.Absolute, &out.Absolute - x := (*in).DeepCopy() - *out = &x - } - if in.Utilization != nil { - in, out := &in.Utilization, &out.Utilization - *out = new(int32) - **out = **in - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerTargetValue. -func (in *DatadogPodAutoscalerTargetValue) DeepCopy() *DatadogPodAutoscalerTargetValue { - if in == nil { - return nil - } - out := new(DatadogPodAutoscalerTargetValue) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *DatadogPodAutoscalerUpdatePolicy) DeepCopyInto(out *DatadogPodAutoscalerUpdatePolicy) { *out = *in @@ -1530,77 +1164,6 @@ func (in *DatadogPodAutoscalerUpdatePolicy) DeepCopy() *DatadogPodAutoscalerUpda return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DatadogPodAutoscalerVerticalAction) DeepCopyInto(out *DatadogPodAutoscalerVerticalAction) { - *out = *in - in.Time.DeepCopyInto(&out.Time) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerVerticalAction. -func (in *DatadogPodAutoscalerVerticalAction) DeepCopy() *DatadogPodAutoscalerVerticalAction { - if in == nil { - return nil - } - out := new(DatadogPodAutoscalerVerticalAction) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DatadogPodAutoscalerVerticalStatus) DeepCopyInto(out *DatadogPodAutoscalerVerticalStatus) { - *out = *in - if in.Target != nil { - in, out := &in.Target, &out.Target - *out = new(DatadogPodAutoscalerVerticalTargetStatus) - (*in).DeepCopyInto(*out) - } - if in.LastAction != nil { - in, out := &in.LastAction, &out.LastAction - *out = new(DatadogPodAutoscalerVerticalAction) - (*in).DeepCopyInto(*out) - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerVerticalStatus. -func (in *DatadogPodAutoscalerVerticalStatus) DeepCopy() *DatadogPodAutoscalerVerticalStatus { - if in == nil { - return nil - } - out := new(DatadogPodAutoscalerVerticalStatus) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DatadogPodAutoscalerVerticalTargetStatus) DeepCopyInto(out *DatadogPodAutoscalerVerticalTargetStatus) { - *out = *in - in.GeneratedAt.DeepCopyInto(&out.GeneratedAt) - if in.Scaled != nil { - in, out := &in.Scaled, &out.Scaled - *out = new(int32) - **out = **in - } - if in.DesiredResources != nil { - in, out := &in.DesiredResources, &out.DesiredResources - *out = make([]DatadogPodAutoscalerContainerResources, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - out.PODCPURequest = in.PODCPURequest.DeepCopy() - out.PODMemoryRequest = in.PODMemoryRequest.DeepCopy() -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerVerticalTargetStatus. -func (in *DatadogPodAutoscalerVerticalTargetStatus) DeepCopy() *DatadogPodAutoscalerVerticalTargetStatus { - if in == nil { - return nil - } - out := new(DatadogPodAutoscalerVerticalTargetStatus) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *DatadogSLO) DeepCopyInto(out *DatadogSLO) { *out = *in diff --git a/api/datadoghq/v1alpha2/datadogpodautoscaler_types.go b/api/datadoghq/v1alpha2/datadogpodautoscaler_types.go index 866722253..c816050ba 100644 --- a/api/datadoghq/v1alpha2/datadogpodautoscaler_types.go +++ b/api/datadoghq/v1alpha2/datadogpodautoscaler_types.go @@ -6,9 +6,8 @@ package v1alpha2 import ( + "github.com/DataDog/datadog-operator/api/datadoghq/common" autoscalingv2 "k8s.io/api/autoscaling/v2" - corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -60,18 +59,6 @@ import ( // minAllowed: // maxAllowed: -// DatadogPodAutoscalerOwner defines the source of truth for this object (local or remote) -// +kubebuilder:validation:Enum:=Local;Remote -type DatadogPodAutoscalerOwner string - -const ( - // DatadogPodAutoscalerLocalOwner states that this `DatadogPodAutoscaler` object is created/managed outside of the Datadog app. - DatadogPodAutoscalerLocalOwner DatadogPodAutoscalerOwner = "Local" - - // DatadogPodAutoscalerRemoteOwner states that this `DatadogPodAutoscaler` object is created/managed in the Datadog app. - DatadogPodAutoscalerRemoteOwner DatadogPodAutoscalerOwner = "Remote" -) - // DatadogPodAutoscalerSpec defines the desired state of DatadogPodAutoscaler type DatadogPodAutoscalerSpec struct { // TargetRef is the reference to the resource to scale. @@ -79,7 +66,7 @@ type DatadogPodAutoscalerSpec struct { // Owner defines the source of truth for this object (local or remote). // Value must be set when a DatadogPodAutoscaler object is created. - Owner DatadogPodAutoscalerOwner `json:"owner"` + Owner common.DatadogPodAutoscalerOwner `json:"owner"` // RemoteVersion is the version of the .Spec currently stored in this object. // This is only set if the owner is Remote. @@ -94,10 +81,10 @@ type DatadogPodAutoscalerSpec struct { // Default to a single target to maintain 80% POD CPU utilization. // +listType=atomic // +optional - Objectives []DatadogPodAutoscalerObjective `json:"objectives,omitempty"` + Objectives []common.DatadogPodAutoscalerObjective `json:"objectives,omitempty"` // Constraints defines constraints that should always be respected. - Constraints *DatadogPodAutoscalerConstraints `json:"constraints,omitempty"` + Constraints *common.DatadogPodAutoscalerConstraints `json:"constraints,omitempty"` } // DatadogPodAutoscalerApplyMode specifies if the controller should apply recommendations. @@ -123,385 +110,13 @@ type DatadogPodAutoscalerApplyPolicy struct { Mode DatadogPodAutoscalerApplyMode `json:"mode"` // Update defines the policy for updating the target resource. - Update *DatadogPodAutoscalerUpdatePolicy `json:"update,omitempty"` + Update *common.DatadogPodAutoscalerUpdatePolicy `json:"update,omitempty"` // ScaleUp defines the policy to scale up the target resource. - ScaleUp *DatadogPodAutoscalerScalingPolicy `json:"scaleup,omitempty"` + ScaleUp *common.DatadogPodAutoscalerScalingPolicy `json:"scaleUp,omitempty"` // ScaleDown defines the policy to scale down the target resource. - ScaleDown *DatadogPodAutoscalerScalingPolicy `json:"scaledown,omitempty"` -} - -// DatadogPodAutoscalerUpdateStrategy defines the mode of the update policy. -// +kubebuilder:validation:Enum:=Auto;Disabled -type DatadogPodAutoscalerUpdateStrategy string - -const ( - // DatadogPodAutoscalerAutoUpdateStrategy is the default mode. - DatadogPodAutoscalerAutoUpdateStrategy DatadogPodAutoscalerUpdateStrategy = "Auto" - - // DatadogPodAutoscalerDisabledUpdateStrategy will disable the update of the target resource. - DatadogPodAutoscalerDisabledUpdateStrategy DatadogPodAutoscalerUpdateStrategy = "Disabled" -) - -// DatadogPodAutoscalerUpdatePolicy defines the policy to update the target resource. -type DatadogPodAutoscalerUpdatePolicy struct { - // Strategy defines the mode of the update policy. - Strategy DatadogPodAutoscalerUpdateStrategy `json:"strategy,omitempty"` -} - -// -// Scaling policy is inspired by the HorizontalPodAutoscalerV2 -// https://github.com/kubernetes/api/blob/master/autoscaling/v2/types.go -// Copyright 2021 The Kubernetes Authors. -// - -// DatadogPodAutoscalerScalingStrategySelect is used to specify which policy should be used while scaling in a certain direction -// +kubebuilder:validation:Enum:=Max;Min;Disabled -type DatadogPodAutoscalerScalingStrategySelect string - -const ( - // DatadogPodAutoscalerMaxChangeStrategySelect selects the policy with the highest possible change. - DatadogPodAutoscalerMaxChangeStrategySelect DatadogPodAutoscalerScalingStrategySelect = "Max" - - // DatadogPodAutoscalerMinChangeStrategySelect selects the policy with the lowest possible change. - DatadogPodAutoscalerMinChangeStrategySelect DatadogPodAutoscalerScalingStrategySelect = "Min" - - // DatadogPodAutoscalerDisabledStrategySelect disables the scaling in this direction. - DatadogPodAutoscalerDisabledStrategySelect DatadogPodAutoscalerScalingStrategySelect = "Disabled" -) - -// DatadogPodAutoscalerScalingPolicy defines the policy to scale the target resource. -type DatadogPodAutoscalerScalingPolicy struct { - // Strategy is used to specify which policy should be used. - // If not set, the default value Max is used. - // +optional - Strategy *DatadogPodAutoscalerScalingStrategySelect `json:"strategy,omitempty"` - - // Rules is a list of potential scaling polices which can be used during scaling. - // At least one policy must be specified, otherwise the DatadogPodAutoscalerScalingPolicy will be discarded as invalid - // +listType=atomic - // +optional - Rules []DatadogPodAutoscalerScalingRule `json:"rules,omitempty"` - - // StabilizationWindowSeconds is the number of seconds the controller should lookback at previous recommendations - // before deciding to apply a new one. Defaults to 0. - // +optional - // +kubebuilder:validation:Minimum=0 - // +kubebuilder:validation:Maximum=1800 - StabilizationWindowSeconds int32 `json:"stabilizationWindowSeconds,omitempty"` -} - -// DatadogPodAutoscalerScalingRuleType defines how a scaling rule value should be interpreted. -// +kubebuilder:validation:Enum:=Pods;Percent -type DatadogPodAutoscalerScalingRuleType string - -const ( - // DatadogPodAutoscalerPodsScalingRuleType specifies a change in the absolute number of pods compared to the starting number of pods. - DatadogPodAutoscalerPodsScalingRuleType DatadogPodAutoscalerScalingRuleType = "Pods" - - // DatadogPodAutoscalerPercentScalingRuleType specifies a relative amount of change compared to the starting number of pods. - DatadogPodAutoscalerPercentScalingRuleType DatadogPodAutoscalerScalingRuleType = "Percent" -) - -// DatadogPodAutoscalerScalingRule defines rules for horizontal scaling that should be true for a certain amount of time. -type DatadogPodAutoscalerScalingRule struct { - // Type is used to specify the scaling policy. - Type DatadogPodAutoscalerScalingRuleType `json:"type"` - - // Value contains the amount of change which is permitted by the policy. - // Setting it to 0 will prevent any scaling in this direction. - // +kubebuilder:validation:Minimum=0 - Value int32 `json:"value"` - - // PeriodSeconds specifies the window of time for which the policy should hold true. - // PeriodSeconds must be greater than zero and less than or equal to 1800 (30 min). - // +kubebuilder:validation:Minimum=1 - // +kubebuilder:validation:Maximum=1800 - PeriodSeconds int32 `json:"periodSeconds"` -} - -// DatadogPodAutoscalerTargetType defines the type of the target. -// +kubebuilder:validation:Enum:=PodResource;ContainerResource -type DatadogPodAutoscalerTargetType string - -const ( - // DatadogPodAutoscalerResourceTargetType allows to set pod-level resource targets. - DatadogPodAutoscalerResourceTargetType DatadogPodAutoscalerTargetType = "PodResource" - - // DatadogPodAutoscalerContainerResourceTargetType allows to set container-level resource targets. - DatadogPodAutoscalerContainerResourceTargetType DatadogPodAutoscalerTargetType = "ContainerResource" -) - -// DatadogPodAutoscalerObjective defines the objectives to reach and maintain for the target resource. -type DatadogPodAutoscalerObjective struct { - // Type sets the type of the target. - Type DatadogPodAutoscalerTargetType `json:"type"` - - // PodResource allows to set a pod-level resource target. - PodResource *DatadogPodAutoscalerResourceTarget `json:"podResource,omitempty"` - - // ContainerResource allows to set a container-level resource target. - ContainerResource *DatadogPodAutoscalerContainerResourceTarget `json:"containerResource,omitempty"` -} - -// DatadogPodAutoscalerResourceTarget defines a pod-level resource target (for instance, CPU Utilization at 80%) -// For pod-level targets, resources are the sum of all containers resources. -// Utilization is computed from sum(usage) / sum(requests). -type DatadogPodAutoscalerResourceTarget struct { - // Name is the name of the resource. - // +kubebuilder:validation:Enum:=cpu - Name corev1.ResourceName `json:"name"` - - // Value is the value of the target. - Value DatadogPodAutoscalerTargetValue `json:"value"` -} - -// DatadogPodAutoscalerContainerResourceTarget defines a container-level resource target (for instance, CPU Utilization for container named "foo" at 80%) -type DatadogPodAutoscalerContainerResourceTarget struct { - // Name is the name of the resource. - // +kubebuilder:validation:Enum:=cpu - Name corev1.ResourceName `json:"name"` - - // Value is the value of the target. - Value DatadogPodAutoscalerTargetValue `json:"value"` - - // Container is the name of the container. - Container string `json:"container"` -} - -// DatadogPodAutoscalerTargetValue defines the value of the target. -type DatadogPodAutoscalerTargetValue struct { - // Utilization defines a percentage of the target compared to requested resource - // +kubebuilder:validation:Minimum=0 - // +kubebuilder:validation:Maximum=100 - Utilization *int32 `json:"utilization,omitempty"` -} - -// DatadogPodAutoscalerConstraints defines constraints that should always be respected. -type DatadogPodAutoscalerConstraints struct { - // MinReplicas is the lower limit for the number of pod replicas. Needs to be >= 1. Defaults to 1. - // +kubebuilder:validation:Minimum=1 - MinReplicas *int32 `json:"minReplicas,omitempty"` - - // MaxReplicas is the upper limit for the number of POD replicas. Needs to be >= minReplicas. - MaxReplicas int32 `json:"maxReplicas"` - - // Containers defines constraints for the containers. - Containers []DatadogPodAutoscalerContainerConstraints `json:"containers,omitempty"` -} - -// DatadogPodAutoscalerContainerConstraints defines constraints that should always be respected for a container. -// If no constraints are set, it enables resource scaling for all containers without any constraints. -type DatadogPodAutoscalerContainerConstraints struct { - // Name is the name of the container. Can be "*" to apply to all containers. - Name string `json:"name"` - - // Enabled, if false, allows one to disable resource autoscaling for the container. Defaults to true. - Enabled *bool `json:"enabled,omitempty"` - - // Requests defines the constraints for the requests of the container. - Requests *DatadogPodAutoscalerContainerResourceConstraints `json:"requests,omitempty"` -} - -// DatadogPodAutoscalerContainerResourceConstraints defines constraints for the resources recommended for a container. -type DatadogPodAutoscalerContainerResourceConstraints struct { - // MinAllowed is the lower limit for the requests of the container. - // +optional - MinAllowed corev1.ResourceList `json:"minAllowed,omitempty"` - - // MaxAllowed is the upper limit for the requests of the container. - // +optional - MaxAllowed corev1.ResourceList `json:"maxAllowed,omitempty"` -} - -// DatadogPodAutoscalerStatus defines the observed state of DatadogPodAutoscaler -type DatadogPodAutoscalerStatus struct { - // Vertical is the status of the vertical scaling, if activated. - // +optional - Vertical *DatadogPodAutoscalerVerticalStatus `json:"vertical,omitempty"` - - // Horizontal is the status of the horizontal scaling, if activated. - // +optional - Horizontal *DatadogPodAutoscalerHorizontalStatus `json:"horizontal,omitempty"` - - // CurrentReplicas is the current number of pods for the targetRef observed by the controller. - // +optional - CurrentReplicas *int32 `json:"currentReplicas,omitempty"` - - // Conditions describe the current state of the DatadogPodAutoscaler operations. - // +patchMergeKey=type - // +patchStrategy=merge - // +listType=map - // +listMapKey=type - // +optional - Conditions []DatadogPodAutoscalerCondition `json:"conditions,omitempty"` -} - -// DatadogPodAutoscalerValueSource defines the source of the value used to scale the target resource. -type DatadogPodAutoscalerValueSource string - -const ( - // DatadogPodAutoscalerAutoscalingValueSource is a recommendation that comes from active autoscaling. - DatadogPodAutoscalerAutoscalingValueSource DatadogPodAutoscalerValueSource = "Autoscaling" - - // DatadogPodAutoscalerManualValueSource is a recommendation that comes from manually applying a recommendation. - DatadogPodAutoscalerManualValueSource DatadogPodAutoscalerValueSource = "Manual" - - // DatadogPodAutoscalerLocalValueSource is a recommendation that comes from the local fallback. - DatadogPodAutoscalerLocalValueSource DatadogPodAutoscalerValueSource = "Local" -) - -// DatadogPodAutoscalerHorizontalStatus defines the status of the horizontal scaling -type DatadogPodAutoscalerHorizontalStatus struct { - // Target is the current target of the horizontal scaling - Target *DatadogPodAutoscalerHorizontalTargetStatus `json:"target,omitempty"` - - // LastActions are the last successful actions done by the controller - LastActions []DatadogPodAutoscalerHorizontalAction `json:"lastActions,omitempty"` -} - -// DatadogPodAutoscalerHorizontalTargetStatus defines the current target of the horizontal scaling -type DatadogPodAutoscalerHorizontalTargetStatus struct { - // Source is the source of the value used to scale the target resource - Source DatadogPodAutoscalerValueSource `json:"source"` - - // GeneratedAt is the timestamp at which the recommendation was generated - GeneratedAt metav1.Time `json:"generatedAt,omitempty"` - - // Replicas is the desired number of replicas for the resource - Replicas int32 `json:"desiredReplicas"` -} - -// DatadogPodAutoscalerHorizontalAction represents a horizontal action done by the controller -type DatadogPodAutoscalerHorizontalAction struct { - // Time is the timestamp of the action - Time metav1.Time `json:"time"` - - // FromReplicas is the number of replicas before the action - FromReplicas int32 `json:"replicas"` - - // ToReplicas is the effective number of replicas after the action - ToReplicas int32 `json:"toReplicas"` - - // RecommendedReplicas is the original number of replicas recommended by Datadog - RecommendedReplicas *int32 `json:"recommendedReplicas,omitempty"` - - // LimitedReason is the reason why the action was limited (that is ToReplicas != RecommendedReplicas) - LimitedReason *string `json:"limitedReason,omitempty"` -} - -// DatadogPodAutoscalerVerticalStatus defines the status of the vertical scaling -type DatadogPodAutoscalerVerticalStatus struct { - // Target is the current target of the vertical scaling - Target *DatadogPodAutoscalerVerticalTargetStatus `json:"target,omitempty"` - - // LastAction is the last successful action done by the controller - LastAction *DatadogPodAutoscalerVerticalAction `json:"lastAction,omitempty"` -} - -// DatadogPodAutoscalerVerticalTargetStatus defines the current target of the vertical scaling -type DatadogPodAutoscalerVerticalTargetStatus struct { - // Source is the source of the value used to scale the target resource - Source DatadogPodAutoscalerValueSource `json:"source"` - - // GeneratedAt is the timestamp at which the recommendation was generated - GeneratedAt metav1.Time `json:"generatedAt,omitempty"` - - // Version is the current version of the received recommendation - Version string `json:"version"` - - // Scaled is the current number of pods having desired resources - Scaled *int32 `json:"scaled,omitempty"` - - // DesiredResources is the desired resources for containers - DesiredResources []DatadogPodAutoscalerContainerResources `json:"desiredResources"` - - // PodCPURequest is the sum of CPU requests for all containers (used for display) - PodCPURequest resource.Quantity `json:"podCPURequest"` - - // PodMemoryRequest is the sum of memory requests for all containers (used for display) - PodMemoryRequest resource.Quantity `json:"podMemoryRequest"` -} - -// DatadogPodAutoscalerVerticalActionType represents the type of action done by the controller -type DatadogPodAutoscalerVerticalActionType string - -const ( - // DatadogPodAutoscalerRolloutTriggeredVerticalActionType is the action when the controller triggers a rollout of the targetRef - DatadogPodAutoscalerRolloutTriggeredVerticalActionType DatadogPodAutoscalerVerticalActionType = "RolloutTriggered" -) - -// DatadogPodAutoscalerVerticalAction represents a vertical action done by the controller -type DatadogPodAutoscalerVerticalAction struct { - // Time is the timestamp of the action - Time metav1.Time `json:"time"` - - // Version is the version of the recommendation used for the action - Version string `json:"version"` - - // Type is the type of action - Type DatadogPodAutoscalerVerticalActionType `json:"type"` -} - -type DatadogPodAutoscalerContainerResources struct { - // Name is the name of the container - Name string `json:"name"` - - // Limits describes the maximum amount of compute resources allowed. - // +optional - Limits corev1.ResourceList `json:"limits,omitempty"` - - // Requests describes the requested amount of compute resources. - // +optional - Requests corev1.ResourceList `json:"requests,omitempty"` -} - -// DatadogPodAutoscalerConditionType is the type used to represent a DatadogPodAutoscaler condition -type DatadogPodAutoscalerConditionType string - -const ( - // DatadogPodAutoscalerErrorCondition is true when a global error is encountered processing this DatadogPodAutoscaler. - DatadogPodAutoscalerErrorCondition DatadogPodAutoscalerConditionType = "Error" - - // DatadogPodAutoscalerActiveCondition is true when the DatadogPodAutoscaler can be used for autoscaling. - DatadogPodAutoscalerActiveCondition DatadogPodAutoscalerConditionType = "Active" - - // DatadogPodAutoscalerHorizontalAbleToRecommendCondition is true when a horizontal recommendation can be received from Datadog. - DatadogPodAutoscalerHorizontalAbleToRecommendCondition DatadogPodAutoscalerConditionType = "HorizontalAbleToRecommend" - - // DatadogPodAutoscalerHorizontalAbleToScaleCondition is true when horizontal scaling is working correctly. - DatadogPodAutoscalerHorizontalAbleToScaleCondition DatadogPodAutoscalerConditionType = "HorizontalAbleToScale" - - // DatadogPodAutoscalerHorizontalScalingLimitedCondition is true when horizontal scaling is limited by constraints. - DatadogPodAutoscalerHorizontalScalingLimitedCondition DatadogPodAutoscalerConditionType = "HorizontalScalingLimited" - - // DatadogPodAutoscalerVerticalAbleToRecommendCondition is true when a vertical recommendation can be received from Datadog. - DatadogPodAutoscalerVerticalAbleToRecommendCondition DatadogPodAutoscalerConditionType = "VerticalAbleToRecommend" - - // DatadogPodAutoscalerVerticalAbleToApply is true when the targetRef can be rolled out to pick up new resources. - DatadogPodAutoscalerVerticalAbleToApply DatadogPodAutoscalerConditionType = "VerticalAbleToApply" -) - -// DatadogPodAutoscalerCondition describes the state of DatadogPodAutoscaler. -type DatadogPodAutoscalerCondition struct { - // DatadogPodAutoscalerConditionType is the type of DatadogPodAutoscaler condition. - Type DatadogPodAutoscalerConditionType `json:"type"` - - // Status of the condition, one of True, False, Unknown. - Status corev1.ConditionStatus `json:"status"` - - // Last time the condition transitioned from one status to another. - // +optional - LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"` - - // The reason for the condition's last transition. - // +optional - Reason string `json:"reason,omitempty"` - - // A human readable message indicating details about the transition. - // +optional - Message string `json:"message,omitempty"` + ScaleDown *common.DatadogPodAutoscalerScalingPolicy `json:"scaleDown,omitempty"` } // +kubebuilder:object:root=true @@ -524,8 +139,8 @@ type DatadogPodAutoscaler struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` - Spec DatadogPodAutoscalerSpec `json:"spec,omitempty"` - Status DatadogPodAutoscalerStatus `json:"status,omitempty"` + Spec DatadogPodAutoscalerSpec `json:"spec,omitempty"` + Status common.DatadogPodAutoscalerStatus `json:"status,omitempty"` } //+kubebuilder:object:root=true diff --git a/api/datadoghq/v1alpha2/zz_generated.deepcopy.go b/api/datadoghq/v1alpha2/zz_generated.deepcopy.go index 96d9a58ab..f7f2a06f1 100644 --- a/api/datadoghq/v1alpha2/zz_generated.deepcopy.go +++ b/api/datadoghq/v1alpha2/zz_generated.deepcopy.go @@ -10,7 +10,7 @@ package v1alpha2 import ( - "k8s.io/api/core/v1" + "github.com/DataDog/datadog-operator/api/datadoghq/common" runtime "k8s.io/apimachinery/pkg/runtime" ) @@ -46,17 +46,17 @@ func (in *DatadogPodAutoscalerApplyPolicy) DeepCopyInto(out *DatadogPodAutoscale *out = *in if in.Update != nil { in, out := &in.Update, &out.Update - *out = new(DatadogPodAutoscalerUpdatePolicy) + *out = new(common.DatadogPodAutoscalerUpdatePolicy) **out = **in } if in.ScaleUp != nil { in, out := &in.ScaleUp, &out.ScaleUp - *out = new(DatadogPodAutoscalerScalingPolicy) + *out = new(common.DatadogPodAutoscalerScalingPolicy) (*in).DeepCopyInto(*out) } if in.ScaleDown != nil { in, out := &in.ScaleDown, &out.ScaleDown - *out = new(DatadogPodAutoscalerScalingPolicy) + *out = new(common.DatadogPodAutoscalerScalingPolicy) (*in).DeepCopyInto(*out) } } @@ -71,217 +71,6 @@ func (in *DatadogPodAutoscalerApplyPolicy) DeepCopy() *DatadogPodAutoscalerApply return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DatadogPodAutoscalerCondition) DeepCopyInto(out *DatadogPodAutoscalerCondition) { - *out = *in - in.LastTransitionTime.DeepCopyInto(&out.LastTransitionTime) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerCondition. -func (in *DatadogPodAutoscalerCondition) DeepCopy() *DatadogPodAutoscalerCondition { - if in == nil { - return nil - } - out := new(DatadogPodAutoscalerCondition) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DatadogPodAutoscalerConstraints) DeepCopyInto(out *DatadogPodAutoscalerConstraints) { - *out = *in - if in.MinReplicas != nil { - in, out := &in.MinReplicas, &out.MinReplicas - *out = new(int32) - **out = **in - } - if in.Containers != nil { - in, out := &in.Containers, &out.Containers - *out = make([]DatadogPodAutoscalerContainerConstraints, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerConstraints. -func (in *DatadogPodAutoscalerConstraints) DeepCopy() *DatadogPodAutoscalerConstraints { - if in == nil { - return nil - } - out := new(DatadogPodAutoscalerConstraints) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DatadogPodAutoscalerContainerConstraints) DeepCopyInto(out *DatadogPodAutoscalerContainerConstraints) { - *out = *in - if in.Enabled != nil { - in, out := &in.Enabled, &out.Enabled - *out = new(bool) - **out = **in - } - if in.Requests != nil { - in, out := &in.Requests, &out.Requests - *out = new(DatadogPodAutoscalerContainerResourceConstraints) - (*in).DeepCopyInto(*out) - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerContainerConstraints. -func (in *DatadogPodAutoscalerContainerConstraints) DeepCopy() *DatadogPodAutoscalerContainerConstraints { - if in == nil { - return nil - } - out := new(DatadogPodAutoscalerContainerConstraints) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DatadogPodAutoscalerContainerResourceConstraints) DeepCopyInto(out *DatadogPodAutoscalerContainerResourceConstraints) { - *out = *in - if in.MinAllowed != nil { - in, out := &in.MinAllowed, &out.MinAllowed - *out = make(v1.ResourceList, len(*in)) - for key, val := range *in { - (*out)[key] = val.DeepCopy() - } - } - if in.MaxAllowed != nil { - in, out := &in.MaxAllowed, &out.MaxAllowed - *out = make(v1.ResourceList, len(*in)) - for key, val := range *in { - (*out)[key] = val.DeepCopy() - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerContainerResourceConstraints. -func (in *DatadogPodAutoscalerContainerResourceConstraints) DeepCopy() *DatadogPodAutoscalerContainerResourceConstraints { - if in == nil { - return nil - } - out := new(DatadogPodAutoscalerContainerResourceConstraints) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DatadogPodAutoscalerContainerResourceTarget) DeepCopyInto(out *DatadogPodAutoscalerContainerResourceTarget) { - *out = *in - in.Value.DeepCopyInto(&out.Value) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerContainerResourceTarget. -func (in *DatadogPodAutoscalerContainerResourceTarget) DeepCopy() *DatadogPodAutoscalerContainerResourceTarget { - if in == nil { - return nil - } - out := new(DatadogPodAutoscalerContainerResourceTarget) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DatadogPodAutoscalerContainerResources) DeepCopyInto(out *DatadogPodAutoscalerContainerResources) { - *out = *in - if in.Limits != nil { - in, out := &in.Limits, &out.Limits - *out = make(v1.ResourceList, len(*in)) - for key, val := range *in { - (*out)[key] = val.DeepCopy() - } - } - if in.Requests != nil { - in, out := &in.Requests, &out.Requests - *out = make(v1.ResourceList, len(*in)) - for key, val := range *in { - (*out)[key] = val.DeepCopy() - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerContainerResources. -func (in *DatadogPodAutoscalerContainerResources) DeepCopy() *DatadogPodAutoscalerContainerResources { - if in == nil { - return nil - } - out := new(DatadogPodAutoscalerContainerResources) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DatadogPodAutoscalerHorizontalAction) DeepCopyInto(out *DatadogPodAutoscalerHorizontalAction) { - *out = *in - in.Time.DeepCopyInto(&out.Time) - if in.RecommendedReplicas != nil { - in, out := &in.RecommendedReplicas, &out.RecommendedReplicas - *out = new(int32) - **out = **in - } - if in.LimitedReason != nil { - in, out := &in.LimitedReason, &out.LimitedReason - *out = new(string) - **out = **in - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerHorizontalAction. -func (in *DatadogPodAutoscalerHorizontalAction) DeepCopy() *DatadogPodAutoscalerHorizontalAction { - if in == nil { - return nil - } - out := new(DatadogPodAutoscalerHorizontalAction) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DatadogPodAutoscalerHorizontalStatus) DeepCopyInto(out *DatadogPodAutoscalerHorizontalStatus) { - *out = *in - if in.Target != nil { - in, out := &in.Target, &out.Target - *out = new(DatadogPodAutoscalerHorizontalTargetStatus) - (*in).DeepCopyInto(*out) - } - if in.LastActions != nil { - in, out := &in.LastActions, &out.LastActions - *out = make([]DatadogPodAutoscalerHorizontalAction, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerHorizontalStatus. -func (in *DatadogPodAutoscalerHorizontalStatus) DeepCopy() *DatadogPodAutoscalerHorizontalStatus { - if in == nil { - return nil - } - out := new(DatadogPodAutoscalerHorizontalStatus) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DatadogPodAutoscalerHorizontalTargetStatus) DeepCopyInto(out *DatadogPodAutoscalerHorizontalTargetStatus) { - *out = *in - in.GeneratedAt.DeepCopyInto(&out.GeneratedAt) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerHorizontalTargetStatus. -func (in *DatadogPodAutoscalerHorizontalTargetStatus) DeepCopy() *DatadogPodAutoscalerHorizontalTargetStatus { - if in == nil { - return nil - } - out := new(DatadogPodAutoscalerHorizontalTargetStatus) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *DatadogPodAutoscalerList) DeepCopyInto(out *DatadogPodAutoscalerList) { *out = *in @@ -314,87 +103,6 @@ func (in *DatadogPodAutoscalerList) DeepCopyObject() runtime.Object { return nil } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DatadogPodAutoscalerObjective) DeepCopyInto(out *DatadogPodAutoscalerObjective) { - *out = *in - if in.PodResource != nil { - in, out := &in.PodResource, &out.PodResource - *out = new(DatadogPodAutoscalerResourceTarget) - (*in).DeepCopyInto(*out) - } - if in.ContainerResource != nil { - in, out := &in.ContainerResource, &out.ContainerResource - *out = new(DatadogPodAutoscalerContainerResourceTarget) - (*in).DeepCopyInto(*out) - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerObjective. -func (in *DatadogPodAutoscalerObjective) DeepCopy() *DatadogPodAutoscalerObjective { - if in == nil { - return nil - } - out := new(DatadogPodAutoscalerObjective) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DatadogPodAutoscalerResourceTarget) DeepCopyInto(out *DatadogPodAutoscalerResourceTarget) { - *out = *in - in.Value.DeepCopyInto(&out.Value) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerResourceTarget. -func (in *DatadogPodAutoscalerResourceTarget) DeepCopy() *DatadogPodAutoscalerResourceTarget { - if in == nil { - return nil - } - out := new(DatadogPodAutoscalerResourceTarget) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DatadogPodAutoscalerScalingPolicy) DeepCopyInto(out *DatadogPodAutoscalerScalingPolicy) { - *out = *in - if in.Strategy != nil { - in, out := &in.Strategy, &out.Strategy - *out = new(DatadogPodAutoscalerScalingStrategySelect) - **out = **in - } - if in.Rules != nil { - in, out := &in.Rules, &out.Rules - *out = make([]DatadogPodAutoscalerScalingRule, len(*in)) - copy(*out, *in) - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerScalingPolicy. -func (in *DatadogPodAutoscalerScalingPolicy) DeepCopy() *DatadogPodAutoscalerScalingPolicy { - if in == nil { - return nil - } - out := new(DatadogPodAutoscalerScalingPolicy) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DatadogPodAutoscalerScalingRule) DeepCopyInto(out *DatadogPodAutoscalerScalingRule) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerScalingRule. -func (in *DatadogPodAutoscalerScalingRule) DeepCopy() *DatadogPodAutoscalerScalingRule { - if in == nil { - return nil - } - out := new(DatadogPodAutoscalerScalingRule) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *DatadogPodAutoscalerSpec) DeepCopyInto(out *DatadogPodAutoscalerSpec) { *out = *in @@ -411,14 +119,14 @@ func (in *DatadogPodAutoscalerSpec) DeepCopyInto(out *DatadogPodAutoscalerSpec) } if in.Objectives != nil { in, out := &in.Objectives, &out.Objectives - *out = make([]DatadogPodAutoscalerObjective, len(*in)) + *out = make([]common.DatadogPodAutoscalerObjective, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } } if in.Constraints != nil { in, out := &in.Constraints, &out.Constraints - *out = new(DatadogPodAutoscalerConstraints) + *out = new(common.DatadogPodAutoscalerConstraints) (*in).DeepCopyInto(*out) } } @@ -432,146 +140,3 @@ func (in *DatadogPodAutoscalerSpec) DeepCopy() *DatadogPodAutoscalerSpec { in.DeepCopyInto(out) return out } - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DatadogPodAutoscalerStatus) DeepCopyInto(out *DatadogPodAutoscalerStatus) { - *out = *in - if in.Vertical != nil { - in, out := &in.Vertical, &out.Vertical - *out = new(DatadogPodAutoscalerVerticalStatus) - (*in).DeepCopyInto(*out) - } - if in.Horizontal != nil { - in, out := &in.Horizontal, &out.Horizontal - *out = new(DatadogPodAutoscalerHorizontalStatus) - (*in).DeepCopyInto(*out) - } - if in.CurrentReplicas != nil { - in, out := &in.CurrentReplicas, &out.CurrentReplicas - *out = new(int32) - **out = **in - } - if in.Conditions != nil { - in, out := &in.Conditions, &out.Conditions - *out = make([]DatadogPodAutoscalerCondition, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerStatus. -func (in *DatadogPodAutoscalerStatus) DeepCopy() *DatadogPodAutoscalerStatus { - if in == nil { - return nil - } - out := new(DatadogPodAutoscalerStatus) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DatadogPodAutoscalerTargetValue) DeepCopyInto(out *DatadogPodAutoscalerTargetValue) { - *out = *in - if in.Utilization != nil { - in, out := &in.Utilization, &out.Utilization - *out = new(int32) - **out = **in - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerTargetValue. -func (in *DatadogPodAutoscalerTargetValue) DeepCopy() *DatadogPodAutoscalerTargetValue { - if in == nil { - return nil - } - out := new(DatadogPodAutoscalerTargetValue) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DatadogPodAutoscalerUpdatePolicy) DeepCopyInto(out *DatadogPodAutoscalerUpdatePolicy) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerUpdatePolicy. -func (in *DatadogPodAutoscalerUpdatePolicy) DeepCopy() *DatadogPodAutoscalerUpdatePolicy { - if in == nil { - return nil - } - out := new(DatadogPodAutoscalerUpdatePolicy) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DatadogPodAutoscalerVerticalAction) DeepCopyInto(out *DatadogPodAutoscalerVerticalAction) { - *out = *in - in.Time.DeepCopyInto(&out.Time) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerVerticalAction. -func (in *DatadogPodAutoscalerVerticalAction) DeepCopy() *DatadogPodAutoscalerVerticalAction { - if in == nil { - return nil - } - out := new(DatadogPodAutoscalerVerticalAction) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DatadogPodAutoscalerVerticalStatus) DeepCopyInto(out *DatadogPodAutoscalerVerticalStatus) { - *out = *in - if in.Target != nil { - in, out := &in.Target, &out.Target - *out = new(DatadogPodAutoscalerVerticalTargetStatus) - (*in).DeepCopyInto(*out) - } - if in.LastAction != nil { - in, out := &in.LastAction, &out.LastAction - *out = new(DatadogPodAutoscalerVerticalAction) - (*in).DeepCopyInto(*out) - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerVerticalStatus. -func (in *DatadogPodAutoscalerVerticalStatus) DeepCopy() *DatadogPodAutoscalerVerticalStatus { - if in == nil { - return nil - } - out := new(DatadogPodAutoscalerVerticalStatus) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DatadogPodAutoscalerVerticalTargetStatus) DeepCopyInto(out *DatadogPodAutoscalerVerticalTargetStatus) { - *out = *in - in.GeneratedAt.DeepCopyInto(&out.GeneratedAt) - if in.Scaled != nil { - in, out := &in.Scaled, &out.Scaled - *out = new(int32) - **out = **in - } - if in.DesiredResources != nil { - in, out := &in.DesiredResources, &out.DesiredResources - *out = make([]DatadogPodAutoscalerContainerResources, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - out.PodCPURequest = in.PodCPURequest.DeepCopy() - out.PodMemoryRequest = in.PodMemoryRequest.DeepCopy() -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DatadogPodAutoscalerVerticalTargetStatus. -func (in *DatadogPodAutoscalerVerticalTargetStatus) DeepCopy() *DatadogPodAutoscalerVerticalTargetStatus { - if in == nil { - return nil - } - out := new(DatadogPodAutoscalerVerticalTargetStatus) - in.DeepCopyInto(out) - return out -} diff --git a/config/crd/bases/v1/datadoghq.com_datadogpodautoscalers.yaml b/config/crd/bases/v1/datadoghq.com_datadogpodautoscalers.yaml index 4093e2683..a875bcbad 100644 --- a/config/crd/bases/v1/datadoghq.com_datadogpodautoscalers.yaml +++ b/config/crd/bases/v1/datadoghq.com_datadogpodautoscalers.yaml @@ -86,33 +86,11 @@ spec: items: description: |- DatadogPodAutoscalerContainerConstraints defines constraints that should always be respected for a container. - If no constraints are set, it enables resources scaling for all containers without any constraints. + If no constraints are set, it enables resource scaling for all containers without any constraints. properties: enabled: - description: Enabled false allows to disable resources autoscaling for the container. Default to true. + description: Enabled, if false, allows one to disable resource autoscaling for the container. Defaults to true. type: boolean - limits: - description: Limits defines the constraints for the limits of the container. - properties: - maxAllowed: - additionalProperties: - anyOf: - - type: integer - - type: string - pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ - x-kubernetes-int-or-string: true - description: MaxAllowed is the upper limit for the requests of the container. - type: object - minAllowed: - additionalProperties: - anyOf: - - type: integer - - type: string - pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ - x-kubernetes-int-or-string: true - description: MinAllowed is the lower limit for the requests of the container. - type: object - type: object name: description: Name is the name of the container. Can be "*" to apply to all containers. type: string @@ -147,7 +125,7 @@ spec: format: int32 type: integer minReplicas: - description: MinReplicas is the lower limit for the number of POD replicas. Needs to be >= 1. Default to 1. + description: MinReplicas is the lower limit for the number of pod replicas. Needs to be >= 1. Defaults to 1. format: int32 minimum: 1 type: integer @@ -187,16 +165,8 @@ spec: Rules is a list of potential scaling polices which can be used during scaling. At least one policy must be specified, otherwise the DatadogPodAutoscalerScalingPolicy will be discarded as invalid items: - description: DatadogPodAutoscalerScalingRule define rules for horizontal that should be true for a certain amount of time. + description: DatadogPodAutoscalerScalingRule defines rules for horizontal scaling that should be true for a certain amount of time. properties: - match: - description: |- - Match defines if the rule should be considered or not in the calculation. - Default to Always if not set. - enum: - - Always - - IfScalingEvent - type: string periodSeconds: description: |- PeriodSeconds specifies the window of time for which the policy should hold true. @@ -214,7 +184,7 @@ spec: value: description: |- Value contains the amount of change which is permitted by the policy. - Setting it to 0 will prevent any scaling in this direction and should not be used unless Match is set to IfScalingEvent. + Setting it to 0 will prevent any scaling in this direction. format: int32 minimum: 0 type: integer @@ -261,16 +231,8 @@ spec: Rules is a list of potential scaling polices which can be used during scaling. At least one policy must be specified, otherwise the DatadogPodAutoscalerScalingPolicy will be discarded as invalid items: - description: DatadogPodAutoscalerScalingRule define rules for horizontal that should be true for a certain amount of time. + description: DatadogPodAutoscalerScalingRule defines rules for horizontal scaling that should be true for a certain amount of time. properties: - match: - description: |- - Match defines if the rule should be considered or not in the calculation. - Default to Always if not set. - enum: - - Always - - IfScalingEvent - type: string periodSeconds: description: |- PeriodSeconds specifies the window of time for which the policy should hold true. @@ -288,7 +250,7 @@ spec: value: description: |- Value contains the amount of change which is permitted by the policy. - Setting it to 0 will prevent any scaling in this direction and should not be used unless Match is set to IfScalingEvent. + Setting it to 0 will prevent any scaling in this direction. format: int32 minimum: 0 type: integer @@ -345,7 +307,7 @@ spec: Targets are objectives to reach and maintain for the target resource. Default to a single target to maintain 80% POD CPU utilization. items: - description: DatadogPodAutoscalerTarget defines the objectives to reach and maintain for the target resource. + description: DatadogPodAutoscalerObjective defines the objectives to reach and maintain for the target resource. properties: containerResource: description: ContainerResource allows to set a container-level resource target. @@ -361,13 +323,6 @@ spec: value: description: Value is the value of the target. properties: - absolute: - anyOf: - - type: integer - - type: string - description: Absolute defines the absolute value of the target (for instance 500 millicores). - pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ - x-kubernetes-int-or-string: true type: description: Type specifies how the value is expressed (Absolute or Utilization). type: string @@ -386,7 +341,7 @@ spec: - value type: object podResource: - description: PodResource allows to set a POD-level resource target. + description: PodResource allows to set a pod-level resource target. properties: name: description: Name is the name of the resource. @@ -396,13 +351,6 @@ spec: value: description: Value is the value of the target. properties: - absolute: - anyOf: - - type: integer - - type: string - description: Absolute defines the absolute value of the target (for instance 500 millicores). - pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ - x-kubernetes-int-or-string: true type: description: Type specifies how the value is expressed (Absolute or Utilization). type: string @@ -456,7 +404,7 @@ spec: description: Status of the condition, one of True, False, Unknown. type: string type: - description: Type of DatadogMetric condition. + description: DatadogPodAutoscalerConditionType is the type of DatadogPodAutoscaler condition. type: string required: - status @@ -467,7 +415,7 @@ spec: - type x-kubernetes-list-type: map currentReplicas: - description: CurrentReplicas is the current number of PODs for the targetRef observed by the controller. + description: CurrentReplicas is the current number of pods for the targetRef observed by the controller. format: int32 type: integer horizontal: @@ -476,10 +424,10 @@ spec: lastActions: description: LastActions are the last successful actions done by the controller items: - description: DatadogPodAutoscalerHorizontalAction represents an horizontal action done by the controller + description: DatadogPodAutoscalerHorizontalAction represents a horizontal action done by the controller properties: limitedReason: - description: LimitedReason is the reason why the action was limited (ToReplicas != RecommendedReplicas) + description: LimitedReason is the reason why the action was limited (that is ToReplicas != RecommendedReplicas) type: string recommendedReplicas: description: RecommendedReplicas is the original number of replicas recommended by Datadog @@ -536,7 +484,7 @@ spec: description: Type is the type of action type: string version: - description: Version is the recommendation version used for the action + description: Version is the version of the recommendation used for the action type: string required: - time @@ -569,7 +517,7 @@ spec: - type: string pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ x-kubernetes-int-or-string: true - description: Requests describes target resources of compute resources allowed. + description: Requests describes the requested amount of compute resources. type: object required: - name @@ -583,18 +531,18 @@ spec: anyOf: - type: integer - type: string - description: PODCPURequest is the sum of CPU requests for all containers (used for display) + description: PodCPURequest is the sum of CPU requests for all containers (used for display) pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ x-kubernetes-int-or-string: true podMemoryRequest: anyOf: - type: integer - type: string - description: PODMemoryRequest is the sum of memory requests for all containers (used for display) + description: PodMemoryRequest is the sum of memory requests for all containers (used for display) pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ x-kubernetes-int-or-string: true scaled: - description: Scaled is the current number of PODs having desired resources + description: Scaled is the current number of pods having desired resources format: int32 type: integer source: @@ -694,7 +642,7 @@ spec: - Apply - Preview type: string - scaledown: + scaleDown: description: ScaleDown defines the policy to scale down the target resource. properties: rules: @@ -750,7 +698,7 @@ spec: - Disabled type: string type: object - scaleup: + scaleUp: description: ScaleUp defines the policy to scale up the target resource. properties: rules: @@ -892,12 +840,17 @@ spec: value: description: Value is the value of the target. properties: + type: + description: Type specifies how the value is expressed (Absolute or Utilization). + type: string utilization: description: Utilization defines a percentage of the target compared to requested resource format: int32 maximum: 100 minimum: 0 type: integer + required: + - type type: object required: - container @@ -915,12 +868,17 @@ spec: value: description: Value is the value of the target. properties: + type: + description: Type specifies how the value is expressed (Absolute or Utilization). + type: string utilization: description: Utilization defines a percentage of the target compared to requested resource format: int32 maximum: 100 minimum: 0 type: integer + required: + - type type: object required: - name diff --git a/config/crd/bases/v1/datadoghq.com_datadogpodautoscalers_v1alpha1.json b/config/crd/bases/v1/datadoghq.com_datadogpodautoscalers_v1alpha1.json index 984898c87..8581efb6a 100644 --- a/config/crd/bases/v1/datadoghq.com_datadogpodautoscalers_v1alpha1.json +++ b/config/crd/bases/v1/datadoghq.com_datadogpodautoscalers_v1alpha1.json @@ -25,77 +25,12 @@ "description": "Containers defines constraints for the containers.", "items": { "additionalProperties": false, - "description": "DatadogPodAutoscalerContainerConstraints defines constraints that should always be respected for a container.\nIf no constraints are set, it enables resources scaling for all containers without any constraints.", + "description": "DatadogPodAutoscalerContainerConstraints defines constraints that should always be respected for a container.\nIf no constraints are set, it enables resource scaling for all containers without any constraints.", "properties": { "enabled": { - "description": "Enabled false allows to disable resources autoscaling for the container. Default to true.", + "description": "Enabled, if false, allows one to disable resource autoscaling for the container. Defaults to true.", "type": "boolean" }, - "limits": { - "additionalProperties": false, - "description": "Limits defines the constraints for the limits of the container.", - "properties": { - "maxAllowed": { - "additionalProperties": false, - "description": "MaxAllowed is the upper limit for the requests of the container.", - "properties": { - "cpu": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "integer" - } - ], - "pattern": "^(\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))))?$" - }, - "memory": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "integer" - } - ], - "pattern": "^(\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))))?$" - } - }, - "type": "object" - }, - "minAllowed": { - "additionalProperties": false, - "description": "MinAllowed is the lower limit for the requests of the container.", - "properties": { - "cpu": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "integer" - } - ], - "pattern": "^(\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))))?$" - }, - "memory": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "integer" - } - ], - "pattern": "^(\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))))?$" - } - }, - "type": "object" - } - }, - "type": "object" - }, "name": { "description": "Name is the name of the container. Can be \"*\" to apply to all containers.", "type": "string" @@ -179,7 +114,7 @@ "type": "integer" }, "minReplicas": { - "description": "MinReplicas is the lower limit for the number of POD replicas. Needs to be \u003e= 1. Default to 1.", + "description": "MinReplicas is the lower limit for the number of pod replicas. Needs to be \u003e= 1. Defaults to 1.", "format": "int32", "minimum": 1, "type": "integer" @@ -221,16 +156,8 @@ "description": "Rules is a list of potential scaling polices which can be used during scaling.\nAt least one policy must be specified, otherwise the DatadogPodAutoscalerScalingPolicy will be discarded as invalid", "items": { "additionalProperties": false, - "description": "DatadogPodAutoscalerScalingRule define rules for horizontal that should be true for a certain amount of time.", + "description": "DatadogPodAutoscalerScalingRule defines rules for horizontal scaling that should be true for a certain amount of time.", "properties": { - "match": { - "description": "Match defines if the rule should be considered or not in the calculation.\nDefault to Always if not set.", - "enum": [ - "Always", - "IfScalingEvent" - ], - "type": "string" - }, "periodSeconds": { "description": "PeriodSeconds specifies the window of time for which the policy should hold true.\nPeriodSeconds must be greater than zero and less than or equal to 1800 (30 min).", "format": "int32", @@ -247,7 +174,7 @@ "type": "string" }, "value": { - "description": "Value contains the amount of change which is permitted by the policy.\nSetting it to 0 will prevent any scaling in this direction and should not be used unless Match is set to IfScalingEvent.", + "description": "Value contains the amount of change which is permitted by the policy.\nSetting it to 0 will prevent any scaling in this direction.", "format": "int32", "minimum": 0, "type": "integer" @@ -305,16 +232,8 @@ "description": "Rules is a list of potential scaling polices which can be used during scaling.\nAt least one policy must be specified, otherwise the DatadogPodAutoscalerScalingPolicy will be discarded as invalid", "items": { "additionalProperties": false, - "description": "DatadogPodAutoscalerScalingRule define rules for horizontal that should be true for a certain amount of time.", + "description": "DatadogPodAutoscalerScalingRule defines rules for horizontal scaling that should be true for a certain amount of time.", "properties": { - "match": { - "description": "Match defines if the rule should be considered or not in the calculation.\nDefault to Always if not set.", - "enum": [ - "Always", - "IfScalingEvent" - ], - "type": "string" - }, "periodSeconds": { "description": "PeriodSeconds specifies the window of time for which the policy should hold true.\nPeriodSeconds must be greater than zero and less than or equal to 1800 (30 min).", "format": "int32", @@ -331,7 +250,7 @@ "type": "string" }, "value": { - "description": "Value contains the amount of change which is permitted by the policy.\nSetting it to 0 will prevent any scaling in this direction and should not be used unless Match is set to IfScalingEvent.", + "description": "Value contains the amount of change which is permitted by the policy.\nSetting it to 0 will prevent any scaling in this direction.", "format": "int32", "minimum": 0, "type": "integer" @@ -401,7 +320,7 @@ "description": "Targets are objectives to reach and maintain for the target resource.\nDefault to a single target to maintain 80% POD CPU utilization.", "items": { "additionalProperties": false, - "description": "DatadogPodAutoscalerTarget defines the objectives to reach and maintain for the target resource.", + "description": "DatadogPodAutoscalerObjective defines the objectives to reach and maintain for the target resource.", "properties": { "containerResource": { "additionalProperties": false, @@ -422,19 +341,6 @@ "additionalProperties": false, "description": "Value is the value of the target.", "properties": { - "absolute": { - "anyOf": [ - { - "type": "integer" - }, - { - "type": "string" - } - ], - "description": "Absolute defines the absolute value of the target (for instance 500 millicores).", - "pattern": "^(\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))))?$", - "x-kubernetes-int-or-string": true - }, "type": { "description": "Type specifies how the value is expressed (Absolute or Utilization).", "type": "string" @@ -462,7 +368,7 @@ }, "podResource": { "additionalProperties": false, - "description": "PodResource allows to set a POD-level resource target.", + "description": "PodResource allows to set a pod-level resource target.", "properties": { "name": { "description": "Name is the name of the resource.", @@ -475,19 +381,6 @@ "additionalProperties": false, "description": "Value is the value of the target.", "properties": { - "absolute": { - "anyOf": [ - { - "type": "integer" - }, - { - "type": "string" - } - ], - "description": "Absolute defines the absolute value of the target (for instance 500 millicores).", - "pattern": "^(\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))))?$", - "x-kubernetes-int-or-string": true - }, "type": { "description": "Type specifies how the value is expressed (Absolute or Utilization).", "type": "string" @@ -564,7 +457,7 @@ "type": "string" }, "type": { - "description": "Type of DatadogMetric condition.", + "description": "DatadogPodAutoscalerConditionType is the type of DatadogPodAutoscaler condition.", "type": "string" } }, @@ -581,7 +474,7 @@ "x-kubernetes-list-type": "map" }, "currentReplicas": { - "description": "CurrentReplicas is the current number of PODs for the targetRef observed by the controller.", + "description": "CurrentReplicas is the current number of pods for the targetRef observed by the controller.", "format": "int32", "type": "integer" }, @@ -593,10 +486,10 @@ "description": "LastActions are the last successful actions done by the controller", "items": { "additionalProperties": false, - "description": "DatadogPodAutoscalerHorizontalAction represents an horizontal action done by the controller", + "description": "DatadogPodAutoscalerHorizontalAction represents a horizontal action done by the controller", "properties": { "limitedReason": { - "description": "LimitedReason is the reason why the action was limited (ToReplicas != RecommendedReplicas)", + "description": "LimitedReason is the reason why the action was limited (that is ToReplicas != RecommendedReplicas)", "type": "string" }, "recommendedReplicas": { @@ -675,7 +568,7 @@ "type": "string" }, "version": { - "description": "Version is the recommendation version used for the action", + "description": "Version is the version of the recommendation used for the action", "type": "string" } }, @@ -730,7 +623,7 @@ }, "requests": { "additionalProperties": false, - "description": "Requests describes target resources of compute resources allowed.", + "description": "Requests describes the requested amount of compute resources.", "properties": { "cpu": { "anyOf": [ @@ -779,7 +672,7 @@ "type": "string" } ], - "description": "PODCPURequest is the sum of CPU requests for all containers (used for display)", + "description": "PodCPURequest is the sum of CPU requests for all containers (used for display)", "pattern": "^(\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))))?$", "x-kubernetes-int-or-string": true }, @@ -792,12 +685,12 @@ "type": "string" } ], - "description": "PODMemoryRequest is the sum of memory requests for all containers (used for display)", + "description": "PodMemoryRequest is the sum of memory requests for all containers (used for display)", "pattern": "^(\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))))?$", "x-kubernetes-int-or-string": true }, "scaled": { - "description": "Scaled is the current number of PODs having desired resources", + "description": "Scaled is the current number of pods having desired resources", "format": "int32", "type": "integer" }, diff --git a/config/crd/bases/v1/datadoghq.com_datadogpodautoscalers_v1alpha2.json b/config/crd/bases/v1/datadoghq.com_datadogpodautoscalers_v1alpha2.json index 922e7b28b..04fb082b4 100644 --- a/config/crd/bases/v1/datadoghq.com_datadogpodautoscalers_v1alpha2.json +++ b/config/crd/bases/v1/datadoghq.com_datadogpodautoscalers_v1alpha2.json @@ -31,7 +31,7 @@ ], "type": "string" }, - "scaledown": { + "scaleDown": { "additionalProperties": false, "description": "ScaleDown defines the policy to scale down the target resource.", "properties": { @@ -92,7 +92,7 @@ }, "type": "object" }, - "scaleup": { + "scaleUp": { "additionalProperties": false, "description": "ScaleUp defines the policy to scale up the target resource.", "properties": { @@ -304,6 +304,10 @@ "additionalProperties": false, "description": "Value is the value of the target.", "properties": { + "type": { + "description": "Type specifies how the value is expressed (Absolute or Utilization).", + "type": "string" + }, "utilization": { "description": "Utilization defines a percentage of the target compared to requested resource", "format": "int32", @@ -312,6 +316,9 @@ "type": "integer" } }, + "required": [ + "type" + ], "type": "object" } }, @@ -337,6 +344,10 @@ "additionalProperties": false, "description": "Value is the value of the target.", "properties": { + "type": { + "description": "Type specifies how the value is expressed (Absolute or Utilization).", + "type": "string" + }, "utilization": { "description": "Utilization defines a percentage of the target compared to requested resource", "format": "int32", @@ -345,6 +356,9 @@ "type": "integer" } }, + "required": [ + "type" + ], "type": "object" } },