diff --git a/provider/webhook/webhook_test.go b/provider/webhook/webhook_test.go index 03b02c20f..ca36e38b8 100644 --- a/provider/webhook/webhook_test.go +++ b/provider/webhook/webhook_test.go @@ -26,6 +26,7 @@ import ( "github.com/stretchr/testify/require" "sigs.k8s.io/external-dns/endpoint" + "sigs.k8s.io/external-dns/plan" "sigs.k8s.io/external-dns/provider" webhookapi "sigs.k8s.io/external-dns/provider/webhook/api" ) @@ -217,3 +218,56 @@ func TestAdjustendpointsWithError(t *testing.T) { require.Error(t, err) require.ErrorIs(t, err, provider.SoftError) } + +// test apply changes with an endpoint with a provider specific property +func TestApplyChangesWithProviderSpecificProperty(t *testing.T) { + svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.URL.Path == "/" { + w.Header().Set(webhookapi.ContentTypeHeader, webhookapi.MediaTypeFormatAndVersion) + w.Write([]byte(`{}`)) + return + } + if r.URL.Path == "/records" { + w.Header().Set(webhookapi.ContentTypeHeader, webhookapi.MediaTypeFormatAndVersion) + // assert that the request contains the provider specific property + var changes plan.Changes + defer r.Body.Close() + b, err := io.ReadAll(r.Body) + if err != nil { + t.Fatal(err) + } + err = json.Unmarshal(b, &changes) + require.Nil(t, err) + require.Len(t, changes.Create, 1) + require.Len(t, changes.Create[0].ProviderSpecific, 1) + require.Equal(t, "prop1", changes.Create[0].ProviderSpecific[0].Name) + require.Equal(t, "value1", changes.Create[0].ProviderSpecific[0].Value) + w.WriteHeader(http.StatusNoContent) + return + } + })) + defer svr.Close() + + p, err := NewWebhookProvider(svr.URL) + require.NoError(t, err) + e := &endpoint.Endpoint{ + DNSName: "test.example.com", + RecordTTL: 10, + RecordType: "A", + Targets: endpoint.Targets{ + "", + }, + ProviderSpecific: endpoint.ProviderSpecific{ + endpoint.ProviderSpecificProperty{ + Name: "prop1", + Value: "value1", + }, + }, + } + err = p.ApplyChanges(context.TODO(), &plan.Changes{ + Create: []*endpoint.Endpoint{ + e, + }, + }) + require.NoError(t, err) +} diff --git a/source/source.go b/source/source.go index 149892853..132f40dcd 100644 --- a/source/source.go +++ b/source/source.go @@ -60,8 +60,6 @@ const ( controllerAnnotationValue = "dns-controller" // The annotation used for defining the desired hostname internalHostnameAnnotationKey = "external-dns.alpha.kubernetes.io/internal-hostname" - // New annotation to support wildcard annotations for webhook providers - webhookWildcardAnnotationKey = "external-dns.alpha.kubernetes.io/webhook-*" ) const ( @@ -226,7 +224,7 @@ func getProviderSpecificAnnotations(annotations map[string]string) (endpoint.Pro Name: fmt.Sprintf("ibmcloud-%s", attr), Value: v, }) - } else if strings.HasPrefix(k, webhookWildcardAnnotationKey) { + } else if strings.HasPrefix(k, "external-dns.alpha.kubernetes.io/webhook-") { // Support for wildcard annotations for webhook providers attr := strings.TrimPrefix(k, "external-dns.alpha.kubernetes.io/webhook-") providerSpecificAnnotations = append(providerSpecificAnnotations, endpoint.ProviderSpecificProperty{