Skip to content

Commit

Permalink
Add flag to support ClusterIP exposed CoreDNS (#1788)
Browse files Browse the repository at this point in the history
Some environments (Calico bare-metal, etc) may allow direct client
reachability to the Service CIDR, bypassing the need to assign and use
LoadBalancerIPs.  This PR adds logic to determine if the coredns service
is of type ClusterIP or LoadBalancer and returns the respective IP addresses.

---------

Signed-off-by: Brandon Ewing <brandon.ewing@imc.com>
  • Loading branch information
bewing authored Dec 19, 2024
1 parent 68a379f commit e2e5a9b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
16 changes: 16 additions & 0 deletions controllers/mocks/assistant_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions controllers/providers/assistant/assistant.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 22 additions & 2 deletions controllers/providers/assistant/gslb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit e2e5a9b

Please sign in to comment.