Skip to content

Commit

Permalink
Remove config flag and refactor assistant
Browse files Browse the repository at this point in the history
Instead of using a config flag to select ClusterIPs for the CoreDNS
service, inspect the service type to determine which set of IPs to
return.

Signed-off-by: Brandon Ewing <[email protected]>
  • Loading branch information
bewing committed Dec 18, 2024
1 parent bada552 commit 7e5d320
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 44 deletions.
2 changes: 0 additions & 2 deletions controllers/depresolver/depresolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ type Config struct {
Infoblox Infoblox
// CoreDNSExposed flag
CoreDNSExposed bool `env:"COREDNS_EXPOSED, default=false"`
// CoreDNSClusterIPs flag
CoreDNSClusterIPs bool `env:"COREDNS_CLUSTERIPS, default=false"`
// Log configuration
Log Log
// MetricsAddress in format address:port where address can be empty, IP address, or hostname, default: 0.0.0.0:8080
Expand Down
27 changes: 14 additions & 13 deletions controllers/mocks/assistant_mock.go

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

5 changes: 3 additions & 2 deletions controllers/providers/assistant/assistant.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +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 {
//CoreDNSClusterIPs retrieves a list of ClusterIPs assigned to CoreDNS
CoreDNSClusterIPs() ([]string, error)
// 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
30 changes: 13 additions & 17 deletions controllers/providers/assistant/gslb.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func NewGslbAssistant(client client.Client, k8gbNamespace string, edgeDNSServers
}
}

// GetCoreDNSService returns the CoreDNS Service
func (r *Gslb) GetCoreDNSService() (*corev1.Service, error) {
serviceList := &corev1.ServiceList{}
sel, err := labels.Parse(coreDNSServiceLabel)
Expand Down Expand Up @@ -90,29 +91,24 @@ func (r *Gslb) GetCoreDNSService() (*corev1.Service, error) {
return coreDNSService, nil
}

// CoreDNSClusterIPs retrieves list of ClusterIPs assigned to CoreDNS
func (r *Gslb) CoreDNSClusterIPs() ([]string, error) {
coreDNSService, err := r.GetCoreDNSService()
if err != nil {
return nil, err
}
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
}

// 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
6 changes: 1 addition & 5 deletions controllers/providers/dns/external.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,7 @@ func (p *ExternalDNSProvider) CreateZoneDelegationForExternalDNS(gslb *k8gbv1bet
var NSServerIPs []string
var err error
if p.config.CoreDNSExposed {
if p.config.CoreDNSClusterIPs {
NSServerIPs, err = p.assistant.CoreDNSClusterIPs()
} else {
NSServerIPs, err = p.assistant.CoreDNSExposedIPs()
}
NSServerIPs, err = p.assistant.CoreDNSExposedIPs()
} else {
if len(gslb.Status.LoadBalancer.ExposedIPs) == 0 {
// do not update DNS Endpoint for External DNS if no IPs are exposed
Expand Down
6 changes: 1 addition & 5 deletions controllers/providers/dns/infoblox.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,7 @@ func (p *InfobloxProvider) CreateZoneDelegationForExternalDNS(gslb *k8gbv1beta1.

var addresses []string
if p.config.CoreDNSExposed {
if p.config.CoreDNSClusterIPs {
addresses, err = p.assistant.CoreDNSClusterIPs()
} else {
addresses, err = p.assistant.CoreDNSExposedIPs()
}
addresses, err = p.assistant.CoreDNSExposedIPs()
} else {
addresses = gslb.Status.LoadBalancer.ExposedIPs
}
Expand Down

0 comments on commit 7e5d320

Please sign in to comment.