Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Annotate and Label existing DNSEndpoints #443

Merged
merged 1 commit into from
Apr 15, 2021
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
33 changes: 32 additions & 1 deletion controllers/gslb_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,14 +395,18 @@ func TestLocalDNSRecordsHasSpecialAnnotation(t *testing.T) {

// act
createHealthyService(t, &settings, serviceName)
// delete DNSEndpoint so we can pretend it wasn't annotated before
deleteDNSEndpoint(t, &settings)
createDNSEndpoint(t, &settings)
defer deleteHealthyService(t, &settings, serviceName)
defer deleteDNSEndpoint(t, &settings)
reconcileAndUpdateGslb(t, settings)
err = settings.client.Get(context.TODO(), settings.request.NamespacedName, dnsEndpoint)
require.NoError(t, err, "Failed to load DNS endpoint")
got := dnsEndpoint.Annotations["k8gb.absa.oss/dnstype"]

// assert
assert.Equal(t, got, want, "got:\n %q annotation value,\n\n want:\n %q", got, want, got, want)
assert.Equal(t, want, got, "got:\n %q annotation value,\n\n want:\n %q", got, want)
}

func TestCanGetExternalTargetsFromK8gbInAnotherLocation(t *testing.T) {
Expand Down Expand Up @@ -1081,6 +1085,33 @@ func deleteUnhealthyService(t *testing.T, s *testSettings, serviceName string) {
}

}
func createDNSEndpoint(t *testing.T, s *testSettings) {
t.Helper()
dnsEndpoint := &externaldns.DNSEndpoint{
ObjectMeta: metav1.ObjectMeta{
Name: s.gslb.Name,
Namespace: s.gslb.Namespace,
},
}
err := s.client.Create(context.TODO(), dnsEndpoint)
if err != nil {
t.Fatalf("Failed to create testing DNSEndpoint: (%v)", err)
}
}

func deleteDNSEndpoint(t *testing.T, s *testSettings) {
t.Helper()
endpoint := &externaldns.DNSEndpoint{
ObjectMeta: metav1.ObjectMeta{
Name: s.gslb.Name,
Namespace: s.gslb.Namespace,
},
}
err := s.client.Delete(context.TODO(), endpoint)
if err != nil {
t.Fatalf("Failed to delete testing DNSEndpoint: (%v)", err)
}
}

func reconcileAndUpdateGslb(t *testing.T, s testSettings) {
t.Helper()
Expand Down
4 changes: 3 additions & 1 deletion controllers/providers/assistant/gslb.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,10 @@ func (r *GslbLoggerAssistant) SaveDNSEndpoint(namespace string, i *externaldns.D
return err
}

// Update existing object with new spec
// Update existing object with new spec, labels and annotations
found.Spec = i.Spec
found.ObjectMeta.Annotations = i.ObjectMeta.Annotations
found.ObjectMeta.Labels = i.ObjectMeta.Labels
err = r.client.Update(context.TODO(), found)

if err != nil {
Expand Down