diff --git a/api/v1alpha1/shared_types.go b/api/v1alpha1/shared_types.go index 34d02959ff..16af4dd151 100644 --- a/api/v1alpha1/shared_types.go +++ b/api/v1alpha1/shared_types.go @@ -446,6 +446,12 @@ type KubernetesPodDisruptionBudgetSpec struct { // // +optional Patch *KubernetesPatchSpec `json:"patch,omitempty"` + + // Name of the podDisruptionBudget. + // When unset, this defaults to an autogenerated name. + // + // +optional + Name *string `json:"name,omitempty"` } // KubernetesHorizontalPodAutoscalerSpec defines Kubernetes Horizontal Pod Autoscaler settings of Envoy Proxy Deployment. @@ -488,6 +494,12 @@ type KubernetesHorizontalPodAutoscalerSpec struct { // // +optional Patch *KubernetesPatchSpec `json:"patch,omitempty"` + + // Name of the horizontalPodAutoScaler. + // When unset, this defaults to an autogenerated name. + // + // +optional + Name *string `json:"name,omitempty"` } // HTTPStatus defines the http status code. diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index bbab5dbf83..8669528496 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -4068,6 +4068,11 @@ func (in *KubernetesHorizontalPodAutoscalerSpec) DeepCopyInto(out *KubernetesHor *out = new(KubernetesPatchSpec) (*in).DeepCopyInto(*out) } + if in.Name != nil { + in, out := &in.Name, &out.Name + *out = new(string) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KubernetesHorizontalPodAutoscalerSpec. @@ -4119,6 +4124,11 @@ func (in *KubernetesPodDisruptionBudgetSpec) DeepCopyInto(out *KubernetesPodDisr *out = new(KubernetesPatchSpec) (*in).DeepCopyInto(*out) } + if in.Name != nil { + in, out := &in.Name, &out.Name + *out = new(string) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KubernetesPodDisruptionBudgetSpec. diff --git a/charts/gateway-crds-helm/templates/generated/gateway.envoyproxy.io_envoyproxies.yaml b/charts/gateway-crds-helm/templates/generated/gateway.envoyproxy.io_envoyproxies.yaml index 7378d02115..d49134caa3 100644 --- a/charts/gateway-crds-helm/templates/generated/gateway.envoyproxy.io_envoyproxies.yaml +++ b/charts/gateway-crds-helm/templates/generated/gateway.envoyproxy.io_envoyproxies.yaml @@ -10236,6 +10236,11 @@ spec: x-kubernetes-validations: - message: minReplicas must be greater than 0 rule: self > 0 + name: + description: |- + Name of the horizontalPodAutoScaler. + When unset, this defaults to an autogenerated name. + type: string patch: description: Patch defines how to perform the patch operation to the HorizontalPodAutoscaler @@ -10281,6 +10286,11 @@ spec: such as node drains or updates. This setting ensures that your envoy proxy maintains a certain level of availability and resilience during maintenance operations. Cannot be combined with maxUnavailable. x-kubernetes-int-or-string: true + name: + description: |- + Name of the podDisruptionBudget. + When unset, this defaults to an autogenerated name. + type: string patch: description: Patch defines how to perform the patch operation to the PodDisruptionBudget 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 d33c04841a..e72e7216ff 100644 --- a/charts/gateway-helm/crds/generated/gateway.envoyproxy.io_envoyproxies.yaml +++ b/charts/gateway-helm/crds/generated/gateway.envoyproxy.io_envoyproxies.yaml @@ -10235,6 +10235,11 @@ spec: x-kubernetes-validations: - message: minReplicas must be greater than 0 rule: self > 0 + name: + description: |- + Name of the horizontalPodAutoScaler. + When unset, this defaults to an autogenerated name. + type: string patch: description: Patch defines how to perform the patch operation to the HorizontalPodAutoscaler @@ -10280,6 +10285,11 @@ spec: such as node drains or updates. This setting ensures that your envoy proxy maintains a certain level of availability and resilience during maintenance operations. Cannot be combined with maxUnavailable. x-kubernetes-int-or-string: true + name: + description: |- + Name of the podDisruptionBudget. + When unset, this defaults to an autogenerated name. + type: string patch: description: Patch defines how to perform the patch operation to the PodDisruptionBudget diff --git a/internal/infrastructure/kubernetes/proxy/resource_provider.go b/internal/infrastructure/kubernetes/proxy/resource_provider.go index edf2fee2bd..2f82aeeee7 100644 --- a/internal/infrastructure/kubernetes/proxy/resource_provider.go +++ b/internal/infrastructure/kubernetes/proxy/resource_provider.go @@ -531,7 +531,6 @@ func (r *ResourceRender) PodDisruptionBudget() (*policyv1.PodDisruptionBudget, e podDisruptionBudget := &policyv1.PodDisruptionBudget{ ObjectMeta: metav1.ObjectMeta{ - Name: r.Name(), Namespace: r.Namespace(), OwnerReferences: r.OwnerReferences(), }, @@ -542,6 +541,13 @@ func (r *ResourceRender) PodDisruptionBudget() (*policyv1.PodDisruptionBudget, e Spec: pdbSpec, } + // set name + if pdb.Name != nil { + podDisruptionBudget.Name = *pdb.Name + } else { + podDisruptionBudget.Name = r.Name() + } + // apply merge patch to PodDisruptionBudget if podDisruptionBudget, err = pdb.ApplyMergePatch(podDisruptionBudget); err != nil { return nil, err @@ -568,7 +574,6 @@ func (r *ResourceRender) HorizontalPodAutoscaler() (*autoscalingv2.HorizontalPod }, ObjectMeta: metav1.ObjectMeta{ Namespace: r.Namespace(), - Name: r.Name(), Annotations: r.infra.GetProxyMetadata().Annotations, Labels: r.infra.GetProxyMetadata().Labels, OwnerReferences: r.OwnerReferences(), @@ -593,6 +598,13 @@ func (r *ResourceRender) HorizontalPodAutoscaler() (*autoscalingv2.HorizontalPod hpa.Spec.ScaleTargetRef.Name = r.Name() } + // set name + if hpaConfig.Name != nil { + hpa.Name = *hpaConfig.Name + } else { + hpa.Name = r.Name() + } + var err error if hpa, err = utils.MergeWithPatch(hpa, hpaConfig.Patch); err != nil { return nil, err diff --git a/internal/infrastructure/kubernetes/proxy/resource_provider_test.go b/internal/infrastructure/kubernetes/proxy/resource_provider_test.go index 6e949c34c8..843712a966 100644 --- a/internal/infrastructure/kubernetes/proxy/resource_provider_test.go +++ b/internal/infrastructure/kubernetes/proxy/resource_provider_test.go @@ -1564,6 +1564,14 @@ func TestPDB(t *testing.T) { }, }, }, + { + caseName: "with-name", + infra: newTestInfra(), + pdb: &egv1a1.KubernetesPodDisruptionBudgetSpec{ + MinAvailable: ptr.To(intstr.IntOrString{Type: intstr.Int, IntVal: 1}), + Name: ptr.To("custom-pdb-name"), + }, + }, { caseName: "gateway-namespace-mode", infra: newTestInfraWithNamespacedName(types.NamespacedName{Namespace: "ns1", Name: "gateway-1"}), @@ -1706,6 +1714,14 @@ func TestHorizontalPodAutoscaler(t *testing.T) { Name: ptr.To("custom-deployment-name"), }, }, + { + caseName: "with-name", + infra: newTestInfra(), + hpa: &egv1a1.KubernetesHorizontalPodAutoscalerSpec{ + MaxReplicas: ptr.To[int32](1), + Name: ptr.To("custom-hpa-name"), + }, + }, { caseName: "gateway-namespace-mode", infra: newTestInfraWithNamespacedName(types.NamespacedName{Namespace: "ns1", Name: "gateway-1"}), diff --git a/internal/infrastructure/kubernetes/proxy/testdata/hpa/with-name.yaml b/internal/infrastructure/kubernetes/proxy/testdata/hpa/with-name.yaml new file mode 100644 index 0000000000..f4cae20bb8 --- /dev/null +++ b/internal/infrastructure/kubernetes/proxy/testdata/hpa/with-name.yaml @@ -0,0 +1,30 @@ +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + creationTimestamp: null + labels: + gateway.envoyproxy.io/owning-gateway-name: default + gateway.envoyproxy.io/owning-gateway-namespace: default + name: custom-hpa-name + namespace: envoy-gateway-system + ownerReferences: + - apiVersion: gateway.networking.k8s.io/v1 + kind: GatewayClass + name: envoy-gateway-class + uid: test-owner-reference-uid-for-gatewayclass +spec: + maxReplicas: 1 + metrics: + - resource: + name: cpu + target: + averageUtilization: 80 + type: Utilization + type: Resource + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: envoy-default-37a8eec1 +status: + currentMetrics: null + desiredReplicas: 0 diff --git a/internal/infrastructure/kubernetes/proxy/testdata/pdb/with-name.yaml b/internal/infrastructure/kubernetes/proxy/testdata/pdb/with-name.yaml new file mode 100644 index 0000000000..7eef80fd20 --- /dev/null +++ b/internal/infrastructure/kubernetes/proxy/testdata/pdb/with-name.yaml @@ -0,0 +1,25 @@ +apiVersion: policy/v1 +kind: PodDisruptionBudget +metadata: + creationTimestamp: null + name: custom-pdb-name + namespace: envoy-gateway-system + ownerReferences: + - apiVersion: gateway.networking.k8s.io/v1 + kind: GatewayClass + name: envoy-gateway-class + uid: test-owner-reference-uid-for-gatewayclass +spec: + minAvailable: 1 + selector: + matchLabels: + app.kubernetes.io/component: proxy + app.kubernetes.io/managed-by: envoy-gateway + app.kubernetes.io/name: envoy + gateway.envoyproxy.io/owning-gateway-name: default + gateway.envoyproxy.io/owning-gateway-namespace: default +status: + currentHealthy: 0 + desiredHealthy: 0 + disruptionsAllowed: 0 + expectedPods: 0 diff --git a/internal/infrastructure/kubernetes/ratelimit/resource_provider.go b/internal/infrastructure/kubernetes/ratelimit/resource_provider.go index 9013127e0f..3aaf6d0bea 100644 --- a/internal/infrastructure/kubernetes/ratelimit/resource_provider.go +++ b/internal/infrastructure/kubernetes/ratelimit/resource_provider.go @@ -341,6 +341,13 @@ func (r *ResourceRender) HorizontalPodAutoscaler() (*autoscalingv2.HorizontalPod hpa.Spec.ScaleTargetRef.Name = r.Name() } + // set name + if hpaConfig.Name != nil { + hpa.Name = *hpaConfig.Name + } else { + hpa.Name = r.Name() + } + if hpa, err = utils.MergeWithPatch(hpa, hpaConfig.Patch); err != nil { return nil, err } diff --git a/internal/infrastructure/kubernetes/ratelimit/resource_provider_test.go b/internal/infrastructure/kubernetes/ratelimit/resource_provider_test.go index f6b9b3a914..3cda63b971 100644 --- a/internal/infrastructure/kubernetes/ratelimit/resource_provider_test.go +++ b/internal/infrastructure/kubernetes/ratelimit/resource_provider_test.go @@ -868,6 +868,20 @@ func TestHorizontalPodAutoscaler(t *testing.T) { Name: ptr.To("foo"), }, }, + { + caseName: "with-name", + rateLimit: &egv1a1.RateLimit{ + Backend: egv1a1.RateLimitDatabaseBackend{ + Type: egv1a1.RedisBackendType, + Redis: &egv1a1.RateLimitRedisSettings{ + URL: "redis.redis.svc:6379", + }, + }, + }, + rateLimitHpa: &egv1a1.KubernetesHorizontalPodAutoscalerSpec{ + Name: ptr.To("custom-hpa-name"), + }, + }, } for _, tc := range cases { t.Run(tc.caseName, func(t *testing.T) { diff --git a/internal/infrastructure/kubernetes/ratelimit/testdata/hpa/with-name.yaml b/internal/infrastructure/kubernetes/ratelimit/testdata/hpa/with-name.yaml new file mode 100644 index 0000000000..9ab0e264be --- /dev/null +++ b/internal/infrastructure/kubernetes/ratelimit/testdata/hpa/with-name.yaml @@ -0,0 +1,26 @@ +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + creationTimestamp: null + labels: + app.kubernetes.io/component: ratelimit + app.kubernetes.io/managed-by: envoy-gateway + app.kubernetes.io/name: envoy-ratelimit + name: custom-hpa-name + namespace: envoy-gateway-system +spec: + maxReplicas: 1 + metrics: + - resource: + name: cpu + target: + averageUtilization: 80 + type: Utilization + type: Resource + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: envoy-ratelimit +status: + currentMetrics: null + desiredReplicas: 0 diff --git a/release-notes/current.yaml b/release-notes/current.yaml index d0648effbd..431d6df99c 100644 --- a/release-notes/current.yaml +++ b/release-notes/current.yaml @@ -22,6 +22,7 @@ new features: | Added support for using extension server policies to in PostTranslateModify hook. Added support for configuring cluster stat name for HTTPRoute and GRPCRoute in EnvoyProxy CRD. Added support for configuring the cache sync period for K8s provider. + Added support for configuring user provided name to generated HorizontalPodAutoscaler and PodDisruptionBudget resources. bug fixes: | Handle integer zone annotation values diff --git a/site/content/en/latest/api/extension_types.md b/site/content/en/latest/api/extension_types.md index 8f32a1a527..ed9fbc2f58 100644 --- a/site/content/en/latest/api/extension_types.md +++ b/site/content/en/latest/api/extension_types.md @@ -2859,6 +2859,7 @@ _Appears in:_ | `metrics` | _[MetricSpec](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.29/#metricspec-v2-autoscaling) array_ | false | | metrics contains the specifications for which to use to calculate the
desired replica count (the maximum replica count across all metrics will
be used).
If left empty, it defaults to being based on CPU utilization with average on 80% usage. | | `behavior` | _[HorizontalPodAutoscalerBehavior](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.29/#horizontalpodautoscalerbehavior-v2-autoscaling)_ | false | | behavior configures the scaling behavior of the target
in both Up and Down directions (scaleUp and scaleDown fields respectively).
If not set, the default HPAScalingRules for scale up and scale down are used.
See k8s.io.autoscaling.v2.HorizontalPodAutoScalerBehavior. | | `patch` | _[KubernetesPatchSpec](#kubernetespatchspec)_ | false | | Patch defines how to perform the patch operation to the HorizontalPodAutoscaler | +| `name` | _string_ | false | | Name of the horizontalPodAutoScaler.
When unset, this defaults to an autogenerated name. | #### KubernetesPatchSpec @@ -2896,6 +2897,7 @@ _Appears in:_ | `minAvailable` | _[IntOrString](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.29/#intorstring-intstr-util)_ | false | | MinAvailable specifies the minimum amount of pods (can be expressed as integers or as a percentage) that must be available at all times during voluntary disruptions,
such as node drains or updates. This setting ensures that your envoy proxy maintains a certain level of availability
and resilience during maintenance operations. Cannot be combined with maxUnavailable. | | `maxUnavailable` | _[IntOrString](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.29/#intorstring-intstr-util)_ | false | | MaxUnavailable specifies the maximum amount of pods (can be expressed as integers or as a percentage) that can be unavailable at all times during voluntary disruptions,
such as node drains or updates. This setting ensures that your envoy proxy maintains a certain level of availability
and resilience during maintenance operations. Cannot be combined with minAvailable. | | `patch` | _[KubernetesPatchSpec](#kubernetespatchspec)_ | false | | Patch defines how to perform the patch operation to the PodDisruptionBudget | +| `name` | _string_ | false | | Name of the podDisruptionBudget.
When unset, this defaults to an autogenerated name. | #### KubernetesPodSpec diff --git a/test/helm/gateway-crds-helm/all.out.yaml b/test/helm/gateway-crds-helm/all.out.yaml index 85d865a3a3..423d51f43a 100644 --- a/test/helm/gateway-crds-helm/all.out.yaml +++ b/test/helm/gateway-crds-helm/all.out.yaml @@ -33801,6 +33801,11 @@ spec: x-kubernetes-validations: - message: minReplicas must be greater than 0 rule: self > 0 + name: + description: |- + Name of the horizontalPodAutoScaler. + When unset, this defaults to an autogenerated name. + type: string patch: description: Patch defines how to perform the patch operation to the HorizontalPodAutoscaler @@ -33846,6 +33851,11 @@ spec: such as node drains or updates. This setting ensures that your envoy proxy maintains a certain level of availability and resilience during maintenance operations. Cannot be combined with maxUnavailable. x-kubernetes-int-or-string: true + name: + description: |- + Name of the podDisruptionBudget. + When unset, this defaults to an autogenerated name. + type: string patch: description: Patch defines how to perform the patch operation to the PodDisruptionBudget diff --git a/test/helm/gateway-crds-helm/envoy-gateway-crds.out.yaml b/test/helm/gateway-crds-helm/envoy-gateway-crds.out.yaml index 837a258bf2..d24bf7a201 100644 --- a/test/helm/gateway-crds-helm/envoy-gateway-crds.out.yaml +++ b/test/helm/gateway-crds-helm/envoy-gateway-crds.out.yaml @@ -16489,6 +16489,11 @@ spec: x-kubernetes-validations: - message: minReplicas must be greater than 0 rule: self > 0 + name: + description: |- + Name of the horizontalPodAutoScaler. + When unset, this defaults to an autogenerated name. + type: string patch: description: Patch defines how to perform the patch operation to the HorizontalPodAutoscaler @@ -16534,6 +16539,11 @@ spec: such as node drains or updates. This setting ensures that your envoy proxy maintains a certain level of availability and resilience during maintenance operations. Cannot be combined with maxUnavailable. x-kubernetes-int-or-string: true + name: + description: |- + Name of the podDisruptionBudget. + When unset, this defaults to an autogenerated name. + type: string patch: description: Patch defines how to perform the patch operation to the PodDisruptionBudget