From 0060c15cc6fb9a777360d5298e4b4a56bdaa478e Mon Sep 17 00:00:00 2001 From: Sandhya Dasu Date: Fri, 7 Feb 2025 12:57:14 -0500 Subject: [PATCH] GCP: Update unit tests when UserProvisionedDNS is enabled Also add test_data containing ControllerConfig for GCP when DNStype is `ClusterHosted` and all the LB IP values are available. --- pkg/controller/template/render_test.go | 44 +++++++++++++++++++ .../controller_config_gcp_custom_dns.yaml | 36 +++++++++++++++ .../controller_config_gcp_default_dns.yaml | 28 ++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 pkg/controller/template/test_data/controller_config_gcp_custom_dns.yaml create mode 100644 pkg/controller/template/test_data/controller_config_gcp_default_dns.yaml diff --git a/pkg/controller/template/render_test.go b/pkg/controller/template/render_test.go index db2e9d0af3..95c8babaa5 100644 --- a/pkg/controller/template/render_test.go +++ b/pkg/controller/template/render_test.go @@ -216,6 +216,8 @@ 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", + "gcp-default-dns": "./test_data/controller_config_gcp_default_dns.yaml", } ) @@ -359,6 +361,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 +379,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 +404,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/pkg/controller/template/test_data/controller_config_gcp_default_dns.yaml b/pkg/controller/template/test_data/controller_config_gcp_default_dns.yaml new file mode 100644 index 0000000000..ca299ff77a --- /dev/null +++ b/pkg/controller/template/test_data/controller_config_gcp_default_dns.yaml @@ -0,0 +1,28 @@ +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: "PlatformDefault"