Merge pull request #126772 from fidelity-contributions/fix-issue-126453

cloud-provider: Fix regex format to escape dot . to match it as string
This commit is contained in:
Kubernetes Prow Robot 2024-09-06 04:24:22 +01:00 committed by GitHub
commit 1dbf0830c5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 1 deletions

View File

@ -550,7 +550,7 @@ func (cnc *CloudNodeController) getNodeModifiersFromCloudProvider(
n.Labels = map[string]string{}
}
k8sNamespaceRegex := regexp.MustCompile("(kubernetes|k8s).io/")
k8sNamespaceRegex := regexp.MustCompile(`(^|\.)(kubernetes|k8s)\.io/`)
for k, v := range instanceMeta.AdditionalLabels {
// Cloud provider should not be using kubernetes namespaces in labels
if isK8sNamespace := k8sNamespaceRegex.MatchString(k); isK8sNamespace {

View File

@ -1598,9 +1598,14 @@ func Test_syncNode(t *testing.T) {
// and should be discarded
"topology.kubernetes.io/region": "us-other-west",
"topology.k8s.io/region": "us-other-west",
"kubernetes.io/region": "us-other-west",
"k8s.io/region": "us-other-west",
// Should discard labels that already exist
"my.custom.label/foo": "bar",
"my.custom.label/bar": "foo",
// Should add labels that not match regex
"app.k8snio/bar": "foo",
"k8snio/bar": "foo",
},
},
existingNode: &v1.Node{
@ -1661,6 +1666,8 @@ func Test_syncNode(t *testing.T) {
"topology.kubernetes.io/zone": "us-west-1a",
"my.custom.label/foo": "fizz",
"my.custom.label/bar": "foo",
"app.k8snio/bar": "foo",
"k8snio/bar": "foo",
},
},
Spec: v1.NodeSpec{