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

Visualization: current version differences for 1.30 - master #3

Draft
wants to merge 1 commit into
base: cluster-autoscaler-release-1.30
Choose a base branch
from
Draft
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

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only trivial changes in this file.

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`. To encode a tag name containing an underscore, use "~2" (eg. "cpu~2arch" gives "cpu_arch").
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`. To encode a taint name containing an underscore, use "~2".
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
64 changes: 55 additions & 9 deletions cluster-autoscaler/cloudprovider/azure/azure_autodiscovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,31 @@ package azure

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did not recognize all in this file. Need evaluation

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import (
"fmt"
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider"
"strconv"
"strings"

"k8s.io/autoscaler/cluster-autoscaler/cloudprovider"
)

const (
autoDiscovererTypeLabel = "label"
autoDiscovererTypeLabel = "label"
vmssAutoDiscovererKeyMinNodes = "min"
vmssAutoDiscovererKeyMaxNodes = "max"
)

// A labelAutoDiscoveryConfig specifies how to auto-discover Azure node groups.
type labelAutoDiscoveryConfig struct {
// Key-values to match on.
Selector map[string]string
// MinSize specifies the minimum size for all VMSSs that match Selector.
MinSize *int
// MazSize specifies the maximum size for all VMSSs that match Selector.
MaxSize *int
}

type autoDiscoveryConfigSizes struct {
Min int
Max int
}

// ParseLabelAutoDiscoverySpecs returns any provided NodeGroupAutoDiscoverySpecs
Expand Down Expand Up @@ -70,34 +83,67 @@ func parseLabelAutoDiscoverySpec(spec string) (labelAutoDiscoveryConfig, error)
if k == "" || v == "" {
return cfg, fmt.Errorf("empty value not allowed in key=value tag pairs")
}
cfg.Selector[k] = v

switch k {
case vmssAutoDiscovererKeyMinNodes:
minSize, err := strconv.Atoi(v)
if err != nil || minSize < 0 {
return cfg, fmt.Errorf("invalid minimum nodes: %s", v)
}
cfg.MinSize = &minSize
case vmssAutoDiscovererKeyMaxNodes:
maxSize, err := strconv.Atoi(v)
if err != nil || maxSize < 0 {
return cfg, fmt.Errorf("invalid maximum nodes: %s", v)
}
cfg.MaxSize = &maxSize
default:
cfg.Selector[k] = v
}
}
if cfg.MaxSize != nil && cfg.MinSize != nil && *cfg.MaxSize < *cfg.MinSize {
return cfg, fmt.Errorf("maximum size %d must be greater than or equal to minimum size %d", *cfg.MaxSize, *cfg.MinSize)
}
return cfg, nil
}

func matchDiscoveryConfig(labels map[string]*string, configs []labelAutoDiscoveryConfig) bool {
// returns an autoDiscoveryConfigSizes struct if the VMSS's tags match the autodiscovery configs
// if the VMSS's tags do not match then return nil
// if there are multiple min/max sizes defined, return the highest min value and the lowest max value
func matchDiscoveryConfig(labels map[string]*string, configs []labelAutoDiscoveryConfig) *autoDiscoveryConfigSizes {
if len(configs) == 0 {
return false
return nil
}
minSize := -1
maxSize := -1

for _, c := range configs {
if len(c.Selector) == 0 {
return false
return nil
}

for k, v := range c.Selector {
value, ok := labels[k]
if !ok {
return false
return nil
}

if v != "" {
if value == nil || *value != v {
return false
return nil
}
}
}
if c.MinSize != nil && minSize < *c.MinSize {
minSize = *c.MinSize
}
if c.MaxSize != nil && (maxSize == -1 || maxSize > *c.MaxSize) {
maxSize = *c.MaxSize
}
}

return true
return &autoDiscoveryConfigSizes{
Min: minSize,
Max: maxSize,
}
}
71 changes: 69 additions & 2 deletions cluster-autoscaler/cloudprovider/azure/azure_autodiscovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ limitations under the License.
package azure

import (
"testing"

"github.com/stretchr/testify/assert"
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider"
"testing"
)

func TestParseLabelAutoDiscoverySpecs(t *testing.T) {
minVal := 1
maxVal := 2
testCases := []struct {
name string
specs []string
Expand All @@ -46,7 +49,7 @@ func TestParseLabelAutoDiscoverySpecs(t *testing.T) {
expectedErr: true,
},
{
name: "InvalidAutoDiscoerLabel",
name: "InvalidAutoDiscoverLabel",
specs: []string{"invalid:test-tag=test-value,another-test-tag"},
expectedErr: true,
},
Expand All @@ -60,6 +63,70 @@ func TestParseLabelAutoDiscoverySpecs(t *testing.T) {
specs: []string{"label:=test-val"},
expectedErr: true,
},
{
name: "ValidSpecWithSizes",
specs: []string{
"label:cluster-autoscaler-enabled=true,cluster-autoscaler-name=fake-cluster,min=1,max=2",
"label:test-tag=test-value,another-test-tag=another-test-value,min=1,max=2",
},
expected: []labelAutoDiscoveryConfig{
{Selector: map[string]string{"cluster-autoscaler-enabled": "true", "cluster-autoscaler-name": "fake-cluster"}, MinSize: &minVal, MaxSize: &maxVal},
{Selector: map[string]string{"test-tag": "test-value", "another-test-tag": "another-test-value"}, MinSize: &minVal, MaxSize: &maxVal},
},
},
{
name: "ValidSpecWithSizesOnlyMax",
specs: []string{
"label:cluster-autoscaler-enabled=true,max=2",
},
expected: []labelAutoDiscoveryConfig{
{Selector: map[string]string{"cluster-autoscaler-enabled": "true"}, MaxSize: &maxVal},
},
},
{
name: "ValidSpecWithSizesOnlyMin",
specs: []string{
"label:cluster-autoscaler-enabled=true,min=1",
},
expected: []labelAutoDiscoveryConfig{
{Selector: map[string]string{"cluster-autoscaler-enabled": "true"}, MinSize: &minVal},
},
},
{
name: "NonIntegerMin",
specs: []string{
"label:cluster-autoscaler-enabled=true,min=random,max=2",
},
expectedErr: true,
},
{
name: "NegativeMin",
specs: []string{
"label:cluster-autoscaler-enabled=true,min=-5,max=2",
},
expectedErr: true,
},
{
name: "NonIntegerMax",
specs: []string{
"label:cluster-autoscaler-enabled=true,min=1,max=random",
},
expectedErr: true,
},
{
name: "NegativeMax",
specs: []string{
"label:cluster-autoscaler-enabled=true,min=1,max=-5",
},
expectedErr: true,
},
{
name: "LowerMaxThanMin",
specs: []string{
"label:cluster-autoscaler-enabled=true,min=5,max=1",
},
expectedErr: true,
},
}

for _, tc := range testCases {
Expand Down
Loading
Loading