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

Infoblox update #58

Merged
merged 3 commits into from
Mar 9, 2020
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
51 changes: 0 additions & 51 deletions chart/ohmyglb/templates/external-dns/external-dns-infoblox.yaml

This file was deleted.

4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ module github.com/AbsaOSS/ohmyglb
go 1.13

require (
github.com/AbsaOSS/infoblox-go-client v0.8.1-0.20200220151434-d103ffba14dd
github.com/AbsaOSS/infoblox-go-client v0.8.1-0.20200305141429-91388c9466d8
github.com/ghodss/yaml v1.0.1-0.20180820084758-c7ce16629ff4
github.com/go-openapi/spec v0.19.0
github.com/kubernetes-incubator/external-dns v0.5.17
github.com/miekg/dns v1.1.27
github.com/onsi/ginkgo v1.8.0
github.com/onsi/gomega v1.5.0
github.com/operator-framework/operator-sdk v0.12.0
github.com/spf13/pflag v1.0.3
k8s.io/api v0.0.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ github.com/AbsaOSS/infoblox-go-client v0.8.1-0.20200202014520-4fcca3cefb11 h1:i3
github.com/AbsaOSS/infoblox-go-client v0.8.1-0.20200202014520-4fcca3cefb11/go.mod h1:MxeaLEnYmDInNuJ7NPxN39oj0NkJGvRoPpJYCwtmnR0=
github.com/AbsaOSS/infoblox-go-client v0.8.1-0.20200220151434-d103ffba14dd h1:vXbdwh1aSpAQOwuEz0KePfSANXEoz/0o0T2k70glTsY=
github.com/AbsaOSS/infoblox-go-client v0.8.1-0.20200220151434-d103ffba14dd/go.mod h1:MxeaLEnYmDInNuJ7NPxN39oj0NkJGvRoPpJYCwtmnR0=
github.com/AbsaOSS/infoblox-go-client v0.8.1-0.20200305141429-91388c9466d8 h1:TsZFZnJy98ShhkbgrAL4qk7wdzmBccBVT7N+JQlD3aI=
github.com/AbsaOSS/infoblox-go-client v0.8.1-0.20200305141429-91388c9466d8/go.mod h1:MxeaLEnYmDInNuJ7NPxN39oj0NkJGvRoPpJYCwtmnR0=
github.com/Azure/azure-sdk-for-go v10.0.4-beta+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc=
github.com/Azure/azure-sdk-for-go v21.4.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc=
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8=
Expand Down
65 changes: 19 additions & 46 deletions pkg/controller/gslb/dnsupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,52 +183,6 @@ func nsServerName(gslb *ohmyglbv1beta1.Gslb, clusterGeoTag string) string {
return fmt.Sprintf("%s-ns-%s.%s", gslb.Name, clusterGeoTag, edgeDNSZone)
}

func (r *ReconcileGslb) gslbEdgeDNSEndpoint(gslb *ohmyglbv1beta1.Gslb) (*externaldns.DNSEndpoint, error) {
clusterGeoTag := os.Getenv("CLUSTER_GEO_TAG")
edgeDNSEndpointSpec := externaldns.DNSEndpointSpec{}
localTargets, err := r.getGslbIngressIPs(gslb)
if err != nil {
return nil, err
}
// Type A record to be registered resolve NS records in edge dns responses(infoblox, route53,...)
edgeDNSRecordA := &externaldns.Endpoint{
DNSName: nsServerName(gslb, clusterGeoTag),
RecordTTL: 30,
RecordType: "A",
Targets: localTargets,
}

edgeTimestamp := fmt.Sprint(time.Now().UTC().Format("2006-01-02T15:04:05"))

edgeDNSRecordTXT := &externaldns.Endpoint{
DNSName: nsServerName(gslb, clusterGeoTag),
RecordTTL: 30,
RecordType: "TXT",
Targets: []string{edgeTimestamp},
}

edgeDNSEndpointSpec = externaldns.DNSEndpointSpec{
Endpoints: []*externaldns.Endpoint{
edgeDNSRecordA,
edgeDNSRecordTXT,
},
}

edgeDNSEndpoint := &externaldns.DNSEndpoint{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-ns", gslb.Name),
Namespace: gslb.Namespace,
Annotations: map[string]string{"ohmyglb.absa.oss/dnstype": "edgedns"},
},
Spec: edgeDNSEndpointSpec,
}
err = controllerutil.SetControllerReference(gslb, edgeDNSEndpoint, r.scheme)
if err != nil {
return nil, err
}
return edgeDNSEndpoint, nil
}

