@@ -13,6 +13,7 @@ import (
1313 "github.com/openshift/installer/pkg/types"
1414 awstypes "github.com/openshift/installer/pkg/types/aws"
1515 azuretypes "github.com/openshift/installer/pkg/types/azure"
16+ gcptypes "github.com/openshift/installer/pkg/types/gcp"
1617 nonetypes "github.com/openshift/installer/pkg/types/none"
1718)
1819
@@ -21,6 +22,7 @@ func TestGenerateInfrastructure(t *testing.T) {
2122 name string
2223 installConfig * types.InstallConfig
2324 expectedInfrastructure * configv1.Infrastructure
25+ expectedFilesGenerated int
2426 }{{
2527 name : "vanilla aws" ,
2628 installConfig : icBuild .build (icBuild .forAWS ()),
@@ -29,6 +31,7 @@ func TestGenerateInfrastructure(t *testing.T) {
2931 infraBuild .withAWSPlatformSpec (),
3032 infraBuild .withAWSPlatformStatus (),
3133 ),
34+ expectedFilesGenerated : 1 ,
3235 }, {
3336 name : "service endpoints" ,
3437 installConfig : icBuild .build (
@@ -39,6 +42,7 @@ func TestGenerateInfrastructure(t *testing.T) {
3942 infraBuild .forPlatform (configv1 .AWSPlatformType ),
4043 infraBuild .withServiceEndpoint ("service" , "https://endpoint" ),
4144 ),
45+ expectedFilesGenerated : 1 ,
4246 }, {
4347 name : "azure resource tags" ,
4448 installConfig : icBuild .build (
@@ -49,6 +53,26 @@ func TestGenerateInfrastructure(t *testing.T) {
4953 infraBuild .forPlatform (configv1 .AzurePlatformType ),
5054 infraBuild .withResourceTags ([]configv1.AzureResourceTag {{Key : "key" , Value : "value" }}),
5155 ),
56+ expectedFilesGenerated : 1 ,
57+ }, {
58+ name : "default GCP custom DNS" ,
59+ installConfig : icBuild .build (icBuild .forGCP ()),
60+ expectedInfrastructure : infraBuild .build (
61+ infraBuild .forPlatform (configv1 .GCPPlatformType ),
62+ infraBuild .withGCPClusterHostedDNS ("Disabled" ),
63+ ),
64+ expectedFilesGenerated : 2 ,
65+ }, {
66+ name : "GCP custom DNS" ,
67+ installConfig : icBuild .build (
68+ icBuild .forGCP (),
69+ icBuild .withGCPUserProvisionedDNS ("Enabled" ),
70+ ),
71+ expectedInfrastructure : infraBuild .build (
72+ infraBuild .forPlatform (configv1 .GCPPlatformType ),
73+ infraBuild .withGCPClusterHostedDNS ("Enabled" ),
74+ ),
75+ expectedFilesGenerated : 2 ,
5276 }}
5377 for _ , tc := range cases {
5478 t .Run (tc .name , func (t * testing.T ) {
@@ -67,12 +91,13 @@ func TestGenerateInfrastructure(t *testing.T) {
6791 if ! assert .NoError (t , err , "failed to generate asset" ) {
6892 return
6993 }
70- if ! assert .Len (t , infraAsset .FileList , 1 , "expected only one file to be generated" ) {
94+
95+ if ! assert .Len (t , infraAsset .FileList , tc .expectedFilesGenerated , "did not generate expected amount of files" ) {
7196 return
7297 }
73- assert .Equal (t , infraAsset .FileList [0 ].Filename , "manifests/cluster-infrastructure-02-config.yml" )
98+ assert .Equal (t , infraAsset .FileList [tc . expectedFilesGenerated - 1 ].Filename , "manifests/cluster-infrastructure-02-config.yml" )
7499 var actualInfra configv1.Infrastructure
75- err = yaml .Unmarshal (infraAsset .FileList [0 ].Data , & actualInfra )
100+ err = yaml .Unmarshal (infraAsset .FileList [tc . expectedFilesGenerated - 1 ].Data , & actualInfra )
76101 if ! assert .NoError (t , err , "failed to unmarshal infra manifest" ) {
77102 return
78103 }
@@ -110,6 +135,15 @@ func (b icBuildNamespace) forAWS() icOption {
110135 }
111136}
112137
138+ func (b icBuildNamespace ) forGCP () icOption {
139+ return func (ic * types.InstallConfig ) {
140+ if ic .Platform .GCP != nil {
141+ return
142+ }
143+ ic .Platform .GCP = & gcptypes.Platform {}
144+ }
145+ }
146+
113147func (b icBuildNamespace ) forNone () icOption {
114148 return func (ic * types.InstallConfig ) {
115149 if ic .Platform .None != nil {
@@ -139,6 +173,16 @@ func (b icBuildNamespace) withLBType(lbType configv1.AWSLBType) icOption {
139173 }
140174}
141175
176+ func (b icBuildNamespace ) withGCPUserProvisionedDNS (enabled string ) icOption {
177+ return func (ic * types.InstallConfig ) {
178+ b .forGCP ()(ic )
179+ if enabled == "Enabled" {
180+ ic .Platform .GCP .UserProvisionedDNS = gcptypes .UserProvisionedDNSEnabled
181+ ic .FeatureGates = []string {"GCPClusterHostedDNS=true" }
182+ }
183+ }
184+ }
185+
142186type infraOption func (* configv1.Infrastructure )
143187
144188type infraBuildNamespace struct {}
@@ -243,3 +287,22 @@ func (b infraBuildNamespace) withResourceTags(tags []configv1.AzureResourceTag)
243287 infra .Status .PlatformStatus .Azure .ResourceTags = tags
244288 }
245289}
290+
291+ func (b infraBuildNamespace ) withGCPPlatformStatus () infraOption {
292+ return func (infra * configv1.Infrastructure ) {
293+ if infra .Status .PlatformStatus .GCP != nil {
294+ return
295+ }
296+ infra .Status .PlatformStatus .GCP = & configv1.GCPPlatformStatus {}
297+ }
298+ }
299+
300+ func (b infraBuildNamespace ) withGCPClusterHostedDNS (enabled string ) infraOption {
301+ return func (infra * configv1.Infrastructure ) {
302+ b .withGCPPlatformStatus ()(infra )
303+ infra .Status .PlatformStatus .GCP .ClusterHostedDNS = configv1 .DisabledClusterHostedDNS
304+ if enabled == "Enabled" {
305+ infra .Status .PlatformStatus .GCP .ClusterHostedDNS = configv1 .EnabledClusterHostedDNS
306+ }
307+ }
308+ }
0 commit comments