Skip to content
Open
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
2 changes: 1 addition & 1 deletion cluster-autoscaler/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
FROM --platform=$BUILDPLATFORM golang:1.24 AS builder
FROM --platform=$BUILDPLATFORM golang:1.25 AS builder

WORKDIR /workspace

Expand Down
53 changes: 26 additions & 27 deletions cluster-autoscaler/apis/go.mod
Original file line number Diff line number Diff line change
@@ -1,61 +1,60 @@
module k8s.io/autoscaler/cluster-autoscaler/apis

go 1.24.0
go 1.25.0

require (
github.com/onsi/ginkgo/v2 v2.21.0
github.com/onsi/gomega v1.35.1
k8s.io/apimachinery v0.34.1
k8s.io/client-go v0.34.1
k8s.io/code-generator v0.34.1
github.com/onsi/ginkgo/v2 v2.27.2
github.com/onsi/gomega v1.38.2
k8s.io/apimachinery v0.35.0-beta.0
k8s.io/client-go v0.35.0-beta.0
k8s.io/code-generator v0.35.0-beta.0
sigs.k8s.io/structured-merge-diff/v6 v6.3.0
)

require (
github.com/Masterminds/semver/v3 v3.4.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emicklei/go-restful/v3 v3.12.2 // indirect
github.com/fxamacker/cbor/v2 v2.9.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/logr v1.4.3 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/gnostic-models v0.7.0 // indirect
github.com/google/go-cmp v0.7.0 // indirect
github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db // indirect
github.com/google/pprof v0.0.0-20250403155104-27863c87afa6 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/pflag v1.0.6 // indirect
github.com/spf13/pflag v1.0.9 // indirect
github.com/x448/float16 v0.8.4 // indirect
go.yaml.in/yaml/v2 v2.4.2 // indirect
go.yaml.in/yaml/v2 v2.4.3 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
golang.org/x/mod v0.21.0 // indirect
golang.org/x/net v0.38.0 // indirect
golang.org/x/oauth2 v0.27.0 // indirect
golang.org/x/sync v0.12.0 // indirect
golang.org/x/sys v0.31.0 // indirect
golang.org/x/term v0.30.0 // indirect
golang.org/x/text v0.23.0 // indirect
golang.org/x/mod v0.28.0 // indirect
golang.org/x/net v0.43.0 // indirect
golang.org/x/oauth2 v0.30.0 // indirect
golang.org/x/sync v0.17.0 // indirect
golang.org/x/sys v0.37.0 // indirect
golang.org/x/term v0.36.0 // indirect
golang.org/x/text v0.29.0 // indirect
golang.org/x/time v0.9.0 // indirect
golang.org/x/tools v0.26.0 // indirect
google.golang.org/protobuf v1.36.5 // indirect
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
golang.org/x/tools v0.36.0 // indirect
google.golang.org/protobuf v1.36.8 // indirect
gopkg.in/evanphx/json-patch.v4 v4.13.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.34.1 // indirect
k8s.io/gengo/v2 v2.0.0-20250604051438-85fd79dbfd9f // indirect
k8s.io/api v0.35.0-beta.0 // indirect
k8s.io/gengo/v2 v2.0.0-20250922181213-ec3ebc5fd46b // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kube-openapi v0.0.0-20250710124328-f3f2b991d03b // indirect
k8s.io/utils v0.0.0-20250604170112-4c0f3b243397 // indirect
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect
k8s.io/kube-openapi v0.0.0-20250910181357-589584f1c912 // indirect
k8s.io/utils v0.0.0-20251002143259-bc988d571ff4 // indirect
sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730 // indirect
sigs.k8s.io/randfill v1.0.0 // indirect
sigs.k8s.io/yaml v1.6.0 // indirect
)
165 changes: 80 additions & 85 deletions cluster-autoscaler/apis/go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cluster-autoscaler/cloudprovider/azure/test/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -484,4 +484,4 @@ sigs.k8s.io/randfill v1.0.0/go.mod h1:XeLlZ/jmk4i1HRopwe7/aU3H5n1zNUcX6TM94b3QxO
sigs.k8s.io/structured-merge-diff/v4 v4.7.0 h1:qPeWmscJcXP0snki5IYF79Z8xrl8ETFxgMd7wez1XkI=
sigs.k8s.io/structured-merge-diff/v4 v4.7.0/go.mod h1:dDy58f92j70zLsuZVuUX5Wp9vtxXpaZnkPGWeqDfCps=
sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=
sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY=
sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY=
34 changes: 29 additions & 5 deletions cluster-autoscaler/cloudprovider/clusterapi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,30 @@ metadata:
> Please see the [Cluster API Book chapter on Metadata propagation](https://cluster-api.sigs.k8s.io/reference/api/metadata-propagation)
> for more information.


#### Pre-defined csi driver information on nodes scaled from zero

To provide CSI driver information for scale from zero, the optional
capacity annotation may be supplied as a comma separated list of driver name
and volume limit key/value pairs, as demonstrated in the example below:

```yaml
apiVersion: cluster.x-k8s.io/v1alpha4
kind: MachineDeployment
metadata:
annotations:
cluster.x-k8s.io/cluster-api-autoscaler-node-group-max-size: "5"
cluster.x-k8s.io/cluster-api-autoscaler-node-group-min-size: "0"
capacity.cluster-autoscaler.kubernetes.io/memory: "128G"
capacity.cluster-autoscaler.kubernetes.io/cpu: "16"
capacity.cluster-autoscaler.kubernetes.io/csi-driver: "ebs.csi.aws.com=25,efs.csi.aws.com=16"
```

> Note: The CSI driver information supplied through the capacity annotation
> specifies which CSI drivers will be installed on nodes scaled from zero, along
> with their respective volume limits. The format is `driver-name=volume-limit`
> with multiple drivers separated by commas.

#### Per-NodeGroup autoscaling options

Custom autoscaling options per node group (MachineDeployment/MachinePool/MachineSet) can be specified as annoations with a common prefix:
Expand All @@ -328,14 +352,14 @@ metadata:
cluster.x-k8s.io/autoscaling-options-maxnodeprovisiontime: "20m0s"
```

#### CPU Architecture awareness for single-arch clusters
#### CPU Architecture awareness for single-arch clusters

Users of single-arch non-amd64 clusters who are using scale from zero
Users of single-arch non-amd64 clusters who are using scale from zero
support should also set the `CAPI_SCALE_ZERO_DEFAULT_ARCH` environment variable
to set the architecture of the nodes they want to default the node group templates to.
The autoscaler will default to `amd64` if it is not set, and the node
group templates may not match the nodes' architecture, specifically when
the workload triggering the scale-up uses a node affinity predicate checking
The autoscaler will default to `amd64` if it is not set, and the node
group templates may not match the nodes' architecture, specifically when
the workload triggering the scale-up uses a node affinity predicate checking
for the node's architecture.

## Specifying a Custom Resource Group
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,12 @@ func (ng *nodegroup) TemplateNodeInfo() (*framework.NodeInfo, error) {
if err != nil {
return nil, err
}
csiNode := ng.scalableResource.InstanceCSINode()

nodeInfo := framework.NewNodeInfo(&node, resourceSlices, &framework.PodInfo{Pod: cloudprovider.BuildKubeProxy(ng.scalableResource.Name())})
if csiNode != nil {
nodeInfo.AddCSINode(csiNode)
}
return nodeInfo, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ import (

"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
storagev1 "k8s.io/api/storage/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider"
"k8s.io/autoscaler/cluster-autoscaler/config"
gpuapis "k8s.io/autoscaler/cluster-autoscaler/utils/gpu"
"k8s.io/client-go/tools/cache"
"k8s.io/utils/ptr"
)

const (
Expand Down Expand Up @@ -1500,6 +1502,7 @@ func TestNodeGroupTemplateNodeInfo(t *testing.T) {
expectedCapacity map[corev1.ResourceName]int64
expectedNodeLabels map[string]string
expectedResourceSlice testResourceSlice
expectedCSINode *storagev1.CSINode
}

testCases := []struct {
Expand Down Expand Up @@ -1650,6 +1653,49 @@ func TestNodeGroupTemplateNodeInfo(t *testing.T) {
},
},
},
{
name: "When the NodeGroup can scale from zero and CSI driver annotations are present, it creates CSINode with driver information",
nodeGroupAnnotations: map[string]string{
memoryKey: "2048Mi",
cpuKey: "2",
csiDriverKey: "ebs.csi.aws.com=25,efs.csi.aws.com=16",
},
config: testCaseConfig{
expectedErr: nil,
nodeLabels: map[string]string{
"kubernetes.io/os": "linux",
"kubernetes.io/arch": "amd64",
},
expectedCapacity: map[corev1.ResourceName]int64{
corev1.ResourceCPU: 2,
corev1.ResourceMemory: 2048 * 1024 * 1024,
corev1.ResourcePods: 110,
},
expectedNodeLabels: map[string]string{
"kubernetes.io/os": "linux",
"kubernetes.io/arch": "amd64",
"kubernetes.io/hostname": "random value",
},
expectedCSINode: &storagev1.CSINode{
Spec: storagev1.CSINodeSpec{
Drivers: []storagev1.CSINodeDriver{
{
Name: "ebs.csi.aws.com",
Allocatable: &storagev1.VolumeNodeResources{
Count: ptr.To(int32(25)),
},
},
{
Name: "efs.csi.aws.com",
Allocatable: &storagev1.VolumeNodeResources{
Count: ptr.To(int32(16)),
},
},
},
},
},
},
},
}

test := func(t *testing.T, testConfig *TestConfig, config testCaseConfig) {
Expand Down Expand Up @@ -1726,6 +1772,55 @@ func TestNodeGroupTemplateNodeInfo(t *testing.T) {
}
}
}

// Validate CSINode if expected
if config.expectedCSINode != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

These nested conditions are extremely hard to read, and while in principle I can understand what's supposed to happen here - it's hard to analyse and likely debug. I would advice to move that to helper function and use short-circuit returns for such validation

if config.expectedCSINode == nil || nodeInfo.CSINode == nil 
{
  ...check that nil value match
  return fmt.Errorf("...")
}

if len(expectedDrivers) != len(gotDrivers) {
  return fmt.Errorf("...")
}

Same can be done for the rest of the config

if nodeInfo.CSINode == nil {
t.Errorf("Expected CSINode to be set, but got nil")
} else {
expectedDrivers := config.expectedCSINode.Spec.Drivers
gotDrivers := nodeInfo.CSINode.Spec.Drivers
if len(expectedDrivers) != len(gotDrivers) {
t.Errorf("Expected %d CSI drivers, but got %d", len(expectedDrivers), len(gotDrivers))
} else {
for i, expectedDriver := range expectedDrivers {
if i >= len(gotDrivers) {
t.Errorf("Expected driver at index %d but got only %d drivers", i, len(gotDrivers))
break
}
gotDriver := gotDrivers[i]
if expectedDriver.Name != gotDriver.Name {
t.Errorf("Expected CSI driver name at index %d to be %s, but got %s", i, expectedDriver.Name, gotDriver.Name)
}
if expectedDriver.Allocatable == nil {
if gotDriver.Allocatable != nil {
t.Errorf("Expected CSI driver Allocatable at index %d to be nil, but got non-nil", i)
}
} else {
if gotDriver.Allocatable == nil {
t.Errorf("Expected CSI driver Allocatable at index %d to be non-nil, but got nil", i)
} else {
if expectedDriver.Allocatable.Count == nil {
if gotDriver.Allocatable.Count != nil {
t.Errorf("Expected CSI driver Count at index %d to be nil, but got %d", i, *gotDriver.Allocatable.Count)
}
} else {
if gotDriver.Allocatable.Count == nil {
t.Errorf("Expected CSI driver Count at index %d to be %d, but got nil", i, *expectedDriver.Allocatable.Count)
} else if *expectedDriver.Allocatable.Count != *gotDriver.Allocatable.Count {
t.Errorf("Expected CSI driver Count at index %d to be %d, but got %d", i, *expectedDriver.Allocatable.Count, *gotDriver.Allocatable.Count)
}
}
}
}
}
}
}
} else {
if nodeInfo.CSINode != nil {
t.Errorf("Expected CSINode to be nil, but got non-nil with %d drivers", len(nodeInfo.CSINode.Spec.Drivers))
}
}
}

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