Skip to content

Commit 1dbf083

Browse files
authored
Merge pull request kubernetes#126772 from fidelity-contributions/fix-issue-126453
cloud-provider: Fix regex format to escape dot . to match it as string
2 parents 2ca0eb3 + 7528e08 commit 1dbf083

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

staging/src/k8s.io/cloud-provider/controllers/node/node_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ func (cnc *CloudNodeController) getNodeModifiersFromCloudProvider(
550550
n.Labels = map[string]string{}
551551
}
552552

553-
k8sNamespaceRegex := regexp.MustCompile("(kubernetes|k8s).io/")
553+
k8sNamespaceRegex := regexp.MustCompile(`(^|\.)(kubernetes|k8s)\.io/`)
554554
for k, v := range instanceMeta.AdditionalLabels {
555555
// Cloud provider should not be using kubernetes namespaces in labels
556556
if isK8sNamespace := k8sNamespaceRegex.MatchString(k); isK8sNamespace {

staging/src/k8s.io/cloud-provider/controllers/node/node_controller_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,9 +1598,14 @@ func Test_syncNode(t *testing.T) {
15981598
// and should be discarded
15991599
"topology.kubernetes.io/region": "us-other-west",
16001600
"topology.k8s.io/region": "us-other-west",
1601+
"kubernetes.io/region": "us-other-west",
1602+
"k8s.io/region": "us-other-west",
16011603
// Should discard labels that already exist
16021604
"my.custom.label/foo": "bar",
16031605
"my.custom.label/bar": "foo",
1606+
// Should add labels that not match regex
1607+
"app.k8snio/bar": "foo",
1608+
"k8snio/bar": "foo",
16041609
},
16051610
},
16061611
existingNode: &v1.Node{
@@ -1661,6 +1666,8 @@ func Test_syncNode(t *testing.T) {
16611666
"topology.kubernetes.io/zone": "us-west-1a",
16621667
"my.custom.label/foo": "fizz",
16631668
"my.custom.label/bar": "foo",
1669+
"app.k8snio/bar": "foo",
1670+
"k8snio/bar": "foo",
16641671
},
16651672
},
16661673
Spec: v1.NodeSpec{

0 commit comments

Comments
 (0)