Skip to content

Commit

Permalink
remove edgeDNSZone and dnsZone from depresolver
Browse files Browse the repository at this point in the history
there is edgeDNSZone still supported by helm, but deployment eats dnsZones only
  • Loading branch information
kuritka committed Feb 20, 2025
1 parent 2325220 commit a33a177
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 422 deletions.
4 changes: 0 additions & 4 deletions chart/k8gb/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ k8gb:
deployCrds: true
# -- whether it should also deploy the service account, cluster role and cluster role binding
deployRbac: true
# -- deprecated: dnsZone controlled by gslb
# dnsZone: "cloud.example.org"
# -- deprecated: main zone which would contain gslb zone to delegate
# edgeDNSZone: example.org # main zone which would contain gslb zone to delegate
# -- array of dns zones controlled by gslb
dnsZones:
- zone: "example.com" # -- main zone which would contain gslb zone to delegate (same meaning as to edgeDNSZone)
Expand Down
6 changes: 1 addition & 5 deletions controllers/depresolver/depresolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type LogFormat int8
const (
// JSONFormat prints messages as single json record
JSONFormat LogFormat = 1 << iota
// SimpleFormat prints messages in human readable way
// SimpleFormat prints messages in human-readable way
SimpleFormat
// NoFormat, returned in situation when format is not recognised
NoFormat
Expand Down Expand Up @@ -134,10 +134,6 @@ type Config struct {
fallbackEdgeDNSServerName string `env:"EDGE_DNS_SERVER"`
// to avoid breaking changes is used as fallback server port for EdgeDNSServers
fallbackEdgeDNSServerPort int `env:"EDGE_DNS_SERVER_PORT, default=53"`
// edgeDNSZone main zone which would contain gslb zone to delegate; e.g. example.com
edgeDNSZone string `env:"EDGE_DNS_ZONE"`
// dnsZone controlled by gslb; e.g. cloud.example.com
dnsZone string `env:"DNS_ZONE"`
// DelegationZones
DelegationZones DelegationZones
// DelegationZones pairs of dnsZone ad edgeDNSZone, eg: DNS_ZONES=example.com:cloud.example.com;example.io:cloud.example.io
Expand Down
72 changes: 17 additions & 55 deletions controllers/depresolver/depresolver_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ const (
ExtClustersGeoTagsKey = "EXT_GSLB_CLUSTERS_GEO_TAGS"
ExtDNSEnabledKey = "EXTDNS_ENABLED"
EdgeDNSServersKey = "EDGE_DNS_SERVERS"
EdgeDNSZoneKey = "EDGE_DNS_ZONE"
DNSZoneKey = "DNS_ZONE"
DNSZonesKey = "DNS_ZONES"
InfobloxGridHostKey = "INFOBLOX_GRID_HOST"
InfobloxVersionKey = "INFOBLOX_WAPI_VERSION"
Expand Down Expand Up @@ -101,13 +99,11 @@ func (dr *DependencyResolver) ResolveOperatorConfig() (*Config, error) {
dr.config.Log.Level, _ = zerolog.ParseLevel(strings.ToLower(dr.config.Log.level))
dr.config.Log.Format = parseLogOutputFormat(strings.ToLower(dr.config.Log.format))
dr.config.EdgeDNSType, recognizedDNSTypes = getEdgeDNSType(dr.config)

dr.config.DelegationZones = parseDelegationZones(dr.config)
// replace validations by go-playground/validator
dr.errorConfig = dr.validateConfig(dr.config, recognizedDNSTypes)
// validation
if dr.errorConfig == nil {
dr.config.DelegationZones = parseDelegationZones(dr.config)
}

})
return dr.config, dr.errorConfig
}
Expand Down Expand Up @@ -174,21 +170,19 @@ func (dr *DependencyResolver) validateConfig(config *Config, recognizedDNSTypes
return fmt.Errorf("error for port of edge dns server(%v): it must be a positive integer between 1 and 65535", s)
}
}
err = field(EdgeDNSZoneKey, config.edgeDNSZone).isNotEmpty().matchRegexp(hostNameRegex).err
if err != nil {
return err
}
err = field(DNSZoneKey, config.dnsZone).isNotEmpty().matchRegexp(hostNameRegex).err
if err != nil {
return err
}
// do full Infoblox validation only in case that Host exists
if isNotEmpty(config.Infoblox.Host) {
err = validateConfigForInfoblox(config)
if err != nil {
return err
}
}

err = field(DNSZonesKey, config.dnsZones).isNotEmpty().err
if err != nil {
return err
}