type fakeInfobloxConnector struct {
//createObjectObj interface{}

Expand Down Expand Up @@ -388,6 +342,7 @@ func (r *ReconcileGslb) configureZoneDelegation(gslb *ohmyglbv1beta1.Gslb) (*rec
}

gslbZoneName := os.Getenv("DNS_ZONE")
edgeDNSZone := os.Getenv("EDGE_DNS_ZONE")
findZone, err := objMgr.GetZoneDelegated(gslbZoneName)
if err != nil {
return &reconcile.Result{}, err
Expand Down Expand Up @@ -426,6 +381,24 @@ func (r *ReconcileGslb) configureZoneDelegation(gslb *ohmyglbv1beta1.Gslb) (*rec
return &reconcile.Result{}, err
}
}

edgeTimestamp := fmt.Sprint(time.Now().UTC().Format("2006-01-02T15:04:05"))
heartbeatTXTName := fmt.Sprintf("%s-heartbeat-%s.%s", gslb.Name, clusterGeoTag, edgeDNSZone)
heartbeatTXTRecord, err := objMgr.GetTXTRecord(heartbeatTXTName)
if err != nil {
return &reconcile.Result{}, err
}
if heartbeatTXTRecord == nil {
_, err := objMgr.CreateTXTRecord(heartbeatTXTName, edgeTimestamp, "default")
if err != nil {
return &reconcile.Result{}, err
}
} else {
_, err := objMgr.UpdateTXTRecord(heartbeatTXTName, edgeTimestamp)
if err != nil {
return &reconcile.Result{}, err
}
}
}
return nil, nil
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/gslb/fakedns.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ func oldEdgeTimestamp(threshold string) string {

var records = map[string][]string{
"localtargets.app3.cloud.example.com.": []string{"10.1.0.1", "10.1.0.2", "10.1.0.3"},
"test-gslb-ns-eu.example.com.": []string{oldEdgeTimestamp("10m")},
"test-gslb-ns-za.example.com.": []string{oldEdgeTimestamp("3m")},
"test-gslb-heartbeat-eu.example.com.": []string{oldEdgeTimestamp("10m")},
"test-gslb-heartbeat-za.example.com.": []string{oldEdgeTimestamp("3m")},
}

func parseQuery(m *dns.Msg) {
Expand Down
19 changes: 19 additions & 0 deletions pkg/controller/gslb/finalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,25 @@ func (r *ReconcileGslb) finalizeGslb(gslb *ohmyglbv1beta1.Gslb) error {
}
}
}

edgeDNSZone := os.Getenv("EDGE_DNS_ZONE")
clusterGeoTag := os.Getenv("CLUSTER_GEO_TAG")
heartbeatTXTName := fmt.Sprintf("%s-heartbeat-%s.%s", gslb.Name, clusterGeoTag, edgeDNSZone)
findTXT, err := objMgr.GetTXTRecord(heartbeatTXTName)
if err != nil {
return err
}

if findTXT != nil {
if len(findTXT.Ref) > 0 {
log.Info(fmt.Sprintf("Deleting split brain TXT record(%s)...", heartbeatTXTName))
_, err := objMgr.DeleteTXTRecord(findTXT.Ref)
if err != nil {
return err
}

}
}
}

log.Info("Successfully finalized Gslb")
Expand Down
14 changes: 0 additions & 14 deletions pkg/controller/gslb/gslb_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,6 @@ func (r *ReconcileGslb) Reconcile(request reconcile.Request) (reconcile.Result,
// Requeue the request
return reconcile.Result{}, err
}
// == external-dns dnsendpoints CRs for Edge DNS==
edgeDNSEndpoint, err := r.gslbEdgeDNSEndpoint(gslb)
if err != nil {
// Requeue the request
return reconcile.Result{}, err
}

result, err = r.ensureDNSEndpoint(
request,
Expand All @@ -224,14 +218,6 @@ func (r *ReconcileGslb) Reconcile(request reconcile.Request) (reconcile.Result,
return *result, err
}

result, err = r.ensureDNSEndpoint(
request,
gslb,
edgeDNSEndpoint)
if result != nil {
return *result, err
}

// == handle delegated zone in Edge DNS

result, err = r.configureZoneDelegation(gslb)
Expand Down
77 changes: 7 additions & 70 deletions pkg/controller/gslb/gslb_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package gslb

import (
"context"
"fmt"
"io/ioutil"
"os"
"reflect"
Expand Down Expand Up @@ -253,72 +252,6 @@ func TestGslbController(t *testing.T) {
}
})

