Skip to content

Commit 42df94a

Browse files
authored
controller, util: make validLabelsMatch regex more lax (#3869)
Previously certain allowed (kubevirt.io) labels that included dots after the / delimiter would be ignored as the expression only matched one or more letters/digits/underscore/dashes. This commit adds dots to the list of allowed symbols. Signed-off-by: Adi Aloni <[email protected]>
1 parent 6d6517a commit 42df94a

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

pkg/controller/common/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ var (
392392
AnnPodMultusDefaultNetwork: "",
393393
}
394394

395-
validLabelsMatch = regexp.MustCompile(`^([\w.]+\.kubevirt.io|kubevirt.io)/[\w-]+$`)
395+
validLabelsMatch = regexp.MustCompile(`^([\w.]+\.kubevirt.io|kubevirt.io)/[\w.-]+$`)
396396

397397
ErrDataSourceMaxDepthReached = errors.New("DataSource reference chain exceeds maximum depth of 1")
398398
ErrDataSourceSelfReference = errors.New("DataSource cannot self-reference")

pkg/controller/common/util_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,18 +328,22 @@ var _ = Describe("CopyAllowedLabels", func() {
328328
testKubevirtIoValueExisting = "existing"
329329
testKubevirtIoNewValueExisting = "newvalue"
330330
testUndesiredKey = "undesired.key"
331+
testCdiDatasourceKey = "cdi.kubevirt.io/storage.import.datasource-name"
332+
testCdiDatasourceKeyValue = "testdatasource"
331333
)
332334

333335
It("Should copy desired labels", func() {
334336
srcLabels := map[string]string{
335337
testKubevirtIoKey: testKubevirtIoValue,
336338
testInstancetypeKubevirtIoKey: testInstancetypeKubevirtIoValue,
337339
testUndesiredKey: "undesired.key",
340+
testCdiDatasourceKey: testCdiDatasourceKeyValue,
338341
}
339342
ds := &cdiv1.DataSource{}
340343
CopyAllowedLabels(srcLabels, ds, false)
341344
Expect(ds.Labels).To(HaveKeyWithValue(testKubevirtIoKey, testKubevirtIoValue))
342345
Expect(ds.Labels).To(HaveKeyWithValue(testInstancetypeKubevirtIoKey, testInstancetypeKubevirtIoValue))
346+
Expect(ds.Labels).To(HaveKeyWithValue(testCdiDatasourceKey, testCdiDatasourceKeyValue))
343347
Expect(ds.Labels).ToNot(HaveKey(testUndesiredKey))
344348
})
345349

0 commit comments

Comments
 (0)