Skip to content

Commit

Permalink
Add amd64 architecture node selector to cluster autoscaler based on k…
Browse files Browse the repository at this point in the history
…8s version (#3414)
  • Loading branch information
janosSarusiKis authored Feb 8, 2021
1 parent 0910021 commit 5be6e79
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
3 changes: 3 additions & 0 deletions config/config.yaml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,9 @@ dex:
# - k8sVersion: ">=1.19"
# tag: "v1.19.1"
# repository: "k8s.gcr.io/autoscaling/cluster-autoscaler"
# - k8sVersion: ">=1.20"
# tag: "v1.20.0"
# repository: "k8s.gcr.io/autoscaling/cluster-autoscaler"
#
# # See https://github.com/banzaicloud/banzai-charts/tree/master/cluster-autoscaler for details
# values: {}
Expand Down
5 changes: 5 additions & 0 deletions internal/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,11 @@ rbac:
"tag": "v1.19.1",
"repository": "k8s.gcr.io/autoscaling/cluster-autoscaler",
},
map[string]interface{}{
"k8sVersion": ">=1.20",
"tag": "v1.20.0",
"repository": "k8s.gcr.io/autoscaling/cluster-autoscaler",
},
})

v.SetDefault("cluster::autoscale::charts::hpaOperator::chart", "banzaicloud-stable/hpa-operator")
Expand Down
33 changes: 32 additions & 1 deletion src/cluster/autoscale.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ const (

const releaseName = "autoscaler"

// nolint: gochecknoglobals
// Required for the newAMD64ArchNodeSelector func to compare k8s versions
var comparedK8sSemver *semver.Version = semver.MustParse("1.20.0")

type deploymentAction string

const (
Expand Down Expand Up @@ -85,6 +89,7 @@ type autoscalingInfo struct {
SslCertPath *string `json:"sslCertPath,omitempty"`
SslCertHostPath *string `json:"sslCertHostPath,omitempty"`
Image map[string]string `json:"image,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
azureInfo
}

Expand Down Expand Up @@ -175,6 +180,11 @@ func getAzureNodeGroups(cluster CommonCluster) ([]nodeGroup, error) {

func createAutoscalingForEks(cluster CommonCluster, groups []nodeGroup) *autoscalingInfo {
eksCertPath := "/etc/ssl/certs/ca-bundle.crt"
nodeSelector, err := newAMD64ArchNodeSelector(cluster)
if err != nil {
log.Error(errors.WrapIfWithDetails(err, "unable to retrieve K8s version of cluster", "clusterID", cluster.GetID()))
}

return &autoscalingInfo{
CloudProvider: cloudProviderAws,
ExtraArgs: map[string]string{
Expand All @@ -190,7 +200,8 @@ func createAutoscalingForEks(cluster CommonCluster, groups []nodeGroup) *autosca
"kubernetes.io/cluster/" + cluster.GetName(),
},
},
SslCertPath: &eksCertPath,
SslCertPath: &eksCertPath,
NodeSelector: nodeSelector,
}
}

Expand Down Expand Up @@ -229,6 +240,11 @@ func createAutoscalingForAzure(cluster CommonCluster, groups []nodeGroup, vmType
return nil
}

nodeSelector, err := newAMD64ArchNodeSelector(cluster)
if err != nil {
log.Error(errors.WrapIfWithDetails(err, "unable to retrieve K8s version of cluster", "clusterID", cluster.GetID()))
}

autoscalingInfo := &autoscalingInfo{
CloudProvider: cloudProviderAzure,
AutoscalingGroups: groups,
Expand All @@ -244,6 +260,7 @@ func createAutoscalingForAzure(cluster CommonCluster, groups []nodeGroup, vmType
TenantID: clusterSecret.Values[secrettype.AzureTenantID],
ClusterName: cluster.GetName(),
},
NodeSelector: nodeSelector,
}

switch cluster.GetDistribution() {
Expand Down Expand Up @@ -445,3 +462,17 @@ func getImageVersion(clusterID uint, cluster interface{}) map[string]string {

return selectedImageVersion
}

// ToDo: This need to be removed when we no longer support k8s versions under 1.20.
func newAMD64ArchNodeSelector(cluster CommonCluster) (map[string]string, error) {
k8sVersion, err := getK8sVersion(cluster)
if err != nil {
return nil, err
}

if k8sVersion.LessThan(comparedK8sSemver) {
return map[string]string{"kubernetes.io/arch": "amd64"}, nil
}

return nil, nil
}

0 comments on commit 5be6e79

Please sign in to comment.