diff --git a/controllers/mocks/assistant_mock.go b/controllers/mocks/assistant_mock.go index ffa837c62c..f84c1e6076 100644 --- a/controllers/mocks/assistant_mock.go +++ b/controllers/mocks/assistant_mock.go @@ -33,6 +33,7 @@ import ( assistant "github.com/k8gb-io/k8gb/controllers/providers/assistant" gomock "go.uber.org/mock/gomock" + v1 "k8s.io/api/core/v1" endpoint "sigs.k8s.io/external-dns/endpoint" ) @@ -74,6 +75,21 @@ func (mr *MockAssistantMockRecorder) CoreDNSExposedIPs() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CoreDNSExposedIPs", reflect.TypeOf((*MockAssistant)(nil).CoreDNSExposedIPs)) } +// GetCoreDNSService mocks base method. +func (m *MockAssistant) GetCoreDNSService() (*v1.Service, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetCoreDNSService") + ret0, _ := ret[0].(*v1.Service) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetCoreDNSService indicates an expected call of GetCoreDNSService. +func (mr *MockAssistantMockRecorder) GetCoreDNSService() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetCoreDNSService", reflect.TypeOf((*MockAssistant)(nil).GetCoreDNSService)) +} + // GetExternalTargets mocks base method. func (m *MockAssistant) GetExternalTargets(host string, extClusterNsNames map[string]string) assistant.Targets { m.ctrl.T.Helper() diff --git a/controllers/providers/assistant/assistant.go b/controllers/providers/assistant/assistant.go index 196555c050..faef7a2aba 100644 --- a/controllers/providers/assistant/assistant.go +++ b/controllers/providers/assistant/assistant.go @@ -21,10 +21,13 @@ Generated by GoLic, for more details see: https://github.com/AbsaOSS/golic import ( "time" + corev1 "k8s.io/api/core/v1" externaldns "sigs.k8s.io/external-dns/endpoint" ) type Assistant interface { + // GetCoreDNSService returns the CoreDNS Service + GetCoreDNSService() (*corev1.Service, error) // CoreDNSExposedIPs retrieves list of exposed IP by CoreDNS CoreDNSExposedIPs() ([]string, error) // GetExternalTargets retrieves slice of targets from external clusters diff --git a/controllers/providers/assistant/gslb.go b/controllers/providers/assistant/gslb.go index 1332a2afb8..059a8db3ac 100644 --- a/controllers/providers/assistant/gslb.go +++ b/controllers/providers/assistant/gslb.go @@ -58,8 +58,8 @@ func NewGslbAssistant(client client.Client, k8gbNamespace string, edgeDNSServers } } -// CoreDNSExposedIPs retrieves list of IP's exposed by CoreDNS -func (r *Gslb) CoreDNSExposedIPs() ([]string, error) { +// GetCoreDNSService returns the CoreDNS Service +func (r *Gslb) GetCoreDNSService() (*corev1.Service, error) { serviceList := &corev1.ServiceList{} sel, err := labels.Parse(coreDNSServiceLabel) if err != nil { @@ -88,7 +88,27 @@ func (r *Gslb) CoreDNSExposedIPs() ([]string, error) { return nil, err } coreDNSService := &serviceList.Items[0] + return coreDNSService, nil +} +// CoreDNSExposedIPs retrieves list of IP's exposed by CoreDNS +func (r *Gslb) CoreDNSExposedIPs() ([]string, error) { + coreDNSService, err := r.GetCoreDNSService() + if err != nil { + return nil, err + } + if coreDNSService.Spec.Type == "ClusterIP" { + if len(coreDNSService.Spec.ClusterIPs) == 0 { + errMessage := "no ClusterIPs found" + log.Warn(). + Str("serviceName", coreDNSService.Name). + Msg(errMessage) + err := coreerrors.New(errMessage) + return nil, err + } + return coreDNSService.Spec.ClusterIPs, nil + } + // LoadBalancer / ExternalName / NodePort service var lb corev1.LoadBalancerIngress if len(coreDNSService.Status.LoadBalancer.Ingress) == 0 { errMessage := "no LoadBalancer ExternalIPs are found"