Skip to content

Commit

Permalink
fix(source): ingresses should be ignored if other controller (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
linki authored Mar 23, 2017
1 parent d7b107a commit f3c1d0f
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 16 deletions.
6 changes: 6 additions & 0 deletions source/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ func (sc *ingressSource) Endpoints() ([]endpoint.Endpoint, error) {
func endpointsFromIngress(ing *v1beta1.Ingress) []endpoint.Endpoint {
var endpoints []endpoint.Endpoint

// Check controller annotation to see if we are responsible.
controller, exists := ing.Annotations[controllerAnnotationKey]
if exists && controller != controllerAnnotationValue {
return endpoints
}

for _, rule := range ing.Spec.Rules {
if rule.Host == "" {
continue
Expand Down
53 changes: 46 additions & 7 deletions source/ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,43 @@ func testIngressEndpoints(t *testing.T) {
},
},
},
{
title: "our controller type is dns-controller",
targetNamespace: "",
ingressItems: []fakeIngress{
{
name: "fake1",
namespace: namespace,
annotations: map[string]string{
controllerAnnotationKey: controllerAnnotationValue,
},
dnsnames: []string{"example.org"},
ips: []string{"8.8.8.8"},
},
},
expected: []endpoint.Endpoint{
{
DNSName: "example.org.",
Target: "8.8.8.8",
},
},
},
{
title: "different controller types are ignored",
targetNamespace: "",
ingressItems: []fakeIngress{
{
name: "fake1",
namespace: namespace,
annotations: map[string]string{
controllerAnnotationKey: "some-other-tool",
},
dnsnames: []string{"example.org"},
ips: []string{"8.8.8.8"},
},
},
expected: []endpoint.Endpoint{},
},
} {
t.Run(ti.title, func(t *testing.T) {
ingresses := make([]*v1beta1.Ingress, 0)
Expand Down Expand Up @@ -243,18 +280,20 @@ func testIngressEndpoints(t *testing.T) {

// ingress specific helper functions
type fakeIngress struct {
dnsnames []string
ips []string
hostnames []string
namespace string
name string
dnsnames []string
ips []string
hostnames []string
namespace string
name string
annotations map[string]string
}

func (ing fakeIngress) Ingress() *v1beta1.Ingress {
ingress := &v1beta1.Ingress{
ObjectMeta: v1.ObjectMeta{
Namespace: ing.namespace,
Name: ing.name,
Namespace: ing.namespace,
Name: ing.name,
Annotations: ing.annotations,
},
Spec: v1beta1.IngressSpec{
Rules: []v1beta1.IngressRule{},
Expand Down
9 changes: 0 additions & 9 deletions source/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,6 @@ import (
"github.com/kubernetes-incubator/external-dns/endpoint"
)

const (
// The annotation used for figuring out which controller is responsible
controllerAnnotationKey = "external-dns.alpha.kubernetes.io/controller"
// The annotation used for defining the desired hostname
hostnameAnnotationKey = "external-dns.alpha.kubernetes.io/hostname"
// The value of the controller annotation so that we feel resposible
controllerAnnotationValue = "dns-controller"
)

// serviceSource is an implementation of Source for Kubernetes service objects.
// It will find all services that are under our jurisdiction, i.e. annotated
// desired hostname and matching or no controller annotation. For each of the
Expand Down
9 changes: 9 additions & 0 deletions source/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ import (
"github.com/kubernetes-incubator/external-dns/endpoint"
)

const (
// The annotation used for figuring out which controller is responsible
controllerAnnotationKey = "external-dns.alpha.kubernetes.io/controller"
// The annotation used for defining the desired hostname
hostnameAnnotationKey = "external-dns.alpha.kubernetes.io/hostname"
// The value of the controller annotation so that we feel resposible
controllerAnnotationValue = "dns-controller"
)

// Source defines the interface Endpoint sources should implement.
type Source interface {
Endpoints() ([]endpoint.Endpoint, error)
Expand Down

0 comments on commit f3c1d0f

Please sign in to comment.