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

Add flag to support ClusterIP exposed CoreDNS #1788

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions controllers/depresolver/depresolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ 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
15 changes: 15 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.

2 changes: 2 additions & 0 deletions controllers/providers/assistant/assistant.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
)

type Assistant interface {
//CoreDNSClusterIPs retrieves a list of ClusterIPs assigned to CoreDNS

Check failure on line 28 in controllers/providers/assistant/assistant.go

View workflow job for this annotation

GitHub Actions / Inspect packages

commentFormatting: put a space between `//` and comment text (gocritic)
CoreDNSClusterIPs() ([]string, error)
// CoreDNSExposedIPs retrieves list of exposed IP by CoreDNS
CoreDNSExposedIPs() ([]string, error)
// GetExternalTargets retrieves slice of targets from external clusters
Expand Down
28 changes: 26 additions & 2 deletions controllers/providers/assistant/gslb.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ func NewGslbAssistant(client client.Client, k8gbNamespace string, edgeDNSServers
}
}

// CoreDNSExposedIPs retrieves list of IP's exposed by CoreDNS
func (r *Gslb) CoreDNSExposedIPs() ([]string, error) {
func (r *Gslb) GetCoreDNSService() (*corev1.Service, error) {
bewing marked this conversation as resolved.
Show resolved Hide resolved
serviceList := &corev1.ServiceList{}
sel, err := labels.Parse(coreDNSServiceLabel)
if err != nil {
Expand Down Expand Up @@ -88,7 +87,32 @@ func (r *Gslb) CoreDNSExposedIPs() ([]string, error) {
return nil, err
}
coreDNSService := &serviceList.Items[0]
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
}
var lb corev1.LoadBalancerIngress
if len(coreDNSService.Status.LoadBalancer.Ingress) == 0 {
errMessage := "no LoadBalancer ExternalIPs are found"
Expand Down
6 changes: 5 additions & 1 deletion controllers/providers/dns/external.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ func (p *ExternalDNSProvider) CreateZoneDelegationForExternalDNS(gslb *k8gbv1bet
var NSServerIPs []string
var err error
if p.config.CoreDNSExposed {
NSServerIPs, err = p.assistant.CoreDNSExposedIPs()
if p.config.CoreDNSClusterIPs {
NSServerIPs, err = p.assistant.CoreDNSClusterIPs()
} else {
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: 5 additions & 1 deletion controllers/providers/dns/infoblox.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ func (p *InfobloxProvider) CreateZoneDelegationForExternalDNS(gslb *k8gbv1beta1.

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