Skip to content

Commit

Permalink
Merge pull request #5249 from elmiko/remove-capi-labels-taints
Browse files Browse the repository at this point in the history
remove unsupported functionality from cluster-api provider
  • Loading branch information
k8s-ci-robot committed Oct 17, 2022
2 parents 7aba0f4 + bb015b2 commit a1b2c2c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 65 deletions.
7 changes: 7 additions & 0 deletions cluster-autoscaler/cloudprovider/clusterapi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,13 @@ rules:
- list
```

#### Pre-defined labels and taints on nodes scaled from zero

The Cluster API provider currently does not support the addition of pre-defined
labels and taints for node groups that are scaling from zero. This work is on-going
and will be included in a future release once the API for specifying those
labels and taints has been accepted by the community.

## Specifying a Custom Resource Group

By default all Kubernetes resources consumed by the Cluster API provider will
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1281,7 +1281,6 @@ func TestNodeGroupTemplateNodeInfo(t *testing.T) {

type testCaseConfig struct {
nodeLabels map[string]string
nodegroupLabels map[string]string
includeNodes bool
expectedErr error
expectedCapacity map[corev1.ResourceName]int64
Expand Down Expand Up @@ -1309,44 +1308,24 @@ func TestNodeGroupTemplateNodeInfo(t *testing.T) {
},
config: testCaseConfig{
expectedErr: nil,
expectedCapacity: map[corev1.ResourceName]int64{
corev1.ResourceCPU: 2,
corev1.ResourceMemory: 2048 * 1024 * 1024,
corev1.ResourcePods: 110,
gpuapis.ResourceNvidiaGPU: 1,
},
expectedNodeLabels: map[string]string{
nodeLabels: map[string]string{
"kubernetes.io/os": "linux",
"beta.kubernetes.io/os": "linux",
"kubernetes.io/arch": "amd64",
"beta.kubernetes.io/arch": "amd64",
},
},
},
{
name: "When the NodeGroup can scale from zero and the nodegroup adds labels to the Node",
nodeGroupAnnotations: map[string]string{
memoryKey: "2048Mi",
cpuKey: "2",
},
config: testCaseConfig{
expectedErr: nil,
nodegroupLabels: map[string]string{
"nodeGroupLabel": "value",
"anotherLabel": "anotherValue",
},
expectedCapacity: map[corev1.ResourceName]int64{
corev1.ResourceCPU: 2,
corev1.ResourceMemory: 2048 * 1024 * 1024,
corev1.ResourcePods: 110,
corev1.ResourceCPU: 2,
corev1.ResourceMemory: 2048 * 1024 * 1024,
corev1.ResourcePods: 110,
gpuapis.ResourceNvidiaGPU: 1,
},
expectedNodeLabels: map[string]string{
"kubernetes.io/os": "linux",
"beta.kubernetes.io/os": "linux",
"kubernetes.io/arch": "amd64",
"beta.kubernetes.io/arch": "amd64",
"nodeGroupLabel": "value",
"anotherLabel": "anotherValue",
"kubernetes.io/hostname": "random value",
},
},
},
Expand All @@ -1361,39 +1340,29 @@ func TestNodeGroupTemplateNodeInfo(t *testing.T) {
expectedErr: nil,
nodeLabels: map[string]string{
"kubernetes.io/os": "windows",
"beta.kubernetes.io/os": "windows",
"kubernetes.io/arch": "arm64",
"beta.kubernetes.io/arch": "arm64",
"node.kubernetes.io/instance-type": "instance1",
"anotherLabel": "nodeValue", // This should not be copied as it is not a well known label
},
nodegroupLabels: map[string]string{
"nodeGroupLabel": "value",
"anotherLabel": "nodeGroupValue",
},
expectedCapacity: map[corev1.ResourceName]int64{
corev1.ResourceCPU: 2,
corev1.ResourceMemory: 2048 * 1024 * 1024,
corev1.ResourcePods: 110,
},
expectedNodeLabels: map[string]string{
"kubernetes.io/hostname": "random value",
"kubernetes.io/os": "windows",
"beta.kubernetes.io/os": "linux",
"beta.kubernetes.io/os": "windows",
"kubernetes.io/arch": "arm64",
"beta.kubernetes.io/arch": "amd64",
"nodeGroupLabel": "value",
"anotherLabel": "nodeGroupValue",
"beta.kubernetes.io/arch": "arm64",
"node.kubernetes.io/instance-type": "instance1",
},
},
},
}

test := func(t *testing.T, testConfig *testConfig, config testCaseConfig) {
if testConfig.machineDeployment != nil {
unstructured.SetNestedStringMap(testConfig.machineDeployment.Object, config.nodegroupLabels, "spec", "template", "spec", "metadata", "labels")
} else {
unstructured.SetNestedStringMap(testConfig.machineSet.Object, config.nodegroupLabels, "spec", "template", "spec", "metadata", "labels")
}

if config.includeNodes {
for i := range testConfig.nodes {
testConfig.nodes[i].SetLabels(config.nodeLabels)
Expand Down Expand Up @@ -1439,15 +1408,20 @@ func TestNodeGroupTemplateNodeInfo(t *testing.T) {
}
}

// expectedNodeLabels won't have the hostname label as it is randomized, so +1 to its length
if len(nodeInfo.Node().GetLabels()) != len(config.expectedNodeLabels)+1 {
t.Errorf("Expected node labels to have len: %d, but got: %d", len(config.expectedNodeLabels)+1, len(nodeInfo.Node().GetLabels()))
if len(nodeInfo.Node().GetLabels()) != len(config.expectedNodeLabels) {
t.Errorf("Expected node labels to have len: %d, but got: %d, labels are: %v", len(config.expectedNodeLabels), len(nodeInfo.Node().GetLabels()), nodeInfo.Node().GetLabels())
}
for key, value := range nodeInfo.Node().GetLabels() {
// Exclude the hostname label as it is randomized
if key != corev1.LabelHostname {
if expected, ok := config.expectedNodeLabels[key]; ok {
if value != expected {
t.Errorf("Expected node label %q: %q, Got: %q", key, config.expectedNodeLabels[key], value)
}
} else {
t.Errorf("Expected node label %q to exist in node", key)
}
if value != config.expectedNodeLabels[key] {
t.Errorf("Expected node label %q: %q, Got: %q", key, config.expectedNodeLabels[key], value)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,28 +169,16 @@ func (r unstructuredScalableResource) MarkMachineForDeletion(machine *unstructur
}

func (r unstructuredScalableResource) Labels() map[string]string {
labels, found, err := unstructured.NestedStringMap(r.unstructured.Object, "spec", "template", "spec", "metadata", "labels")
if !found || err != nil {
return nil
}
return labels
// TODO implement this once the community has decided how they will handle labels
// this issue is related, https://github.com/kubernetes-sigs/cluster-api/issues/7006

return nil
}

func (r unstructuredScalableResource) Taints() []apiv1.Taint {
taints, found, err := unstructured.NestedSlice(r.unstructured.Object, "spec", "template", "spec", "taints")
if !found || err != nil {
return nil
}
ret := make([]apiv1.Taint, len(taints))
for i, t := range taints {
if v, ok := t.(apiv1.Taint); ok {
ret[i] = v
} else {
// if we cannot convert the interface to a Taint, return early with zero value
return nil
}
}
return ret
// TODO implement this once the community has decided how they will handle taints

return nil
}

// A node group can scale from zero if it can inform about the CPU and memory
Expand Down

0 comments on commit a1b2c2c

Please sign in to comment.