Skip to content

Commit

Permalink
chore: change maxReplicas with pointer
Browse files Browse the repository at this point in the history
Signed-off-by: Ardika Bagus <[email protected]>
  • Loading branch information
ardikabs committed Dec 6, 2023
1 parent b1a9fcd commit d4d16f5
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 11 deletions.
3 changes: 2 additions & 1 deletion api/v1alpha1/envoyproxy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand Down
4 changes: 0 additions & 4 deletions api/v1alpha1/kubernetes_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
3 changes: 1 addition & 2 deletions api/v1alpha1/shared_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit d4d16f5

Please sign in to comment.