Skip to content
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
5 changes: 5 additions & 0 deletions apis/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ import (
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

const (
// DNSEndpointKind is the kind name for DNSEndpoint resources
DNSEndpointKind = "DNSEndpoint"
)

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "externaldns.k8s.io", Version: "v1alpha1"}
Expand Down
11 changes: 1 addition & 10 deletions source/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,6 @@ type crdSource struct {
informer cache.SharedInformer
}

func addKnownTypes(scheme *runtime.Scheme, groupVersion schema.GroupVersion) error {
scheme.AddKnownTypes(groupVersion,
&apiv1alpha1.DNSEndpoint{},
&apiv1alpha1.DNSEndpointList{},
)
metav1.AddToGroupVersion(scheme, groupVersion)
return nil
}

// NewCRDClientForAPIVersionKind return rest client for the given apiVersion and kind of the CRD
func NewCRDClientForAPIVersionKind(client kubernetes.Interface, kubeConfig, apiServerURL, apiVersion, kind string) (*rest.RESTClient, *runtime.Scheme, error) {
if kubeConfig == "" {
Expand Down Expand Up @@ -105,7 +96,7 @@ func NewCRDClientForAPIVersionKind(client kubernetes.Interface, kubeConfig, apiS
}

scheme := runtime.NewScheme()
_ = addKnownTypes(scheme, groupVersion)
_ = apiv1alpha1.AddToScheme(scheme)

config.GroupVersion = &groupVersion
config.APIPath = "/apis"
Expand Down
138 changes: 69 additions & 69 deletions source/crd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func objBody(codec runtime.Encoder, obj runtime.Object) io.ReadCloser {
func fakeRESTClient(endpoints []*endpoint.Endpoint, apiVersion, kind, namespace, name string, annotations map[string]string, labels map[string]string, _ *testing.T) rest.Interface {
groupVersion, _ := schema.ParseGroupVersion(apiVersion)
scheme := runtime.NewScheme()
_ = addKnownTypes(scheme, groupVersion)
_ = apiv1alpha1.AddToScheme(scheme)

dnsEndpointList := apiv1alpha1.DNSEndpointList{}
dnsEndpoint := &apiv1alpha1.DNSEndpoint{
Expand Down Expand Up @@ -171,9 +171,9 @@ func testCRDSourceEndpoints(t *testing.T) {
},
{
title: "invalid crd kind",
registeredAPIVersion: "test.k8s.io/v1alpha1",
apiVersion: "test.k8s.io/v1alpha1",
registeredKind: "DNSEndpoint",
registeredAPIVersion: apiv1alpha1.GroupVersion.String(),
apiVersion: apiv1alpha1.GroupVersion.String(),
registeredKind: apiv1alpha1.DNSEndpointKind,
kind: "JustEndpoint",
endpoints: []*endpoint.Endpoint{
{
Expand All @@ -188,10 +188,10 @@ func testCRDSourceEndpoints(t *testing.T) {
},
{
title: "endpoints within a specific namespace",
registeredAPIVersion: "test.k8s.io/v1alpha1",
apiVersion: "test.k8s.io/v1alpha1",
registeredKind: "DNSEndpoint",
kind: "DNSEndpoint",
registeredAPIVersion: apiv1alpha1.GroupVersion.String(),
apiVersion: apiv1alpha1.GroupVersion.String(),
registeredKind: apiv1alpha1.DNSEndpointKind,
kind: apiv1alpha1.DNSEndpointKind,
namespace: "foo",
registeredNamespace: "foo",
endpoints: []*endpoint.Endpoint{
Expand All @@ -207,10 +207,10 @@ func testCRDSourceEndpoints(t *testing.T) {
},
{
title: "no endpoints within a specific namespace",
registeredAPIVersion: "test.k8s.io/v1alpha1",
apiVersion: "test.k8s.io/v1alpha1",
registeredKind: "DNSEndpoint",
kind: "DNSEndpoint",
registeredAPIVersion: apiv1alpha1.GroupVersion.String(),
apiVersion: apiv1alpha1.GroupVersion.String(),
registeredKind: apiv1alpha1.DNSEndpointKind,
kind: apiv1alpha1.DNSEndpointKind,
namespace: "foo",
registeredNamespace: "bar",
endpoints: []*endpoint.Endpoint{
Expand All @@ -226,10 +226,10 @@ func testCRDSourceEndpoints(t *testing.T) {
},
{
title: "valid crd with no targets (relies on default-targets)",
registeredAPIVersion: "test.k8s.io/v1alpha1",
apiVersion: "test.k8s.io/v1alpha1",
registeredKind: "DNSEndpoint",
kind: "DNSEndpoint",
registeredAPIVersion: apiv1alpha1.GroupVersion.String(),
apiVersion: apiv1alpha1.GroupVersion.String(),
registeredKind: apiv1alpha1.DNSEndpointKind,
kind: apiv1alpha1.DNSEndpointKind,
namespace: "foo",
registeredNamespace: "foo",
endpoints: []*endpoint.Endpoint{
Expand All @@ -245,10 +245,10 @@ func testCRDSourceEndpoints(t *testing.T) {
},
{
title: "valid crd gvk with single endpoint",
registeredAPIVersion: "test.k8s.io/v1alpha1",
apiVersion: "test.k8s.io/v1alpha1",
registeredKind: "DNSEndpoint",
kind: "DNSEndpoint",
registeredAPIVersion: apiv1alpha1.GroupVersion.String(),
apiVersion: apiv1alpha1.GroupVersion.String(),
registeredKind: apiv1alpha1.DNSEndpointKind,
kind: apiv1alpha1.DNSEndpointKind,
namespace: "foo",
registeredNamespace: "foo",
endpoints: []*endpoint.Endpoint{
Expand All @@ -264,10 +264,10 @@ func testCRDSourceEndpoints(t *testing.T) {
},
{
title: "valid crd gvk with multiple endpoints",
registeredAPIVersion: "test.k8s.io/v1alpha1",
apiVersion: "test.k8s.io/v1alpha1",
registeredKind: "DNSEndpoint",
kind: "DNSEndpoint",
registeredAPIVersion: apiv1alpha1.GroupVersion.String(),
apiVersion: apiv1alpha1.GroupVersion.String(),
registeredKind: apiv1alpha1.DNSEndpointKind,
kind: apiv1alpha1.DNSEndpointKind,
namespace: "foo",
registeredNamespace: "foo",
endpoints: []*endpoint.Endpoint{
Expand All @@ -289,10 +289,10 @@ func testCRDSourceEndpoints(t *testing.T) {
},
{
title: "valid crd gvk with annotation and non matching annotation filter",
registeredAPIVersion: "test.k8s.io/v1alpha1",
apiVersion: "test.k8s.io/v1alpha1",
registeredKind: "DNSEndpoint",
kind: "DNSEndpoint",
registeredAPIVersion: apiv1alpha1.GroupVersion.String(),
apiVersion: apiv1alpha1.GroupVersion.String(),
registeredKind: apiv1alpha1.DNSEndpointKind,
kind: apiv1alpha1.DNSEndpointKind,
namespace: "foo",
registeredNamespace: "foo",
annotations: map[string]string{"test": "that"},
Expand All @@ -310,10 +310,10 @@ func testCRDSourceEndpoints(t *testing.T) {
},
{
title: "valid crd gvk with annotation and matching annotation filter",
registeredAPIVersion: "test.k8s.io/v1alpha1",
apiVersion: "test.k8s.io/v1alpha1",
registeredKind: "DNSEndpoint",
kind: "DNSEndpoint",
registeredAPIVersion: apiv1alpha1.GroupVersion.String(),
apiVersion: apiv1alpha1.GroupVersion.String(),
registeredKind: apiv1alpha1.DNSEndpointKind,
kind: apiv1alpha1.DNSEndpointKind,
namespace: "foo",
registeredNamespace: "foo",
annotations: map[string]string{"test": "that"},
Expand All @@ -331,10 +331,10 @@ func testCRDSourceEndpoints(t *testing.T) {
},
{
title: "valid crd gvk with label and non matching label filter",
registeredAPIVersion: "test.k8s.io/v1alpha1",
apiVersion: "test.k8s.io/v1alpha1",
registeredKind: "DNSEndpoint",
kind: "DNSEndpoint",
registeredAPIVersion: apiv1alpha1.GroupVersion.String(),
apiVersion: apiv1alpha1.GroupVersion.String(),
registeredKind: apiv1alpha1.DNSEndpointKind,
kind: apiv1alpha1.DNSEndpointKind,
namespace: "foo",
registeredNamespace: "foo",
labels: map[string]string{"test": "that"},
Expand All @@ -352,10 +352,10 @@ func testCRDSourceEndpoints(t *testing.T) {
},
{
title: "valid crd gvk with label and matching label filter",
registeredAPIVersion: "test.k8s.io/v1alpha1",
apiVersion: "test.k8s.io/v1alpha1",
registeredKind: "DNSEndpoint",
kind: "DNSEndpoint",
registeredAPIVersion: apiv1alpha1.GroupVersion.String(),
apiVersion: apiv1alpha1.GroupVersion.String(),
registeredKind: apiv1alpha1.DNSEndpointKind,
kind: apiv1alpha1.DNSEndpointKind,
namespace: "foo",
registeredNamespace: "foo",
labels: map[string]string{"test": "that"},
Expand All @@ -373,10 +373,10 @@ func testCRDSourceEndpoints(t *testing.T) {
},
{
title: "Create NS record",
registeredAPIVersion: "test.k8s.io/v1alpha1",
apiVersion: "test.k8s.io/v1alpha1",
registeredKind: "DNSEndpoint",
kind: "DNSEndpoint",
registeredAPIVersion: apiv1alpha1.GroupVersion.String(),
apiVersion: apiv1alpha1.GroupVersion.String(),
registeredKind: apiv1alpha1.DNSEndpointKind,
kind: apiv1alpha1.DNSEndpointKind,
namespace: "foo",
registeredNamespace: "foo",
labels: map[string]string{"test": "that"},
Expand All @@ -394,10 +394,10 @@ func testCRDSourceEndpoints(t *testing.T) {
},
{
title: "Create SRV record",
registeredAPIVersion: "test.k8s.io/v1alpha1",
apiVersion: "test.k8s.io/v1alpha1",
registeredKind: "DNSEndpoint",
kind: "DNSEndpoint",
registeredAPIVersion: apiv1alpha1.GroupVersion.String(),
apiVersion: apiv1alpha1.GroupVersion.String(),
registeredKind: apiv1alpha1.DNSEndpointKind,
kind: apiv1alpha1.DNSEndpointKind,
namespace: "foo",
registeredNamespace: "foo",
labels: map[string]string{"test": "that"},
Expand All @@ -415,10 +415,10 @@ func testCRDSourceEndpoints(t *testing.T) {
},
{
title: "Create NAPTR record",
registeredAPIVersion: "test.k8s.io/v1alpha1",
apiVersion: "test.k8s.io/v1alpha1",
registeredKind: "DNSEndpoint",
kind: "DNSEndpoint",
registeredAPIVersion: apiv1alpha1.GroupVersion.String(),
apiVersion: apiv1alpha1.GroupVersion.String(),
registeredKind: apiv1alpha1.DNSEndpointKind,
kind: apiv1alpha1.DNSEndpointKind,
namespace: "foo",
registeredNamespace: "foo",
labels: map[string]string{"test": "that"},
Expand All @@ -436,10 +436,10 @@ func testCRDSourceEndpoints(t *testing.T) {
},
{
title: "illegal target CNAME",
registeredAPIVersion: "test.k8s.io/v1alpha1",
apiVersion: "test.k8s.io/v1alpha1",
registeredKind: "DNSEndpoint",
kind: "DNSEndpoint",
registeredAPIVersion: apiv1alpha1.GroupVersion.String(),
apiVersion: apiv1alpha1.GroupVersion.String(),
registeredKind: apiv1alpha1.DNSEndpointKind,
kind: apiv1alpha1.DNSEndpointKind,
namespace: "foo",
registeredNamespace: "foo",
labels: map[string]string{"test": "that"},
Expand All @@ -457,10 +457,10 @@ func testCRDSourceEndpoints(t *testing.T) {
},
{
title: "illegal target NAPTR",
registeredAPIVersion: "test.k8s.io/v1alpha1",
apiVersion: "test.k8s.io/v1alpha1",
registeredKind: "DNSEndpoint",
kind: "DNSEndpoint",
registeredAPIVersion: apiv1alpha1.GroupVersion.String(),
apiVersion: apiv1alpha1.GroupVersion.String(),
registeredKind: apiv1alpha1.DNSEndpointKind,
kind: apiv1alpha1.DNSEndpointKind,
namespace: "foo",
registeredNamespace: "foo",
labels: map[string]string{"test": "that"},
Expand All @@ -478,10 +478,10 @@ func testCRDSourceEndpoints(t *testing.T) {
},
{
title: "valid target TXT",
registeredAPIVersion: "test.k8s.io/v1alpha1",
apiVersion: "test.k8s.io/v1alpha1",
registeredKind: "DNSEndpoint",
kind: "DNSEndpoint",
registeredAPIVersion: apiv1alpha1.GroupVersion.String(),
apiVersion: apiv1alpha1.GroupVersion.String(),
registeredKind: apiv1alpha1.DNSEndpointKind,
kind: apiv1alpha1.DNSEndpointKind,
namespace: "foo",
registeredNamespace: "foo",
labels: map[string]string{"test": "that"},
Expand All @@ -499,10 +499,10 @@ func testCRDSourceEndpoints(t *testing.T) {
},
{
title: "illegal target A",
registeredAPIVersion: "test.k8s.io/v1alpha1",
apiVersion: "test.k8s.io/v1alpha1",
registeredKind: "DNSEndpoint",
kind: "DNSEndpoint",
registeredAPIVersion: apiv1alpha1.GroupVersion.String(),
apiVersion: apiv1alpha1.GroupVersion.String(),
registeredKind: apiv1alpha1.DNSEndpointKind,
kind: apiv1alpha1.DNSEndpointKind,
namespace: "foo",
registeredNamespace: "foo",
labels: map[string]string{"test": "that"},
Expand All @@ -528,7 +528,7 @@ func testCRDSourceEndpoints(t *testing.T) {
require.NotNil(t, groupVersion)

scheme := runtime.NewScheme()
err = addKnownTypes(scheme, groupVersion)
err = apiv1alpha1.AddToScheme(scheme)
require.NoError(t, err)

labelSelector, err := labels.Parse(ti.labelFilter)
Expand Down
Loading