Skip to content

Commit 0896323

Browse files
Merge pull request #10043 from jcpowermac/fix-template-customos-validation
OCPBUGS-63584: vSphere-don't use template,ClusterOSImage together
2 parents fd30059 + fa6ab99 commit 0896323

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

pkg/types/vsphere/validation/platform.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func ValidatePlatform(p *vsphere.Platform, agentBasedInstallation bool, fldPath
4646
if len(p.FailureDomains) == 0 {
4747
return append(allErrs, field.Required(fldPath.Child("failureDomains"), "must be defined"))
4848
}
49-
allErrs = append(allErrs, validateFailureDomains(p, fldPath.Child("failureDomains"), isLegacyUpi)...)
49+
allErrs = append(allErrs, validateFailureDomains(p, fldPath, fldPath.Child("failureDomains"), isLegacyUpi)...)
5050

5151
// Validate hosts if configured for static IP
5252
if p.Hosts != nil {
@@ -68,7 +68,7 @@ func ValidatePlatform(p *vsphere.Platform, agentBasedInstallation bool, fldPath
6868
if p.FailureDomains[0].Name != conversion.GeneratedFailureDomainName &&
6969
p.FailureDomains[0].Zone != conversion.GeneratedFailureDomainZone &&
7070
p.FailureDomains[0].Region != conversion.GeneratedFailureDomainRegion {
71-
allErrs = append(allErrs, validateFailureDomains(p, fldPath.Child("failureDomains"), isLegacyUpi)...)
71+
allErrs = append(allErrs, validateFailureDomains(p, fldPath, fldPath.Child("failureDomains"), isLegacyUpi)...)
7272
}
7373
}
7474
}
@@ -151,7 +151,7 @@ func validateVCenters(p *vsphere.Platform, fldPath *field.Path) field.ErrorList
151151
return allErrs
152152
}
153153

154-
func validateFailureDomains(p *vsphere.Platform, fldPath *field.Path, isLegacyUpi bool) field.ErrorList {
154+
func validateFailureDomains(p *vsphere.Platform, platformFldPath *field.Path, fldPath *field.Path, isLegacyUpi bool) field.ErrorList { //nolint:gocyclo
155155
var fdNames []string
156156
tagUrnPattern := regexp.MustCompile(`^(urn):(vmomi):(InventoryServiceTag):([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}):([^:]+)$`)
157157
allErrs := field.ErrorList{}
@@ -320,6 +320,12 @@ func validateFailureDomains(p *vsphere.Platform, fldPath *field.Path, isLegacyUp
320320
p.FailureDomains[index].Topology.ResourcePool = filepath.Clean(p.FailureDomains[index].Topology.ResourcePool)
321321
}
322322

323+
// Validate that template and clusterOSImage are mutually exclusive
324+
if len(failureDomain.Topology.Template) > 0 && len(p.ClusterOSImage) > 0 {
325+
allErrs = append(allErrs, field.Invalid(topologyFld.Child("template"), failureDomain.Topology.Template, "cannot be specified when clusterOSImage is set"))
326+
allErrs = append(allErrs, field.Invalid(platformFldPath.Child("clusterOSImage"), p.ClusterOSImage, "cannot be specified when failuredomain.topology.template is set"))
327+
}
328+
323329
if len(failureDomain.Topology.Template) > 0 {
324330
p.FailureDomains[index].Topology.Template = filepath.Clean(p.FailureDomains[index].Topology.Template)
325331
}

pkg/types/vsphere/validation/platform_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,32 @@ func TestValidatePlatform(t *testing.T) {
952952
}(),
953953
expectedError: `test-path.failureDomains.topology.networks: Required value: must specify a network`,
954954
},
955+
{
956+
name: "Valid - template without clusterOSImage",
957+
platform: func() *vsphere.Platform {
958+
p := validPlatform()
959+
p.FailureDomains[0].Topology.Template = "/test-datacenter/vm/test-template"
960+
return p
961+
}(),
962+
},
963+
{
964+
name: "Valid - clusterOSImage without template",
965+
platform: func() *vsphere.Platform {
966+
p := validPlatform()
967+
p.ClusterOSImage = "http://example.com/rhcos.ova"
968+
return p
969+
}(),
970+
},
971+
{
972+
name: "Invalid - both template and clusterOSImage",
973+
platform: func() *vsphere.Platform {
974+
p := validPlatform()
975+
p.FailureDomains[0].Topology.Template = "/test-datacenter/vm/test-template"
976+
p.ClusterOSImage = "http://example.com/rhcos.ova"
977+
return p
978+
}(),
979+
expectedError: `test-path.failureDomains.topology.template: Invalid value: "/test-datacenter/vm/test-template": cannot be specified when clusterOSImage is set, test-path.clusterOSImage: Invalid value: "http://example.com/rhcos.ova": cannot be specified when failuredomain.topology.template is set`,
980+
},
955981
}
956982
for _, tc := range cases {
957983
t.Run(tc.name, func(t *testing.T) {

0 commit comments

Comments
 (0)