mirror of
https://github.com/kubernetes-sigs/external-dns.git
synced 2025-08-05 09:06:58 +02:00
test
Signed-off-by: Raffaele Di Fazio <difazio.raffaele@gmail.com>
This commit is contained in:
parent
761d6551d3
commit
c375899f91
@ -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)
|
||||
}
|
||||
|
@ -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{
|
||||
|
Loading…
Reference in New Issue
Block a user