diff --git a/pkg/controller/template/render.go b/pkg/controller/template/render.go index f3726ea351..f21981c36c 100644 --- a/pkg/controller/template/render.go +++ b/pkg/controller/template/render.go @@ -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 @@ -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) diff --git a/pkg/controller/template/render_test.go b/pkg/controller/template/render_test.go index db2e9d0af3..022d9d4ea2 100644 --- a/pkg/controller/template/render_test.go +++ b/pkg/controller/template/render_test.go @@ -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", } ) @@ -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 @@ -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, @@ -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) diff --git a/templates/common/cloud-platform-alt-dns/files/coredns-corefile.yaml b/templates/common/cloud-platform-alt-dns/files/coredns-corefile.yaml index 7d90a7d3fe..2551b16537 100644 --- a/templates/common/cloud-platform-alt-dns/files/coredns-corefile.yaml +++ b/templates/common/cloud-platform-alt-dns/files/coredns-corefile.yaml @@ -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 }} {