Support externalTrafficPolicy on the client Service #6

Merged
benvin merged 1 commits from benvin/svc-external-traffic-policy into main 2026-07-04 22:37:04 +10:00
5 changed files with 30 additions and 0 deletions
+7
View File
@@ -33,6 +33,13 @@ type ClusterServiceSpec struct {
// +optional
LoadBalancerIP string `json:"loadBalancerIP,omitempty"`
// ExternalTrafficPolicy for a LoadBalancer/NodePort Service. Local preserves
// client source IPs (required for source-IP ACLs on the DNS servers) but
// only routes to nodes running a pod. Defaults to Cluster.
// +kubebuilder:validation:Enum=Cluster;Local
// +optional
ExternalTrafficPolicy corev1.ServiceExternalTrafficPolicy `json:"externalTrafficPolicy,omitempty"`
// Annotations added to the client-facing Service (e.g. PureLB/MetalLB hints).
// +optional
Annotations map[string]string `json:"annotations,omitempty"`
@@ -1094,6 +1094,15 @@ spec:
description: Annotations added to the client-facing Service (e.g.
PureLB/MetalLB hints).
type: object
externalTrafficPolicy:
description: |-
ExternalTrafficPolicy for a LoadBalancer/NodePort Service. Local preserves
client source IPs (required for source-IP ACLs on the DNS servers) but
only routes to nodes running a pod. Defaults to Cluster.
enum:
- Cluster
- Local
type: string
loadBalancerIP:
description: LoadBalancerIP requests a specific address when Type
is LoadBalancer.
+9
View File
@@ -1399,6 +1399,15 @@ spec:
description: Annotations added to the client-facing Service (e.g.
PureLB/MetalLB hints).
type: object
externalTrafficPolicy:
description: |-
ExternalTrafficPolicy for a LoadBalancer/NodePort Service. Local preserves
client source IPs (required for source-IP ACLs on the DNS servers) but
only routes to nodes running a pod. Defaults to Cluster.
enum:
- Cluster
- Local
type: string
loadBalancerIP:
description: LoadBalancerIP requests a specific address when Type
is LoadBalancer.
@@ -273,6 +273,10 @@ func (r *BindClusterReconciler) reconcileServices(ctx context.Context, c *bindv1
LoadBalancerIP: c.Spec.Service.LoadBalancerIP,
},
}
// externalTrafficPolicy is only valid for LoadBalancer/NodePort Services.
if svcType == corev1.ServiceTypeLoadBalancer || svcType == corev1.ServiceTypeNodePort {
client.Spec.ExternalTrafficPolicy = c.Spec.Service.ExternalTrafficPolicy
}
return r.upsertService(ctx, c, client)
}
+1
View File
@@ -57,6 +57,7 @@ func (r *BindClusterReconciler) upsertService(ctx context.Context, c *bindv1alph
existing.Spec.Selector = desired.Spec.Selector
existing.Spec.Type = desired.Spec.Type
existing.Spec.LoadBalancerIP = desired.Spec.LoadBalancerIP
existing.Spec.ExternalTrafficPolicy = desired.Spec.ExternalTrafficPolicy
if desired.Annotations != nil {
if existing.Annotations == nil {
existing.Annotations = map[string]string{}