t.Run("Created DNS Record for Edge DNS(e.g. Infoblox, Route53,...", func(t *testing.T) {
err := os.Setenv("EDGE_DNS_ZONE", "example.com")
if err != nil {
t.Fatalf("Can't setup env var: (%v)", err)
}

clusterGeoTag := "eu"
err = os.Setenv("CLUSTER_GEO_TAG", clusterGeoTag)
if err != nil {
t.Fatalf("Can't setup env var: (%v)", err)
}

reconcileAndUpdateGslb(t, r, req, cl, gslb)

edgeDNSEndpoint := &externaldns.DNSEndpoint{}
edgeDNSEName := fmt.Sprintf("%s-ns", gslb.Name)
nn := types.NamespacedName{Name: edgeDNSEName, Namespace: gslb.Namespace}
err = cl.Get(context.TODO(), nn, edgeDNSEndpoint)
if err != nil {
t.Fatalf("Failed to get expected DNSEndpoint: (%v)", err)
}

fqdn := fmt.Sprintf("%s-ns-%s.example.com", gslb.Name, clusterGeoTag)
timestamp := time.Now().UTC().Format("2006-01-02T15:04:05")
got := edgeDNSEndpoint.Spec.Endpoints
want := []*externaldns.Endpoint{
{
DNSName: fqdn,
RecordTTL: 30,
RecordType: "A",
Targets: externaldns.Targets{"10.0.0.1", "10.0.0.2", "10.0.0.3"},
},
{
DNSName: fqdn,
RecordTTL: 30,
RecordType: "TXT",
Targets: externaldns.Targets{timestamp},
},
}

prettyGot := prettyPrint(got)
prettyWant := prettyPrint(want)

if !reflect.DeepEqual(got, want) {
t.Errorf("got:\n %s DNSEndpoint,\n\n want:\n %s", prettyGot, prettyWant)
}

})

t.Run("Edge DNS records has special annotation", func(t *testing.T) {
edgeDNSEndpoint := &externaldns.DNSEndpoint{}
edgeDNSEName := fmt.Sprintf("%s-ns", gslb.Name)
nn := types.NamespacedName{Name: edgeDNSEName, Namespace: gslb.Namespace}
err = cl.Get(context.TODO(), nn, edgeDNSEndpoint)
if err != nil {
t.Fatalf("Failed to get expected DNSEndpoint: (%v)", err)
}

got := edgeDNSEndpoint.Annotations["ohmyglb.absa.oss/dnstype"]

want := "edgedns"
if got != want {
t.Errorf("got:\n %q annotation value,\n\n want:\n %q", got, want)
}
})

t.Run("Local DNS records has special annotation", func(t *testing.T) {
dnsEndpoint := &externaldns.DNSEndpoint{}
err = cl.Get(context.TODO(), req.NamespacedName, dnsEndpoint)
Expand All @@ -335,7 +268,11 @@ func TestGslbController(t *testing.T) {
})

t.Run("Generates proper external NS target FQDNs according to the geo tags", func(t *testing.T) {
err := os.Setenv("EXT_GSLB_CLUSTERS_GEO_TAGS", "za")
err := os.Setenv("EDGE_DNS_ZONE", "example.com")
if err != nil {
t.Fatalf("Can't setup env var: (%v)", err)
}
err = os.Setenv("EXT_GSLB_CLUSTERS_GEO_TAGS", "za")
if err != nil {
t.Fatalf("Can't setup env var: (%v)", err)
}
Expand Down Expand Up @@ -396,7 +333,7 @@ func TestGslbController(t *testing.T) {
t.Fatalf("Can't setup env var: (%v)", err)
}

got := checkAliveFromTXT("fake", "test-gslb-ns-eu.example.com")
got := checkAliveFromTXT("fake", "test-gslb-heartbeat-eu.example.com")

want := errors.NewGone("Split brain TXT record expired the time threshold: (5m0s)")

Expand All @@ -412,7 +349,7 @@ func TestGslbController(t *testing.T) {
t.Fatalf("Can't setup env var: (%v)", err)
}

err := checkAliveFromTXT("fake", "test-gslb-ns-za.example.com")
err := checkAliveFromTXT("fake", "test-gslb-heartbeat-za.example.com")

if err != nil {
t.Errorf("got:\n %s from TXT split brain check,\n\n want error:\n %v", err, nil)
Expand Down
Loading