Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Azure: support node label keys having underscores #5116

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cluster-autoscaler/cloudprovider/azure/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ If you are using `nodeSelector`, you need to tag the VMSS with a node-template

To add the label of `foo=bar` to a node from a VMSS pool, you would add the following tag to the VMSS `k8s.io_cluster-autoscaler_node-template_label_foo: bar`.

You can also use forward slashes in the labels by setting them as an underscore in the tag name. For example to add the label of `k8s.io/foo=bar` to a node from a VMSS pool, you would add the following tag to the VMSS `k8s.io_cluster-autoscaler_node-template_label_k8s.io_foo: bar`
You can also use forward slashes in the labels by setting them as an underscore in the tag name. For example to add the label of `k8s.io/foo=bar` to a node from a VMSS pool, you would add the following tag to the VMSS `k8s.io_cluster-autoscaler_node-template_label_k8s.io_foo: bar`. To encode a tag name containing an underscore, use "~2" (eg. "cpu~2arch" gives "cpu_arch").

#### Taints

To add the taint of `foo=bar:NoSchedule` to a node from a VMSS pool, you would add the following tag to the VMSS `k8s.io_cluster-autoscaler_node-template_taint_foo: bar:NoSchedule`.

You can also use forward slashes in taints by setting them as an underscore in the tag name. For example to add the taint of `k8s.io/foo=bar:NoSchedule` to a node from a VMSS pool, you would add the following tag to the VMSS `k8s.io_cluster-autoscaler_node-template_taint_k8s.io_foo: bar:NoSchedule`
You can also use forward slashes in taints by setting them as an underscore in the tag name. For example to add the taint of `k8s.io/foo=bar:NoSchedule` to a node from a VMSS pool, you would add the following tag to the VMSS `k8s.io_cluster-autoscaler_node-template_taint_k8s.io_foo: bar:NoSchedule`. To encode a taint name containing an underscore, use "~2".

#### Resources

Expand Down
3 changes: 3 additions & 0 deletions cluster-autoscaler/cloudprovider/azure/azure_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ func extractLabelsFromScaleSet(tags map[string]*string) map[string]string {
splits := strings.Split(tagName, nodeLabelTagName)
if len(splits) > 1 {
label := strings.Replace(splits[1], "_", "/", -1)
label = strings.Replace(label, "~2", "_", -1)
if label != "" {
result[label] = *tagValue
}
Expand All @@ -188,6 +189,7 @@ func extractTaintsFromScaleSet(tags map[string]*string) []apiv1.Taint {
values := strings.SplitN(*tagValue, ":", 2)
if len(values) > 1 {
taintKey := strings.Replace(splits[1], "_", "/", -1)
taintKey = strings.Replace(taintKey, "~2", "_", -1)
taints = append(taints, apiv1.Taint{
Key: taintKey,
Value: values[0],
Expand Down Expand Up @@ -258,6 +260,7 @@ func extractAllocatableResourcesFromScaleSet(tags map[string]*string) map[string
}

normalizedResourceName := strings.Replace(resourceName[1], "_", "/", -1)
normalizedResourceName = strings.Replace(normalizedResourceName, "~2", "/", -1)
quantity, err := resource.ParseQuantity(*tagValue)
if err != nil {
continue
Expand Down
14 changes: 13 additions & 1 deletion cluster-autoscaler/cloudprovider/azure/azure_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,27 @@ func TestExtractLabelsFromScaleSet(t *testing.T) {
extraNodeLabelValue := "buzz"
blankString := ""

escapedSlashNodeLabelKey := "spam_egg"
escapedSlashNodeLabelValue := "foo"
expectedSlashEscapedNodeLabelKey := "spam/egg"

escapedUnderscoreNodeLabelKey := "foo~2bar"
escapedUnderscoreNodeLabelValue := "egg"
expectedUnderscoreEscapedNodeLabelKey := "foo_bar"

tags := map[string]*string{
fmt.Sprintf("%s%s", nodeLabelTagName, expectedNodeLabelKey): &expectedNodeLabelValue,
"fizz": &extraNodeLabelValue,
"bip": &blankString,
fmt.Sprintf("%s%s", nodeLabelTagName, escapedSlashNodeLabelKey): &escapedSlashNodeLabelValue,
fmt.Sprintf("%s%s", nodeLabelTagName, escapedUnderscoreNodeLabelKey): &escapedUnderscoreNodeLabelValue,
}

labels := extractLabelsFromScaleSet(tags)
assert.Len(t, labels, 1)
assert.Len(t, labels, 3)
assert.Equal(t, expectedNodeLabelValue, labels[expectedNodeLabelKey])
assert.Equal(t, escapedSlashNodeLabelValue, labels[expectedSlashEscapedNodeLabelKey])
assert.Equal(t, escapedUnderscoreNodeLabelValue, labels[expectedUnderscoreEscapedNodeLabelKey])
}

func TestExtractTaintsFromScaleSet(t *testing.T) {
Expand Down