Skip to content

Commit

Permalink
Merge branch 'kubernetes:master' into vpa-1.3.0-updates-to-vpa-releas…
Browse files Browse the repository at this point in the history
…e-1.3-branch
  • Loading branch information
jm-franc authored Jan 27, 2025
2 parents ff938ab + 3291bae commit adb6c84
Show file tree
Hide file tree
Showing 26 changed files with 1,201 additions and 51 deletions.
2 changes: 1 addition & 1 deletion charts/cluster-autoscaler/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ name: cluster-autoscaler
sources:
- https://github.com/kubernetes/autoscaler/tree/master/cluster-autoscaler
type: application
version: 9.45.1
version: 9.46.0
26 changes: 24 additions & 2 deletions charts/cluster-autoscaler/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ To create a valid configuration, follow instructions for your cloud provider:
- [Cluster API](#cluster-api)
- [Exoscale](#exoscale)
- [Hetzner Cloud](#hetzner-cloud)
- [Civo](#civo)

### Templating the autoDiscovery.clusterName

Expand Down Expand Up @@ -282,6 +283,23 @@ Each autoscaling group requires an additional `instanceType` and `region` key to

Read [cluster-autoscaler/cloudprovider/hetzner/README.md](https://github.com/kubernetes/autoscaler/blob/master/cluster-autoscaler/cloudprovider/hetzner/README.md) for further information on the setup without helm.

### Civo

The following parameters are required:

- `cloudProvider=civo`
- `autoscalingGroups=...`

When installing the helm chart to the namespace `kube-system`, you can set `secretKeyRefNameOverride` to `civo-api-access`.
Otherwise specify the following parameters:

- `civoApiUrl=https://api.civo.com`
- `civoApiKey=...`
- `civoClusterID=...`
- `civoRegion=...`

Read [cluster-autoscaler/cloudprovider/civo/README.md](https://github.com/kubernetes/autoscaler/blob/master/cluster-autoscaler/cloudprovider/civo/README.md) for further information on the setup without helm.

## Uninstalling the Chart

To uninstall `my-release`:
Expand Down Expand Up @@ -421,8 +439,12 @@ vpa:
| azureUseManagedIdentityExtension | bool | `false` | Whether to use Azure's managed identity extension for credentials. If using MSI, ensure subscription ID, resource group, and azure AKS cluster name are set. You can only use one authentication method at a time, either azureUseWorkloadIdentityExtension or azureUseManagedIdentityExtension should be set. |
| azureUseWorkloadIdentityExtension | bool | `false` | Whether to use Azure's workload identity extension for credentials. See the project here: https://github.com/Azure/azure-workload-identity for more details. You can only use one authentication method at a time, either azureUseWorkloadIdentityExtension or azureUseManagedIdentityExtension should be set. |
| azureVMType | string | `"vmss"` | Azure VM type. |
| civoApiKey | string | `""` | API key for the Civo API. Required if `cloudProvider=civo` |
| civoApiUrl | string | `"https://api.civo.com"` | URL for the Civo API. Required if `cloudProvider=civo` |
| civoClusterID | string | `""` | Cluster ID for the Civo cluster. Required if `cloudProvider=civo` |
| civoRegion | string | `""` | Region for the Civo cluster. Required if `cloudProvider=civo` |
| cloudConfigPath | string | `""` | Configuration file for cloud provider. |
| cloudProvider | string | `"aws"` | The cloud provider where the autoscaler runs. Currently only `gce`, `aws`, `azure`, `magnum` and `clusterapi` are supported. `aws` supported for AWS. `gce` for GCE. `azure` for Azure AKS. `magnum` for OpenStack Magnum, `clusterapi` for Cluster API. |
| cloudProvider | string | `"aws"` | The cloud provider where the autoscaler runs. Currently only `gce`, `aws`, `azure`, `magnum`, `clusterapi` and `civo` are supported. `aws` supported for AWS. `gce` for GCE. `azure` for Azure AKS. `magnum` for OpenStack Magnum, `clusterapi` for Cluster API. `civo` for Civo Cloud. |
| clusterAPICloudConfigPath | string | `"/etc/kubernetes/mgmt-kubeconfig"` | Path to kubeconfig for connecting to Cluster API Management Cluster, only used if `clusterAPIMode=kubeconfig-kubeconfig or incluster-kubeconfig` |
| clusterAPIConfigMapsNamespace | string | `""` | Namespace on the workload cluster to store Leader election and status configmaps |
| clusterAPIKubeconfigSecret | string | `""` | Secret containing kubeconfig for connecting to Cluster API managed workloadcluster Required if `cloudProvider=clusterapi` and `clusterAPIMode=kubeconfig-kubeconfig,kubeconfig-incluster or incluster-kubeconfig` |
Expand Down Expand Up @@ -476,7 +498,7 @@ vpa:
| replicaCount | int | `1` | Desired number of pods |
| resources | object | `{}` | Pod resource requests and limits. |
| revisionHistoryLimit | int | `10` | The number of revisions to keep. |
| secretKeyRefNameOverride | string | `""` | Overrides the name of the Secret to use when loading the secretKeyRef for AWS and Azure env variables |
| secretKeyRefNameOverride | string | `""` | Overrides the name of the Secret to use when loading the secretKeyRef for AWS, Azure and Civo env variables |
| securityContext | object | `{}` | [Security context for pod](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/) |
| service.annotations | object | `{}` | Annotations to add to service |
| service.clusterIP | string | `""` | IP address to assign to service |
Expand Down
18 changes: 18 additions & 0 deletions charts/cluster-autoscaler/README.md.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ To create a valid configuration, follow instructions for your cloud provider:
- [Cluster API](#cluster-api)
- [Exoscale](#exoscale)
- [Hetzner Cloud](#hetzner-cloud)
- [Civo](#civo)

### Templating the autoDiscovery.clusterName

Expand Down Expand Up @@ -282,6 +283,23 @@ Each autoscaling group requires an additional `instanceType` and `region` key to

Read [cluster-autoscaler/cloudprovider/hetzner/README.md](https://github.com/kubernetes/autoscaler/blob/master/cluster-autoscaler/cloudprovider/hetzner/README.md) for further information on the setup without helm.

### Civo

The following parameters are required:

- `cloudProvider=civo`
- `autoscalingGroups=...`

When installing the helm chart to the namespace `kube-system`, you can set `secretKeyRefNameOverride` to `civo-api-access`.
Otherwise specify the following parameters:

- `civoApiUrl=https://api.civo.com`
- `civoApiKey=...`
- `civoClusterID=...`
- `civoRegion=...`

Read [cluster-autoscaler/cloudprovider/civo/README.md](https://github.com/kubernetes/autoscaler/blob/master/cluster-autoscaler/cloudprovider/civo/README.md) for further information on the setup without helm.

## Uninstalling the Chart

To uninstall `my-release`:
Expand Down
21 changes: 21 additions & 0 deletions charts/cluster-autoscaler/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,27 @@ spec:
{{- else if eq .Values.cloudProvider "kwok" }}
- name: KWOK_PROVIDER_CONFIGMAP
value: "{{.Values.kwokConfigMapName | default "kwok-provider-config"}}"
{{- else if eq .Values.cloudProvider "civo" }}
- name: CIVO_API_URL
valueFrom:
secretKeyRef:
key: api-url
name: {{ default (include "cluster-autoscaler.fullname" .) .Values.secretKeyRefNameOverride }}
- name: CIVO_API_KEY
valueFrom:
secretKeyRef:
key: api-key
name: {{ default (include "cluster-autoscaler.fullname" .) .Values.secretKeyRefNameOverride }}
- name: CIVO_CLUSTER_ID
valueFrom:
secretKeyRef:
key: cluster-id
name: {{ default (include "cluster-autoscaler.fullname" .) .Values.secretKeyRefNameOverride }}
- name: CIVO_REGION
valueFrom:
secretKeyRef:
key: region
name: {{ default (include "cluster-autoscaler.fullname" .) .Values.secretKeyRefNameOverride }}
{{- end }}
{{- range $key, $value := .Values.extraEnv }}
- name: {{ $key }}
Expand Down
8 changes: 7 additions & 1 deletion charts/cluster-autoscaler/templates/secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
{{- $isAzure := eq .Values.cloudProvider "azure" }}
{{- $isAws := eq .Values.cloudProvider "aws" }}
{{- $awsCredentialsProvided := and .Values.awsAccessKeyID .Values.awsSecretAccessKey }}
{{- $isCivo := eq .Values.cloudProvider "civo" }}

{{- if or $isAzure (and $isAws $awsCredentialsProvided) }}
{{- if or $isAzure (and $isAws $awsCredentialsProvided) $isCivo }}
apiVersion: v1
kind: Secret
metadata:
Expand All @@ -20,6 +21,11 @@ data:
{{- else if $isAws }}
AwsAccessKeyId: "{{ .Values.awsAccessKeyID | b64enc }}"
AwsSecretAccessKey: "{{ .Values.awsSecretAccessKey | b64enc }}"
{{- else if $isCivo }}
api-url: "{{ .Values.civoApiUrl | b64enc }}"
api-key: "{{ .Values.civoApiKey | b64enc }}"
cluster-id: "{{ .Values.civoClusterID | b64enc }}"
region: "{{ .Values.civoRegion | b64enc }}"
{{- end }}
{{- end }}
{{- end }}
21 changes: 19 additions & 2 deletions charts/cluster-autoscaler/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,30 @@ azureVMType: "vmss"
# azureEnableForceDelete -- Whether to force delete VMs or VMSS instances when scaling down.
azureEnableForceDelete: false

# civoApiUrl -- URL for the Civo API.
# Required if `cloudProvider=civo`
civoApiUrl: "https://api.civo.com"

# civoApiKey -- API key for the Civo API.
# Required if `cloudProvider=civo`
civoApiKey: ""

# civoClusterID -- Cluster ID for the Civo cluster.
# Required if `cloudProvider=civo`
civoClusterID: ""

# civoRegion -- Region for the Civo cluster.
# Required if `cloudProvider=civo`
civoRegion: ""

# cloudConfigPath -- Configuration file for cloud provider.
cloudConfigPath: ""

# cloudProvider -- The cloud provider where the autoscaler runs.
# Currently only `gce`, `aws`, `azure`, `magnum` and `clusterapi` are supported.
# Currently only `gce`, `aws`, `azure`, `magnum`, `clusterapi` and `civo` are supported.
# `aws` supported for AWS. `gce` for GCE. `azure` for Azure AKS.
# `magnum` for OpenStack Magnum, `clusterapi` for Cluster API.
# `civo` for Civo Cloud.
cloudProvider: aws

# clusterAPICloudConfigPath -- Path to kubeconfig for connecting to Cluster API Management Cluster, only used if `clusterAPIMode=kubeconfig-kubeconfig or incluster-kubeconfig`
Expand Down Expand Up @@ -446,5 +463,5 @@ vpa:
# vpa.containerPolicy -- [ContainerResourcePolicy](https://github.com/kubernetes/autoscaler/blob/vertical-pod-autoscaler/v0.13.0/vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1/types.go#L159). The containerName is always et to the deployment's container name. This value is required if VPA is enabled.
containerPolicy: {}

# secretKeyRefNameOverride -- Overrides the name of the Secret to use when loading the secretKeyRef for AWS and Azure env variables
# secretKeyRefNameOverride -- Overrides the name of the Secret to use when loading the secretKeyRef for AWS, Azure and Civo env variables
secretKeyRefNameOverride: ""
95 changes: 95 additions & 0 deletions cluster-autoscaler/cloudprovider/azure/azure_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package azure

import (
"fmt"
"os"
"reflect"
"strings"
"testing"
Expand Down Expand Up @@ -198,7 +199,26 @@ const (
testASG = "test-asg"
)

func saveAndClearEnv() []string {
originalEnv := os.Environ()
os.Clearenv()
return originalEnv
}

func loadEnv(originalEnv []string) {
os.Clearenv()
for _, e := range originalEnv {
parts := strings.SplitN(e, "=", 2)
os.Setenv(parts[0], parts[1])
}
}

func TestCreateAzureManagerValidConfig(t *testing.T) {
originalEnv := saveAndClearEnv()
t.Cleanup(func() {
loadEnv(originalEnv)
})

ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockVMClient := mockvmclient.NewMockInterface(ctrl)
Expand Down Expand Up @@ -284,6 +304,11 @@ func TestCreateAzureManagerValidConfig(t *testing.T) {
}

func TestCreateAzureManagerLegacyConfig(t *testing.T) {
originalEnv := saveAndClearEnv()
t.Cleanup(func() {
loadEnv(originalEnv)
})

ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockVMClient := mockvmclient.NewMockInterface(ctrl)
Expand Down Expand Up @@ -367,6 +392,11 @@ func TestCreateAzureManagerLegacyConfig(t *testing.T) {
}

func TestCreateAzureManagerValidConfigForStandardVMType(t *testing.T) {
originalEnv := saveAndClearEnv()
t.Cleanup(func() {
loadEnv(originalEnv)
})

ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockVMClient := mockvmclient.NewMockInterface(ctrl)
Expand Down Expand Up @@ -474,12 +504,22 @@ func TestCreateAzureManagerValidConfigForStandardVMType(t *testing.T) {
}

func TestCreateAzureManagerValidConfigForStandardVMTypeWithoutDeploymentParameters(t *testing.T) {
originalEnv := saveAndClearEnv()
t.Cleanup(func() {
loadEnv(originalEnv)
})

manager, err := createAzureManagerInternal(strings.NewReader(validAzureCfgForStandardVMTypeWithoutDeploymentParameters), cloudprovider.NodeGroupDiscoveryOptions{}, &azClient{})
expectedErr := "open /var/lib/azure/azuredeploy.parameters.json: no such file or directory"
assert.Nil(t, manager)
assert.Equal(t, expectedErr, err.Error(), "return error does not match, expected: %v, actual: %v", expectedErr, err.Error())
}
func TestCreateAzureManagerValidConfigForVMsPool(t *testing.T) {
originalEnv := saveAndClearEnv()
t.Cleanup(func() {
loadEnv(originalEnv)
})

ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockVMClient := mockvmclient.NewMockInterface(ctrl)
Expand Down Expand Up @@ -567,6 +607,11 @@ func TestCreateAzureManagerValidConfigForVMsPool(t *testing.T) {
}

func TestCreateAzureManagerWithNilConfig(t *testing.T) {
originalEnv := saveAndClearEnv()
t.Cleanup(func() {
loadEnv(originalEnv)
})

ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockVMClient := mockvmclient.NewMockInterface(ctrl)
Expand Down Expand Up @@ -814,6 +859,11 @@ func TestCreateAzureManagerWithNilConfig(t *testing.T) {
}

func TestCreateAzureManagerWithEnvOverridingConfig(t *testing.T) {
originalEnv := saveAndClearEnv()
t.Cleanup(func() {
loadEnv(originalEnv)
})

ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockVMClient := mockvmclient.NewMockInterface(ctrl)
Expand Down Expand Up @@ -945,11 +995,21 @@ func TestCreateAzureManagerWithEnvOverridingConfig(t *testing.T) {
}

func TestCreateAzureManagerInvalidConfig(t *testing.T) {
originalEnv := saveAndClearEnv()
t.Cleanup(func() {
loadEnv(originalEnv)
})

_, err := createAzureManagerInternal(strings.NewReader(invalidAzureCfg), cloudprovider.NodeGroupDiscoveryOptions{}, &azClient{})
assert.Error(t, err, "failed to unmarshal config body")
}

func TestFetchExplicitNodeGroups(t *testing.T) {
originalEnv := saveAndClearEnv()
t.Cleanup(func() {
loadEnv(originalEnv)
})

ctrl := gomock.NewController(t)
defer ctrl.Finish()

Expand Down Expand Up @@ -1025,6 +1085,11 @@ func TestFetchExplicitNodeGroups(t *testing.T) {
}

func TestGetFilteredAutoscalingGroupsVmss(t *testing.T) {
originalEnv := saveAndClearEnv()
t.Cleanup(func() {
loadEnv(originalEnv)
})

ctrl := gomock.NewController(t)
defer ctrl.Finish()

Expand Down Expand Up @@ -1070,6 +1135,11 @@ func TestGetFilteredAutoscalingGroupsVmss(t *testing.T) {
}

func TestGetFilteredAutoscalingGroupsVmssWithConfiguredSizes(t *testing.T) {
originalEnv := saveAndClearEnv()
t.Cleanup(func() {
loadEnv(originalEnv)
})

ctrl := gomock.NewController(t)
defer ctrl.Finish()

Expand Down Expand Up @@ -1118,6 +1188,11 @@ func TestGetFilteredAutoscalingGroupsVmssWithConfiguredSizes(t *testing.T) {
}

func TestGetFilteredAutoscalingGroupsWithInvalidVMType(t *testing.T) {
originalEnv := saveAndClearEnv()
t.Cleanup(func() {
loadEnv(originalEnv)
})

ctrl := gomock.NewController(t)
defer ctrl.Finish()

Expand All @@ -1142,6 +1217,11 @@ func TestGetFilteredAutoscalingGroupsWithInvalidVMType(t *testing.T) {
}

func TestFetchAutoAsgsVmss(t *testing.T) {
originalEnv := saveAndClearEnv()
t.Cleanup(func() {
loadEnv(originalEnv)
})

ctrl := gomock.NewController(t)
defer ctrl.Finish()

Expand Down Expand Up @@ -1196,6 +1276,11 @@ func TestFetchAutoAsgsVmss(t *testing.T) {
}

func TestManagerRefreshAndCleanup(t *testing.T) {
originalEnv := saveAndClearEnv()
t.Cleanup(func() {
loadEnv(originalEnv)
})

ctrl := gomock.NewController(t)
defer ctrl.Finish()

Expand All @@ -1206,6 +1291,11 @@ func TestManagerRefreshAndCleanup(t *testing.T) {
}

func TestGetScaleSetOptions(t *testing.T) {
originalEnv := saveAndClearEnv()
t.Cleanup(func() {
loadEnv(originalEnv)
})

manager := &AzureManager{
azureCache: &azureCache{
autoscalingOptions: make(map[azureRef]map[string]string),
Expand Down Expand Up @@ -1254,6 +1344,11 @@ func TestGetScaleSetOptions(t *testing.T) {
// if even one expected nodeGroup was not found. When manager creation errored out,
// BuildAzure returns log.Fatalf() which caused CAS to crash.
func TestVMSSNotFound(t *testing.T) {
originalEnv := saveAndClearEnv()
t.Cleanup(func() {
loadEnv(originalEnv)
})

// client setup
ctrl := gomock.NewController(t)
defer ctrl.Finish()
Expand Down
Loading

0 comments on commit adb6c84

Please sign in to comment.