mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-10 12:32:03 +00:00
cloud-provider: Fix regex format to escape dot . to match it as string
This allows additional labels with name like app.k8snio/name to be added Signed-off-by: Wang, Shu <shu.wang@fmr.com>
This commit is contained in:
parent
7de63a887f
commit
7528e08875
@ -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 {
|
||||
|
@ -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{
|
||||
|
Loading…
Reference in New Issue
Block a user