Skip to content

Commit 12a1259

Browse files
committed
Add annotation to disable patching of loadbalancer services.
1 parent 7a6aaa1 commit 12a1259

3 files changed

Lines changed: 25 additions & 17 deletions

File tree

docs/usage/ipv6.md

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ When creating a load balancer, the corresponding annotations need to be configur
8585

8686
The AWS Load Balancer Controller allows dual-stack ingress so that an IPv6-only shoot cluster can serve IPv4 and IPv6 clients.
8787
You can find an example [here](dual-stack-ingress.md#creating-an-ipv4ipv6-dual-stack-ingress).
88+
A mutating webhook will automatically add the required annotations. To disable this automated behavior, use the annotation `extensions.gardener.cloud/ignore-load-balancer: "true"`.
8889
8990
> [!WARNING]
9091
> When accessing Network Load Balancers (NLB) from within the same IPv6-only cluster, it is crucial to add the annotation `service.beta.kubernetes.io/aws-load-balancer-target-group-attributes: preserve_client_ip.enabled=false`.
@@ -176,19 +177,3 @@ You can find more information about the process and the steps required [here](ht
176177
> [!WARNING]
177178
> Please note that the dual-stack migration requires the IPv4-only cluster to run in native routing mode, i.e. pod overlay network needs to be disabled.
178179
> The default quota of routes per route table in AWS is 50. This restricts the cluster size to about 50 nodes. Therefore, please adapt (if necessary) the routes per route table limit in the Amazon Virtual Private Cloud quotas accordingly before switching to native routing. The maximum setting is currently 1000.
179-
180-
### Load Balancer Configuration
181-
182-
The AWS Load Balancer Controller is automatically deployed when using a dual-stack shoot cluster.
183-
When creating a load balancer, the corresponding annotations need to be configured, see [AWS Load Balancer Documentation - Network Load Balancer](https://kubernetes-sigs.github.io/aws-load-balancer-controller/latest/guide/service/nlb/) for details.
184-
185-
> [!WARNING]
186-
> Please note that load balancer services without any special annotations will default to IPv4-only regardless how `.spec.ipFamilies` is set.
187-
188-
The AWS Load Balancer Controller allows dual-stack ingress so that a dual-stack shoot cluster can serve IPv4 and IPv6 clients.
189-
You can find an example [here](dual-stack-ingress.md#creating-an-ipv4ipv6-dual-stack-ingress).
190-
191-
> [!WARNING]
192-
> When accessing external Network Load Balancers (NLB) from within the same cluster via IPv6 or internal NLBs via IPv4, it is crucial to add the annotation `service.beta.kubernetes.io/aws-load-balancer-target-group-attributes: preserve_client_ip.enabled=false`.
193-
> Without this annotation, if a request is routed by the NLB to the same target instance from which it originated, the client IP and destination IP will be identical.
194-
> This situation, known as the hair-pinning effect, will prevent the request from being processed.

pkg/webhook/shootservice/mutator.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ func (m *mutator) Mutate(ctx context.Context, newObj, _ client.Object) error {
6363
if metav1.HasAnnotation(service.ObjectMeta, "service.beta.kubernetes.io/aws-load-balancer-scheme") &&
6464
service.Annotations["service.beta.kubernetes.io/aws-load-balancer-scheme"] == "internal" ||
6565
metav1.HasAnnotation(service.ObjectMeta, "service.beta.kubernetes.io/aws-load-balancer-internal") &&
66-
service.Annotations["service.beta.kubernetes.io/aws-load-balancer-internal"] == "true" {
66+
service.Annotations["service.beta.kubernetes.io/aws-load-balancer-internal"] == "true" ||
67+
metav1.HasAnnotation(service.ObjectMeta, "extensions.gardener.cloud/ignore-load-balancer") &&
68+
service.Annotations["extensions.gardener.cloud/ignore-load-balancer"] == "true" {
6769
return nil
6870
}
6971

pkg/webhook/shootservice/mutator_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,27 @@ var _ = Describe("Mutator", func() {
106106

107107
Entry("no data", &corev1.Service{ObjectMeta: loadBalancerServiceMapMeta, Spec: corev1.ServiceSpec{Type: corev1.ServiceTypeLoadBalancer, IPFamilies: []corev1.IPFamily{corev1.IPv4Protocol, corev1.IPv6Protocol}}}),
108108
)
109+
110+
DescribeTable("#Mutate",
111+
func(service *corev1.Service) {
112+
metav1.SetMetaDataAnnotation(&service.ObjectMeta, "extensions.gardener.cloud/ignore-load-balancer", "true")
113+
Expect(fakeShootClient.Patch(context.TODO(), &corev1.Service{
114+
ObjectMeta: metav1.ObjectMeta{Name: "kube-dns", Namespace: "kube-system"},
115+
Spec: corev1.ServiceSpec{
116+
IPFamilies: []corev1.IPFamily{corev1.IPv4Protocol},
117+
},
118+
}, client.MergeFrom(&corev1.Service{ObjectMeta: metav1.ObjectMeta{Name: "kube-dns", Namespace: "kube-system"}}))).To(Succeed())
119+
err := mutator.Mutate(ctxWithClient, service, nil)
120+
Expect(err).To(Not(HaveOccurred()))
121+
Expect(service.Annotations).ToNot(HaveKeyWithValue("service.beta.kubernetes.io/aws-load-balancer-ip-address-type", "dualstack"))
122+
Expect(service.Annotations).ToNot(HaveKeyWithValue("service.beta.kubernetes.io/aws-load-balancer-scheme", "internet-facing"))
123+
Expect(service.Annotations).ToNot(HaveKeyWithValue("service.beta.kubernetes.io/aws-load-balancer-nlb-target-type", "instance"))
124+
Expect(service.Annotations).ToNot(HaveKeyWithValue("service.beta.kubernetes.io/aws-load-balancer-type", "external"))
125+
},
126+
127+
Entry("no data", &corev1.Service{ObjectMeta: loadBalancerServiceMapMeta, Spec: corev1.ServiceSpec{Type: corev1.ServiceTypeLoadBalancer, IPFamilies: []corev1.IPFamily{corev1.IPv4Protocol, corev1.IPv6Protocol}}}),
128+
)
129+
109130
It("should return error if resource is not a Service", func() {
110131
err := mutator.Mutate(ctxWithClient, &corev1.ConfigMap{}, nil)
111132
Expect(err).To(HaveOccurred())

0 commit comments

Comments
 (0)