diff --git a/api/v1alpha1/envoyproxy_types.go b/api/v1alpha1/envoyproxy_types.go index 9fcc6584b6b..e11da79d850 100644 --- a/api/v1alpha1/envoyproxy_types.go +++ b/api/v1alpha1/envoyproxy_types.go @@ -132,7 +132,8 @@ type EnvoyProxyKubernetesProvider struct { // Once the HPA is being set, Replicas field from EnvoyDeployment will be ignored. // // +optional - // +kubebuilder:validation:XValidation:message="maxReplicas must be greater than 0",rule="self.maxReplicas > 0" + // +kubebuilder:validation:XValidation:message="minReplicas must be greater than 0",rule="!has(self.minReplicas) || self.minReplicas > 0" + // +kubebuilder:validation:XValidation:message="maxReplicas must be greater than 0",rule="!has(self.maxReplicas) || self.maxReplicas > 0" // +kubebuilder:validation:XValidation:message="maxReplicas cannot be less than minReplicas",rule="!has(self.minReplicas) || self.maxReplicas >= self.minReplicas" EnvoyHpa *KubernetesHorizontalPodAutoscalerSpec `json:"envoyHpa,omitempty"` } diff --git a/api/v1alpha1/kubernetes_helpers.go b/api/v1alpha1/kubernetes_helpers.go index 5a4dd43e7d9..90c75873cbb 100644 --- a/api/v1alpha1/kubernetes_helpers.go +++ b/api/v1alpha1/kubernetes_helpers.go @@ -108,10 +108,6 @@ func (deployment *KubernetesDeploymentSpec) defaultKubernetesDeploymentSpec(imag } func (hpa *KubernetesHorizontalPodAutoscalerSpec) setDefault() { - if hpa.MaxReplicas == 0 { - hpa.MaxReplicas = 1 - } - if len(hpa.Metrics) == 0 { hpa.Metrics = DefaultEnvoyProxyHpaMetrics() } diff --git a/api/v1alpha1/shared_types.go b/api/v1alpha1/shared_types.go index 17bc7f2bf62..bcc406dba69 100644 --- a/api/v1alpha1/shared_types.go +++ b/api/v1alpha1/shared_types.go @@ -291,8 +291,7 @@ type KubernetesHorizontalPodAutoscalerSpec struct { // See k8s.io.autoscaling.v2.HorizontalPodAutoScalerSpec // // +optional - // +kubebuilder:default=1 - MaxReplicas int32 `json:"maxReplicas,omitempty"` + MaxReplicas *int32 `json:"maxReplicas,omitempty"` // metrics contains the specifications for which to use to calculate the // desired replica count (the maximum replica count across all metrics will diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 99f5c0866f2..2654e070a27 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -1442,6 +1442,11 @@ func (in *KubernetesHorizontalPodAutoscalerSpec) DeepCopyInto(out *KubernetesHor *out = new(int32) **out = **in } + if in.MaxReplicas != nil { + in, out := &in.MaxReplicas, &out.MaxReplicas + *out = new(int32) + **out = **in + } if in.Metrics != nil { in, out := &in.Metrics, &out.Metrics *out = make([]v2.MetricSpec, len(*in)) diff --git a/charts/gateway-helm/crds/generated/gateway.envoyproxy.io_envoyproxies.yaml b/charts/gateway-helm/crds/generated/gateway.envoyproxy.io_envoyproxies.yaml index b4d04d7291e..d0bd299aacc 100644 --- a/charts/gateway-helm/crds/generated/gateway.envoyproxy.io_envoyproxies.yaml +++ b/charts/gateway-helm/crds/generated/gateway.envoyproxy.io_envoyproxies.yaml @@ -5364,7 +5364,6 @@ spec: type: object type: object maxReplicas: - default: 1 description: maxReplicas is the upper limit for the number of replicas to which the autoscaler can scale up. It cannot be less that minReplicas. It defaults to 1 replica. @@ -5908,8 +5907,10 @@ spec: type: integer type: object x-kubernetes-validations: + - message: minReplicas must be greater than 0 + rule: '!has(self.minReplicas) || self.minReplicas > 0' - message: maxReplicas must be greater than 0 - rule: self.maxReplicas > 0 + rule: '!has(self.maxReplicas) || self.maxReplicas > 0' - message: maxReplicas cannot be less than minReplicas rule: '!has(self.minReplicas) || self.maxReplicas >= self.minReplicas' envoyService: diff --git a/internal/infrastructure/kubernetes/proxy/resource_provider.go b/internal/infrastructure/kubernetes/proxy/resource_provider.go index f463b1088b3..6ab47c0b334 100644 --- a/internal/infrastructure/kubernetes/proxy/resource_provider.go +++ b/internal/infrastructure/kubernetes/proxy/resource_provider.go @@ -16,6 +16,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" "k8s.io/utils/pointer" + "k8s.io/utils/ptr" egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1" "github.com/envoyproxy/gateway/internal/gatewayapi" @@ -260,7 +261,7 @@ func (r *ResourceRender) HorizontalPodAutoscaler() (*autoscalingv2.HorizontalPod Name: r.Name(), }, MinReplicas: hpaConfig.MinReplicas, - MaxReplicas: hpaConfig.MaxReplicas, + MaxReplicas: ptr.Deref[int32](hpaConfig.MaxReplicas, 1), Metrics: hpaConfig.Metrics, Behavior: hpaConfig.Behavior, }, diff --git a/internal/infrastructure/kubernetes/proxy/resource_provider_test.go b/internal/infrastructure/kubernetes/proxy/resource_provider_test.go index 6f5c33833af..f1b295475f8 100644 --- a/internal/infrastructure/kubernetes/proxy/resource_provider_test.go +++ b/internal/infrastructure/kubernetes/proxy/resource_provider_test.go @@ -530,7 +530,7 @@ func TestHorizontalPodAutoscaler(t *testing.T) { infra: newTestInfra(), hpa: &egv1a1.KubernetesHorizontalPodAutoscalerSpec{ MinReplicas: ptr.To[int32](5), - MaxReplicas: 10, + MaxReplicas: ptr.To[int32](10), Metrics: []autoscalingv2.MetricSpec{ { Resource: &autoscalingv2.ResourceMetricSource{