Skip to content

Commit

Permalink
Allow the EXT_GSLB_CLUSTERS_GEO_TAGS to contain CLUSTER_GEO_TAG
Browse files Browse the repository at this point in the history
Signed-off-by: Jirka Kremser <[email protected]>
  • Loading branch information
jkremser committed Nov 16, 2021
1 parent a8af8b2 commit 6250f8b
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 15 deletions.
14 changes: 13 additions & 1 deletion controllers/depresolver/depresolver_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func (dr *DependencyResolver) ResolveOperatorConfig() (*Config, error) {
fallbackDNS := fmt.Sprintf("%s:%v", dr.config.fallbackEdgeDNSServerName, dr.config.fallbackEdgeDNSServerPort)
edgeDNSServerList := env.GetEnvAsArrayOfStringsOrFallback(EdgeDNSServersKey, []string{fallbackDNS})
dr.config.EdgeDNSServers = parseEdgeDNSServers(edgeDNSServerList)
dr.config.ExtClustersGeoTags = parseExtClusterGeoTags(dr.config.ExtClustersGeoTags, dr.config.ClusterGeoTag)
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)
Expand Down Expand Up @@ -124,7 +125,7 @@ func (dr *DependencyResolver) validateConfig(config *Config, recognizedDNSTypes
}
for i, geoTag := range config.ExtClustersGeoTags {
err = field(fmt.Sprintf("%s[%v]", ExtClustersGeoTagsKey, i), geoTag).
isNotEmpty().matchRegexp(geoTagRegex).isNotEqualTo(config.ClusterGeoTag).err
isNotEmpty().matchRegexp(geoTagRegex).err
if err != nil {
return err
}
Expand Down Expand Up @@ -321,6 +322,17 @@ func parseEdgeDNSServers(serverList []string) (r []utils.DNSServer) {
return r
}

// parseExtClusterGeoTags ignores/excludes the clusterGeoTag from external geo tags
func parseExtClusterGeoTags(tags []string, tag string) (r []string) {
r = []string{}
for _, t := range tags {
if tag != t {
r = append(r, t)
}
}
return
}

// getEdgeDNSType contains logic retrieving EdgeDNSType.
func getEdgeDNSType(config *Config) (EdgeDNSType, []EdgeDNSType) {
recognized := make([]EdgeDNSType, 0)
Expand Down
53 changes: 49 additions & 4 deletions controllers/depresolver/depresolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,15 +603,39 @@ func TestResolveInvalidExtGeoTags(t *testing.T) {
}
}

func TestResolveGeoTagExistsWithinExtGeoTags(t *testing.T) {
func TestResolveOnlyGeoTagExistsWithinExtGeoTags(t *testing.T) {
// arrange
defer cleanup()
tag := "us-west1"
expected := predefinedConfig
expected.ClusterGeoTag = tag
expected.ExtClustersGeoTags = []string{"us-east1", tag}
// act,assert
arrangeVariablesAndAssert(t, expected, assert.Error)
expected.ExtClustersGeoTags = []string{}
configureEnvVar(expected)
os.Setenv(ExtClustersGeoTagsKey, tag)
resolver := NewDependencyResolver()
config, err := resolver.ResolveOperatorConfig()
assert.Error(t, err)
assert.Equal(t, expected, *config)
}

func TestResolveGeoTagExistsWithinExtGeoTags(t *testing.T) {
// arrange
defer cleanup()
tag := "us-west1"
for _, arr := range [][]string{{"good-tag"}, {"us-east1", "eu"}} {
expected := predefinedConfig
expected.ClusterGeoTag = tag
expected.ExtClustersGeoTags = arr
configureEnvVar(expected)
os.Setenv(ExtClustersGeoTagsKey, strings.Join(append(arr, tag), ","))
// act,assert
resolver := NewDependencyResolver()
// act
config, err := resolver.ResolveOperatorConfig()
// assert
assert.NoError(t, err)
assert.Equal(t, expected, *config)
}
}

func TestResolveGeoTagWithRepeatingExtGeoTags(t *testing.T) {
Expand Down Expand Up @@ -1191,6 +1215,27 @@ func TestNsServerNamesWithOneExtClusterGeoTag(t *testing.T) {
assert.Equal(t, config.GetExternalClusterNSNames()["location-2"], "gslb-ns-location-2-k8gb-test-preprod-gslb.cloud.example.com")
}

func TestNsServerNamesWithExtClusterGeoTagsContainingClusterGeoTag(t *testing.T) {
// arrange
defer cleanup()
customConfig := predefinedConfig
customConfig.DNSZone = defaultDNSZone
customConfig.EdgeDNSZone = defaultEdgeDNSZone
customConfig.ClusterGeoTag = defaultClusterGeoTagUs1
customConfig.ExtClustersGeoTags = []string{"location-2", defaultClusterGeoTagUs1}
configureEnvVar(customConfig)
resolver := NewDependencyResolver()

// act
config, err := resolver.ResolveOperatorConfig()

// assert
assert.NoError(t, err)
assert.Len(t, config.GetExternalClusterNSNames(), 1)
assert.Equal(t, "gslb-ns-us-west-1-k8gb-test-preprod-gslb.cloud.example.com", config.GetClusterNSName())
assert.Equal(t, config.GetExternalClusterNSNames()["location-2"], "gslb-ns-location-2-k8gb-test-preprod-gslb.cloud.example.com")
}

func TestNsServerNamesLargeDNSZone(t *testing.T) {
defer cleanup()
// arrange DNSZone exceeds
Expand Down
10 changes: 0 additions & 10 deletions controllers/depresolver/depresolver_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,6 @@ func (v *validator) isHigherThan(num int) *validator {
return v
}

func (v *validator) isNotEqualTo(value string) *validator {
if v.err != nil {
return v
}
if v.strValue == value {
v.err = fmt.Errorf(`'%s' can't be equal to '%s'`, v.name, value)
}
return v
}

func (v *validator) hasItems() *validator {
if v.err != nil {
return v
Expand Down

0 comments on commit 6250f8b

Please sign in to comment.