diff --git a/controllers/dnsupdate.go b/controllers/dnsupdate.go index 85c64cd8c4..d90a970998 100644 --- a/controllers/dnsupdate.go +++ b/controllers/dnsupdate.go @@ -74,7 +74,7 @@ func (r *GslbReconciler) gslbDNSEndpoint(gslb *k8gbv1beta1.Gslb) (*externaldns.D if len(externalTargets) > 0 { switch gslb.Spec.Strategy.Type { - case roundRobinStrategy: + case roundRobinStrategy, geoStrategy: finalTargets = append(finalTargets, externalTargets...) case failoverStrategy: // If cluster is Primary @@ -107,6 +107,9 @@ func (r *GslbReconciler) gslbDNSEndpoint(gslb *k8gbv1beta1.Gslb) (*externaldns.D RecordTTL: ttl, RecordType: "A", Targets: finalTargets, + Labels: externaldns.Labels{ + "strategy": gslb.Spec.Strategy.Type, + }, } gslbHosts = append(gslbHosts, dnsRecord) } diff --git a/controllers/gslb_controller.go b/controllers/gslb_controller.go index 4aaab31990..e8de815344 100644 --- a/controllers/gslb_controller.go +++ b/controllers/gslb_controller.go @@ -56,6 +56,7 @@ type GslbReconciler struct { const ( gslbFinalizer = "k8gb.absa.oss/finalizer" + geoStrategy = "geoip" roundRobinStrategy = "roundRobin" failoverStrategy = "failover" primaryGeoTagAnnotation = "k8gb.io/primary-geotag" diff --git a/controllers/gslb_controller_test.go b/controllers/gslb_controller_test.go index 11ca645741..3c720116ba 100644 --- a/controllers/gslb_controller_test.go +++ b/controllers/gslb_controller_test.go @@ -316,7 +316,8 @@ func TestGslbCreatesDNSEndpointCRForHealthyIngressHosts(t *testing.T) { DNSName: "roundrobin.cloud.example.com", RecordTTL: 30, RecordType: "A", - Targets: externaldns.Targets{"10.0.0.1", "10.0.0.2", "10.0.0.3"}}, + Targets: externaldns.Targets{"10.0.0.1", "10.0.0.2", "10.0.0.3"}, + Labels: externaldns.Labels{"strategy": "roundRobin"}}, } ingressIPs := []corev1.LoadBalancerIngress{ {IP: "10.0.0.1"}, @@ -426,7 +427,8 @@ func TestCanGetExternalTargetsFromK8gbInAnotherLocation(t *testing.T) { DNSName: "roundrobin.cloud.example.com", RecordTTL: 30, RecordType: "A", - Targets: externaldns.Targets{"10.0.0.1", "10.0.0.2", "10.0.0.3", "10.1.0.1", "10.1.0.2", "10.1.0.3"}}, + Targets: externaldns.Targets{"10.0.0.1", "10.0.0.2", "10.0.0.3", "10.1.0.1", "10.1.0.2", "10.1.0.3"}, + Labels: externaldns.Labels{"strategy": "roundRobin"}}, } hrWant := map[string][]string{"roundrobin.cloud.example.com": {"10.0.0.1", "10.0.0.2", "10.0.0.3", "10.1.0.1", "10.1.0.2", "10.1.0.3"}} ingressIPs := []corev1.LoadBalancerIngress{ @@ -510,6 +512,7 @@ func TestReturnsOwnRecordsUsingFailoverStrategyWhenPrimary(t *testing.T) { RecordTTL: 30, RecordType: "A", Targets: externaldns.Targets{"10.0.0.1", "10.0.0.2", "10.0.0.3"}, + Labels: externaldns.Labels{"strategy": "failover"}, }, } ingressIPs := []corev1.LoadBalancerIngress{ @@ -564,6 +567,7 @@ func TestReturnsExternalRecordsUsingFailoverStrategy(t *testing.T) { RecordTTL: 30, RecordType: "A", Targets: externaldns.Targets{"10.1.0.1", "10.1.0.2", "10.1.0.3"}, + Labels: externaldns.Labels{"strategy": "failover"}, }, } ingressIPs := []corev1.LoadBalancerIngress{ @@ -830,7 +834,8 @@ func TestResolvesLoadBalancerHostnameFromIngressStatus(t *testing.T) { DNSName: "roundrobin.cloud.example.com", RecordTTL: 30, RecordType: "A", - Targets: externaldns.Targets{"1.0.0.1", "1.1.1.1"}}, + Targets: externaldns.Targets{"1.0.0.1", "1.1.1.1"}, + Labels: externaldns.Labels{"strategy": "roundRobin"}}, } settings := provideSettings(t, customConfig) dnsEndpoint := &externaldns.DNSEndpoint{ObjectMeta: metav1.ObjectMeta{Namespace: settings.gslb.Namespace, Name: settings.gslb.Name}}