Skip to content

Commit

Permalink
GCP: Fix issues and update tests when UserProvisionedDNS is enabled
Browse files Browse the repository at this point in the history
Fix issues with CoreDNS Corefile and template path for cloud platforms
when UserProvisionedDNS is enabled.
Add test_data for GCP with all the UserProvisionedDNS configuration
to better test this path.
  • Loading branch information
sadasu committed Feb 5, 2025
1 parent f4b3f01 commit 513164e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 10 deletions.
23 changes: 15 additions & 8 deletions pkg/controller/template/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@ type RenderConfig struct {
}

const (
filesDir = "files"
unitsDir = "units"
platformBase = "_base"
platformOnPrem = "on-prem"
sno = "sno"
masterRole = "master"
workerRole = "worker"
arbiterRole = "arbiter"
filesDir = "files"
unitsDir = "units"
platformBase = "_base"
platformOnPrem = "on-prem"
sno = "sno"
masterRole = "master"
workerRole = "worker"
arbiterRole = "arbiter"
cloudPlatformAltDNS = "cloud-platform-alt-dns"
)

// generateTemplateMachineConfigs returns MachineConfig objects from the templateDir and a config object
Expand Down Expand Up @@ -222,6 +223,12 @@ func getPaths(config *RenderConfig, platformString string) []string {
platformBasedPaths = append(platformBasedPaths, platformOnPrem)
}

// If this is a cloud platform with DNSType set to `ClusterHosted` with
// LB IPs provided, include path for their CoreDNS files
if cloudPlatformLoadBalancerIPState(*config) == availableLBIPState {
platformBasedPaths = append(platformBasedPaths, cloudPlatformAltDNS)
}

// specific platform should be the last one in order
// to override on-prem files in case needed
platformBasedPaths = append(platformBasedPaths, platformString)
Expand Down
43 changes: 43 additions & 0 deletions pkg/controller/template/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ var (
"nutanix": "./test_data/controller_config_nutanix.yaml",
"network-forwarding-sdn": "./test_data/controller_config_forwarding_sdn.yaml",
"network-forwarding-ovn": "./test_data/controller_config_forwarding_ovn.yaml",
"gcp-custom-dns": "./test_data/controller_config_gcp_custom_dns.yaml",
}
)

Expand Down Expand Up @@ -359,6 +360,11 @@ func TestGenerateMachineConfigs(t *testing.T) {
}

func TestGetPaths(t *testing.T) {
APIIntLBIP := configv1.IP("10.10.10.4")
APILBIP := configv1.IP("196.78.125.4")
IngressLBIP1 := configv1.IP("196.78.125.5")
IngressLBIP2 := configv1.IP("10.10.10.5")

cases := []struct {
platform configv1.PlatformType
topology configv1.TopologyMode
Expand All @@ -372,6 +378,11 @@ func TestGetPaths(t *testing.T) {
res: []string{strings.ToLower(string(configv1.BareMetalPlatformType)), "on-prem"},
topology: configv1.HighlyAvailableTopologyMode,
}, {
platform: configv1.GCPPlatformType,
res: []string{strings.ToLower(string(configv1.GCPPlatformType))},
topology: configv1.HighlyAvailableTopologyMode,
}, {

platform: configv1.NonePlatformType,
res: []string{strings.ToLower(string(configv1.NonePlatformType)), sno},
topology: configv1.SingleReplicaTopologyMode,
Expand All @@ -392,6 +403,38 @@ func TestGetPaths(t *testing.T) {
},
},
}
if c.platform == configv1.GCPPlatformType {
config = &mcfgv1.ControllerConfig{
Spec: mcfgv1.ControllerConfigSpec{
Infra: &configv1.Infrastructure{
Status: configv1.InfrastructureStatus{
Platform: c.platform,
PlatformStatus: &configv1.PlatformStatus{
Type: c.platform,
GCP: &configv1.GCPPlatformStatus{
CloudLoadBalancerConfig: &configv1.CloudLoadBalancerConfig{
DNSType: configv1.ClusterHostedDNSType,
ClusterHosted: &configv1.CloudLoadBalancerIPs{
APIIntLoadBalancerIPs: []configv1.IP{
APIIntLBIP,
},
APILoadBalancerIPs: []configv1.IP{
APILBIP,
},
IngressLoadBalancerIPs: []configv1.IP{
IngressLBIP1,
IngressLBIP2,
},
},
},
},
},
ControlPlaneTopology: c.topology,
},
},
},
}
}
c.res = append(c.res, platformBase)

got := getPaths(&RenderConfig{&config.Spec, `{"dummy":"dummy"}`, "dummy", nil, nil}, config.Spec.Platform)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ contents:
}
template IN {{`{{ .Cluster.CloudLBRecordType }}`}} {{ .DNS.Spec.BaseDomain }} {
match ^api.{{ .DNS.Spec.BaseDomain }}
answer "{{`{{"{{ .Name }}"}}`}} 60 in {{`{{"{{ .Type }}"}}`}} {{ if gt (len (cloudPlatformAPILoadBalancerIPs .)) 0 }}{{ index (cloudPlatformAPILoadBalancerIPs) 0 }}{{ end }}"
answer "{{`{{"{{ .Name }}"}}`}} 60 in {{`{{"{{ .Type }}"}}`}} {{ if gt (len (cloudPlatformAPILoadBalancerIPs .)) 0 }}{{ index (cloudPlatformAPILoadBalancerIPs .) 0 }}{{ end }}"
fallthrough
}
template IN {{`{{ .Cluster.CloudLBEmptyType }}`}} {{ .DNS.Spec.BaseDomain }} {
match ^api.{{ .DNS.Spec.BaseDomain }}
{{ if gt (len (cloudPlatformAPILoadBalancerIPs .)) 1 }}answer "{{`{{"{{ .Name }}"}}`}} 60 in {{`{{"{{ .Type }}"}}`}} {{ index (cloudPlatformAPILoadBalancerIPs) 1 }}"{{ end }}
{{ if gt (len (cloudPlatformAPILoadBalancerIPs .)) 1 }}answer "{{`{{"{{ .Name }}"}}`}} 60 in {{`{{"{{ .Type }}"}}`}} {{ index (cloudPlatformAPILoadBalancerIPs .) 1 }}"{{ end }}
fallthrough
}
template IN {{`{{ .Cluster.CloudLBRecordType }}`}} {{ .DNS.Spec.BaseDomain }} {
Expand Down

0 comments on commit 513164e

Please sign in to comment.