Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions api/v1alpha1/shared_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
10 changes: 10 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 @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 14 additions & 2 deletions internal/infrastructure/kubernetes/proxy/resource_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
},
Expand All @@ -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
Expand All @@ -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(),
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"}),
Expand Down Expand Up @@ -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"}),
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions release-notes/current.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions site/content/en/latest/api/extension_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<br />desired replica count (the maximum replica count across all metrics will<br />be used).<br />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<br />in both Up and Down directions (scaleUp and scaleDown fields respectively).<br />If not set, the default HPAScalingRules for scale up and scale down are used.<br />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.<br />When unset, this defaults to an autogenerated name. |


#### KubernetesPatchSpec
Expand Down Expand Up @@ -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,<br />such as node drains or updates. This setting ensures that your envoy proxy maintains a certain level of availability<br />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,<br />such as node drains or updates. This setting ensures that your envoy proxy maintains a certain level of availability<br />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.<br />When unset, this defaults to an autogenerated name. |


#### KubernetesPodSpec
Expand Down
10 changes: 10 additions & 0 deletions test/helm/gateway-crds-helm/all.out.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions test/helm/gateway-crds-helm/envoy-gateway-crds.out.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down