Skip to content

Commit 29341ee

Browse files
Merge pull request #7796 from sadasu/CORS-2952
CORS-2952: GCP Set "ClusterHostedDNS" in the Infra CR based on the value of userProvisionedDNS
2 parents 0efc396 + 5d4297a commit 29341ee

File tree

4 files changed

+89
-3
lines changed

4 files changed

+89
-3
lines changed

pkg/asset/manifests/infrastructure.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,13 @@ func (i *Infrastructure) Generate(dependencies asset.Parents) error {
194194
}
195195
config.Status.PlatformStatus.GCP.ResourceTags = resourceTags
196196
}
197+
// If the user has requested the use of a DNS provisioned by them, then OpenShift needs to
198+
// start an in-cluster DNS for the installation to succeed. The user can then configure their
199+
// DNS post-install.
200+
config.Status.PlatformStatus.GCP.ClusterHostedDNS = configv1.DisabledClusterHostedDNS
201+
if installConfig.Config.GCP.UserProvisionedDNS == gcp.UserProvisionedDNSEnabled {
202+
config.Status.PlatformStatus.GCP.ClusterHostedDNS = configv1.EnabledClusterHostedDNS
203+
}
197204
case ibmcloud.Name:
198205
config.Spec.PlatformSpec.Type = configv1.IBMCloudPlatformType
199206
var cisInstanceCRN, dnsInstanceCRN string

pkg/asset/manifests/infrastructure_test.go

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
113147
func (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+
142186
type infraOption func(*configv1.Infrastructure)
143187

144188
type 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+
}

pkg/types/gcp/validation/featuregates.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
configv1 "github.com/openshift/api/config/v1"
77
"github.com/openshift/installer/pkg/types"
88
"github.com/openshift/installer/pkg/types/featuregates"
9+
"github.com/openshift/installer/pkg/types/gcp"
910
)
1011

1112
// GatedFeatures determines all of the install config fields that should
@@ -23,5 +24,10 @@ func GatedFeatures(c *types.InstallConfig) []featuregates.GatedInstallConfigFeat
2324
Condition: len(g.UserTags) > 0,
2425
Field: field.NewPath("platform", "gcp", "userTags"),
2526
},
27+
{
28+
FeatureGateName: configv1.FeatureGateGCPClusterHostedDNS,
29+
Condition: g.UserProvisionedDNS == gcp.UserProvisionedDNSEnabled,
30+
Field: field.NewPath("platform", "gcp", "userProvisionedDNS"),
31+
},
2632
}
2733
}

pkg/types/validation/featuregate_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ func TestFeatureGates(t *testing.T) {
4747
return c
4848
}(),
4949
},
50+
{
51+
name: "GCP UserProvisionedDNS is not allowed without Feature Gates",
52+
installConfig: func() *types.InstallConfig {
53+
c := validInstallConfig()
54+
c.GCP = validGCPPlatform()
55+
c.GCP.UserProvisionedDNS = gcp.UserProvisionedDNSEnabled
56+
return c
57+
}(),
58+
expected: `^platform.gcp.userProvisionedDNS: Forbidden: this field is protected by the GCPClusterHostedDNS feature gate which must be enabled through either the TechPreviewNoUpgrade or CustomNoUpgrade feature set$`,
59+
},
5060
{
5161
name: "GCP UserLabels is not allowed without Feature Gates",
5262
installConfig: func() *types.InstallConfig {

0 commit comments

Comments
 (0)