Skip to content

Commit 7d5d26a

Browse files
committed
allow assignment of additional tags
1 parent 9d34929 commit 7d5d26a

File tree

5 files changed

+48
-0
lines changed

5 files changed

+48
-0
lines changed

data/data/install.openshift.io_installconfigs.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4420,6 +4420,14 @@ spec:
44204420
minLength: 1
44214421
pattern: ^/.*?/host/.*?/Resources.*
44224422
type: string
4423+
tagIDs:
4424+
description: tagIDs is an optional set of tags to add
4425+
to an instance. Specified tagIDs must use URN-notation
4426+
instead of display names. A maximum of 10 tag IDs
4427+
may be specified.
4428+
items:
4429+
type: string
4430+
type: array
44234431
template:
44244432
description: template is the inventory path of the virtual
44254433
machine or template that will be used for cloning.

pkg/asset/machines/vsphere/machines.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ func provider(clusterID string, vcenter *vsphere.VCenter, failureDomain vsphere.
247247
Folder: folder,
248248
ResourcePool: resourcePool,
249249
},
250+
TagIDs: failureDomain.Topology.TagIDs,
250251
NumCPUs: mpool.NumCPUs,
251252
NumCoresPerSocket: mpool.NumCoresPerSocket,
252253
MemoryMiB: mpool.MemoryMiB,

pkg/types/vsphere/platform.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,11 @@ type Topology struct {
212212
// +kubebuilder:validation:Pattern=`^/.*?/vm/.*?`
213213
// +optional
214214
Template string `json:"template,omitempty"`
215+
// tagIDs is an optional set of tags to add to an instance. Specified tagIDs
216+
// must use URN-notation instead of display names. A maximum of 10 tag IDs may be specified.
217+
// +kubebuilder:example=urn:vmomi:InventoryServiceTag:5736bf56-49f5-4667-b38c-b97e09dc9578:GLOBAL
218+
// +optional
219+
TagIDs []string `json:"tagIDs,omitempty"`
215220
}
216221

217222
// VCenter stores the vCenter connection fields

pkg/types/vsphere/validation/platform.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ func validateVCenters(p *vsphere.Platform, fldPath *field.Path) field.ErrorList
117117

118118
func validateFailureDomains(p *vsphere.Platform, fldPath *field.Path, isLegacyUpi bool) field.ErrorList {
119119
var fdNames []string
120+
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}):([^:]+)$`)
120121
allErrs := field.ErrorList{}
121122
topologyFld := fldPath.Child("topology")
122123
var associatedVCenter *vsphere.VCenter
@@ -172,6 +173,16 @@ func validateFailureDomains(p *vsphere.Platform, fldPath *field.Path, isLegacyUp
172173
}
173174
}
174175

176+
if len(failureDomain.Topology.TagIDs) > 10 {
177+
allErrs = append(allErrs, field.Invalid(topologyFld.Child("tagIDs"), failureDomain.Topology.TagIDs, "a maximum of 10 tags are allowed"))
178+
}
179+
180+
for _, tagID := range failureDomain.Topology.TagIDs {
181+
if tagUrnPattern.FindStringSubmatch(tagID) == nil {
182+
allErrs = append(allErrs, field.Invalid(topologyFld.Child("tagIDs"), failureDomain.Topology.TagIDs, "tag ID must be in the format of urn:vmomi:InventoryServiceTag:<UUID>:GLOBAL"))
183+
}
184+
}
185+
175186
if len(failureDomain.Topology.Networks) == 0 {
176187
if isLegacyUpi {
177188
logrus.Warn("network field empty is now deprecated, in later releases this field will be required.")

pkg/types/vsphere/validation/platform_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,29 @@ func TestValidatePlatform(t *testing.T) {
194194
}(),
195195
expectedError: `^test-path\.diskType: Invalid value: "invalidDiskType": diskType must be one of \[eagerZeroedThick thick thin\]$`,
196196
},
197+
{
198+
name: "Additional tag IDs provided",
199+
platform: func() *vsphere.Platform {
200+
p := validPlatform()
201+
p.FailureDomains[0].Topology.TagIDs = []string{
202+
"urn:vmomi:InventoryServiceTag:5736bf56-49f5-4667-b38c-b97e09dc9578:GLOBAL",
203+
"urn:vmomi:InventoryServiceTag:5736bf56-49f5-4667-b38c-b97e09dc9579:GLOBAL",
204+
}
205+
return p
206+
}(),
207+
},
208+
{
209+
name: "Additional invalid tag IDs provided",
210+
platform: func() *vsphere.Platform {
211+
p := validPlatform()
212+
p.FailureDomains[0].Topology.TagIDs = []string{
213+
"urn:bad:InventoryServiceTag:5736bf56-49f5-4667-b38c-b97e09dc9578:GLOBAL",
214+
"urn:bad:InventoryServiceTag:5736bf56-49f5-4667-b38c-b97e09dc9579:GLOBAL",
215+
}
216+
return p
217+
}(),
218+
expectedError: `^test-path\.failureDomains\.topology\.tagIDs\: Invalid value\:.*?: tag ID must be in the format of urn\:vmomi\:InventoryServiceTag\:<UUID>\:GLOBAL$`,
219+
},
197220

198221
{
199222
name: "Valid Multi-zone platform",

0 commit comments

Comments
 (0)