From 1bb98dc6382e73a145b769aa2e6ca1074022915d Mon Sep 17 00:00:00 2001 From: Sandhya Dasu Date: Wed, 5 Feb 2025 12:08:38 -0500 Subject: [PATCH] GCP: Fix issues and update tests when UserProvisionedDNS is enabled 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. --- pkg/controller/template/render.go | 23 ++++++---- pkg/controller/template/render_test.go | 43 +++++++++++++++++++ .../controller_config_gcp_custom_dns.yaml | 36 ++++++++++++++++ .../files/coredns-corefile.yaml | 4 +- 4 files changed, 96 insertions(+), 10 deletions(-) create mode 100644 pkg/controller/template/test_data/controller_config_gcp_custom_dns.yaml 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/pkg/controller/template/test_data/controller_config_gcp_custom_dns.yaml b/pkg/controller/template/test_data/controller_config_gcp_custom_dns.yaml new file mode 100644 index 0000000000..c133224e72 --- /dev/null +++ b/pkg/controller/template/test_data/controller_config_gcp_custom_dns.yaml @@ -0,0 +1,36 @@ +apiVersion: "machineconfigurations.openshift.io/v1" +kind: "ControllerConfig" +spec: + clusterDNSIP: "10.3.0.10" + cloudProviderConfig: "" + etcdInitialCount: 3 + etcdCAData: ZHVtbXkgZXRjZC1jYQo= + rootCAData: ZHVtbXkgcm9vdC1jYQo= + pullSecret: + data: ZHVtbXkgZXRjZC1jYQo= + images: + etcd: image/etcd:1 + setupEtcdEnv: image/setupEtcdEnv:1 + infraImage: image/infraImage:1 + kubeClientAgentImage: image/kubeClientAgentImage:1 + infra: + apiVersion: config.openshift.io/v1 + kind: Infrastructure + status: + apiServerInternalURI: https://api-int.my-test-cluster.installer.team.coreos.systems:6443 + apiServerURL: https://api.my-test-cluster.installer.team.coreos.systems:6443 + etcdDiscoveryDomain: my-test-cluster.installer.team.coreos.systems + infrastructureName: my-test-cluster + platformStatus: + type: "GCP" + gcp: + cloudLoadBalancerConfig: + dnsType: "ClusterHosted" + clusterHosted: + apiLoadBalancerIPs: + - 20.20.20.20 + apiIntLoadBalancerIPs: + - 10.10.10.10 + dns: + spec: + baseDomain: my-test-cluster.installer.team.coreos.systems 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 }} {