validateLabels := func(label string) error {
labels := strings.Split(label, ".")
for _, l := range labels {
Expand All @@ -199,15 +193,15 @@ func (dr *DependencyResolver) validateConfig(config *Config, recognizedDNSTypes
return nil
}

serverNames := config.getExternalClusterNSNames()
serverNames[config.ClusterGeoTag] = config.getClusterNSName()
for geoTag, nsName := range serverNames {
if len(nsName) > dnsNameMax {
return fmt.Errorf("ns name '%s' exceeds %v charactes limit for [GeoTag: '%s', %s: '%s', %s: '%s']",
nsName, dnsLabelMax, geoTag, EdgeDNSZoneKey, config.edgeDNSZone, DNSZoneKey, config.dnsZone)
}
if err := validateLabels(nsName); err != nil {
return fmt.Errorf("error for geo tag: %s. %s in ns name %s", geoTag, err, nsName)
for _, zone := range config.DelegationZones {
for _, nsName := range zone.GetNSServerList() {
if len(nsName) > dnsNameMax {
return fmt.Errorf("ns name '%s' exceeds %v charactes limit for [%s: '%s:%s']",
nsName, dnsLabelMax, DNSZonesKey, zone.Zone, zone.Domain)
}
if err := validateLabels(nsName); err != nil {
return fmt.Errorf("%s in ns name %s", err, nsName)
}
}
}

Expand Down Expand Up @@ -383,35 +377,3 @@ func parseLogOutputFormat(value string) LogFormat {
}
return NoFormat
}

// deprecated, used for validations only
func (c *Config) getExternalClusterNSNames() (m map[string]string) {
m = make(map[string]string, len(c.extClustersGeoTags))
for _, tag := range c.extClustersGeoTags {
m[tag] = getNsName(tag, c.dnsZone, c.edgeDNSZone, c.EdgeDNSServers[0].Host)
}
return
}

// deprecated, used for validations only
func (c *Config) getClusterNSName() string {
return getNsName(c.ClusterGeoTag, c.dnsZone, c.edgeDNSZone, c.EdgeDNSServers[0].Host)
}

// getNsName returns NS for geo tag.
// The values is combination of dnsZone, edgeDNSZone and (Ext)ClusterGeoTag, see:
// DNS_ZONE k8gb-test.gslb.cloud.example.com
// EDGE_DNS_ZONE: cloud.example.com
// CLUSTER_GEOTAG: us
// will generate "gslb-ns-us-k8gb-test-gslb.cloud.example.com"
// If edgeDNSServer == localhost or 127.0.0.1 than edgeDNSServer is returned.
// The function is private and expects only valid inputs.
func getNsName(tag, dnsZone, edgeDNSZone, edgeDNSServer string) string {
if edgeDNSServer == "127.0.0.1" || edgeDNSServer == "localhost" {
return edgeDNSServer
}
const prefix = "gslb-ns"
d := strings.TrimSuffix(dnsZone, "."+edgeDNSZone)
domainX := strings.ReplaceAll(d, ".", "-")
return fmt.Sprintf("%s-%s-%s.%s", prefix, tag, domainX, edgeDNSZone)
}
20 changes: 3 additions & 17 deletions controllers/depresolver/depresolver_domaininfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ type DelegationZoneInfo struct {
func parseDelegationZones(config *Config) []DelegationZoneInfo {

zones := config.dnsZones
edgeDNSZone := config.edgeDNSZone
dnsZone := config.dnsZone

getNsName := func(tag, edgeDNSServer, zone, edge string) string {
if edgeDNSServer == localhost || edgeDNSServer == localhostIPv4 {
Expand All @@ -52,33 +50,21 @@ func parseDelegationZones(config *Config) []DelegationZoneInfo {
}

// parse example.com:cloud.example.com;example.io:cloud.example.io into map[string]string
getEnvAsArrayOfPairsOrFallback := func(zones string, fallback map[string]string) map[string]string {
getEnvAsArrayOfPairsOrFallback := func(zones string) map[string]string {
pairs := make(map[string]string)
slice := strings.Split(zones, ";")
if len(slice) == 0 {
return fallback
}
for _, z := range slice {
pair := strings.Split(z, ":")
if len(pair) != 2 {
return fallback
return pairs
}
pairs[strings.Trim(pair[0], " ")] = strings.Trim(pair[1], " ")
}
for k, v := range fallback {
if _, found := pairs[k]; !found {
pairs[k] = v
}
}
return pairs
}
var dzi []DelegationZoneInfo
zones = strings.TrimSuffix(strings.TrimSuffix(zones, ";"), " ")
fallbackDNSZone := map[string]string{}
if !(edgeDNSZone == "" && dnsZone == "") {
fallbackDNSZone[edgeDNSZone] = dnsZone
}
di := getEnvAsArrayOfPairsOrFallback(zones, fallbackDNSZone)
di := getEnvAsArrayOfPairsOrFallback(zones)

for edge, zone := range di {
zoneInfo := DelegationZoneInfo{
Expand Down
Loading

0 comments on commit a33a177

Please sign in to comment.