Skip to content

Commit

Permalink
Prevent changing dnsEndpoint name and namespace attributes in createO…
Browse files Browse the repository at this point in the history
…rUpdate

This is not permitted by controllerRuntime and should not be performed

Change-Id: I5f01e93edd2b8c48689588a871905047d4fbed8f
  • Loading branch information
Thibault Jamet committed Nov 29, 2024
1 parent fcaf4a0 commit c76cc2b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
2 changes: 0 additions & 2 deletions pkg/controllers/ingress_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,6 @@ func (r *IngressReconciler) newDnsEndpoint(ctx context.Context, dnsEndpoint *ext

setOwnerRef(dnsEndpoint, &ingress)

dnsEndpoint.Name = ingress.ObjectMeta.Name
dnsEndpoint.Namespace = ingress.ObjectMeta.Namespace
desiredWeight = uint(trafficweight.Store.DesiredWeight)
if r.isIngressWeighted(ingress) {
desiredWeight, err = r.calculateIngressWeight(ingress)
Expand Down
21 changes: 18 additions & 3 deletions pkg/controllers/ingress_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,12 @@ func TestIngressController(t *testing.T) {
}

t.Run("Should forge DNS Endpoints", func(t *testing.T) {
forged := &externaldnsk8siov1alpha1.DNSEndpoint{}
forged := &externaldnsk8siov1alpha1.DNSEndpoint{
ObjectMeta: metav1.ObjectMeta{
Name: "bar",
Namespace: "foo",
},
}
reconciler.newDnsEndpoint(context.Background(), forged, ing)
assert.Equal(t, expected, *forged)
})
Expand Down Expand Up @@ -194,7 +199,12 @@ func TestIngressController(t *testing.T) {

t.Run("if we dont set --aws-health-check-id ingress shouldnt have health property", func(t *testing.T) {
trafficweight.Store.AWSHealthCheckID = ""
forged := &externaldnsk8siov1alpha1.DNSEndpoint{}
forged := &externaldnsk8siov1alpha1.DNSEndpoint{
ObjectMeta: metav1.ObjectMeta{
Name: "bar",
Namespace: "foo",
},
}
reconciler.newDnsEndpoint(context.Background(), forged, ing)
assert.Equal(t, expected, *forged)
})
Expand Down Expand Up @@ -229,7 +239,12 @@ func TestIngressController(t *testing.T) {
},
}

forged := &externaldnsk8siov1alpha1.DNSEndpoint{}
forged := &externaldnsk8siov1alpha1.DNSEndpoint{
ObjectMeta: metav1.ObjectMeta{
Name: "bar",
Namespace: "foo",
},
}
reconciler.newDnsEndpoint(context.Background(), forged, ing)
assert.Equal(t, expected, *forged)
ing.Spec.Rules = oldRules
Expand Down

0 comments on commit c76cc2b

Please sign in to comment.