Skip to content

Commit fe80b49

Browse files
Support Cluster API - Cluster AutoScaler integration
Signed-off-by: Archisman <[email protected]>
1 parent b50e11a commit fe80b49

File tree

8 files changed

+75
-24
lines changed

8 files changed

+75
-24
lines changed

cmd/bootstrap_cluster/bootstrap_cluster.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,9 @@ func BootstrapCluster(ctx *cli.Context) error {
274274
"clusterctl move --kubeconfig %s --namespace %s --to-kubeconfig %s",
275275
constants.OutputPathManagementClusterKubeconfig, capiClusterNamespace, constants.OutputPathProvisionedClusterKubeconfig,
276276
))
277+
278+
// Sync cluster-autoscaler ArgoCD App.
279+
utils.ExecuteCommandOrDie("argocd app sync argo-cd/cluster-autoscaler")
277280
}
278281

279282
slog.Info("Cluster provisioned successfully 🎉🎉 !", slog.String("kubeconfig", constants.OutputPathProvisionedClusterKubeconfig))

cmd/bootstrap_cluster/templates/argocd-apps/capi-cluster.values.yaml.tmpl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ global:
55
{{- end }}
66
kubernetes:
77
version: {{ .K8sVersion }}
8-
capa:
9-
autoScaler: true
108
kubeaid:
119
repo: {{ .KubeaidForkURL }}
1210
kubeaidConfig:
@@ -33,5 +31,5 @@ aws:
3331
instanceType: {{ .ControlPlaneInstanceType }}
3432
ami:
3533
id: {{ .ControlPlaneAMI }}
36-
machinePools:
37-
{{ .MachinePools | toYaml | indent 2 }}
34+
nodeGroups:
35+
{{ .NodeGroups | toYaml | indent 2 }}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
cluster-autoscaler:
2+
cloudProvider: clusterapi
3+
4+
# Cluster API mode : incluster-incluster / incluster-kubeconfig / kubeconfig-incluster / kubeconfig-kubeconfig / single-kubeconfig.
5+
# Syntax: workloadClusterMode-ManagementClusterMode
6+
#
7+
# For 'kubeconfig-kubeconfig', 'incluster-kubeconfig' and 'single-kubeconfig' you always must
8+
# mount the external kubeconfig using either 'extraVolumeSecrets' or 'extraMounts' and
9+
# 'extraVolumes'.
10+
#
11+
# If you dont set 'clusterAPIKubeconfigSecret'and thus use an in-cluster config or want to use a
12+
# non CAPI generated kubeconfig you must do so for the workload kubeconfig as well
13+
#
14+
# REFER : https://github.com/kubernetes/autoscaler/blob/master/cluster-autoscaler/cloudprovider/clusterapi/README.md#connecting-cluster-autoscaler-to-cluster-api-management-and-workload-clusters
15+
clusterAPIMode: incluster-incluster
16+
17+
autoDiscovery:
18+
clusterName: {{ .ClusterName }}
19+
namespace: {{ .CAPIClusterNamespace }}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
apiVersion: argoproj.io/v1alpha1
2+
kind: Application
3+
metadata:
4+
name: cluster-autoscaler
5+
namespace: argo-cd
6+
7+
spec:
8+
destination:
9+
namespace: cluster-autoscaler
10+
server: https://kubernetes.default.svc
11+
sources:
12+
- repoURL: {{ .KubeaidForkURL }}
13+
path: argocd-helm-charts/cluster-autoscaler
14+
targetRevision: HEAD
15+
helm:
16+
valueFiles:
17+
- $values/k8s/{{ .ClusterName }}/argocd-apps/cluster-autoscaler.values.yaml
18+
- repoURL: {{ .KubeaidConfigForkURL }}
19+
targetRevision: HEAD
20+
ref: values
21+
project: default
22+
syncPolicy:
23+
syncOptions:
24+
- CreateNamespace=true
25+
- ApplyOutOfSyncOnly=true

config/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ type (
5959
ControlPlaneAMI string `yaml:"controlPlaneAMI" validate:"required"`
6060
ControlPlaneReplicas int `yaml:"controlPlaneReplicas" validate:"required"`
6161

62-
MachinePools []AWSMachinePool `yaml:"machinePools"`
62+
NodeGroups []NodeGroups `yaml:"nodeGroups"`
6363
}
6464

65-
AWSMachinePool struct {
65+
NodeGroups struct {
6666
Name string `yaml:"name" validate:"required"`
6767
Replicas int `yaml:"replicas" validate:"required"`
6868
InstanceType string `yaml:"instanceType" validate:"required"`

config/templates/aws.sample.config.yaml.tmpl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ cloud:
2222
controlPlaneAMI: {{ .AMI }}
2323
controlPlaneReplicas: 1
2424

25-
machinePools:
25+
nodeGroups:
2626
- name: primary
2727
ami:
2828
id: {{ .AMI }}
@@ -42,6 +42,8 @@ cloud:
4242
# REFER : https://cluster-api.sigs.k8s.io/developer/architecture/controllers/metadata-propagation#machine
4343
# labels: []
4444

45+
# taints []
46+
4547
monitoring:
4648
kubePrometheusVersion: v0.14.0
4749
grafanaURL: ""

config/validate.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import (
1212
)
1313

1414
var (
15-
// A user defined MachinePool label key should belong to one of these domains.
15+
// A user defined NodeGroup label key should belong to one of these domains.
1616
// REFER : https://cluster-api.sigs.k8s.io/developer/architecture/controllers/metadata-propagation#machine.
17-
ValidMachinePoolLabelDomains = []string{
17+
ValidNodeGroupLabelDomains = []string{
1818
"node.cluster.x-k8s.io/",
1919
"node-role.kubernetes.io/",
2020
"node-restriction.kubernetes.io/",
@@ -23,7 +23,7 @@ var (
2323

2424
// Validates the parsed config.
2525
// Panics on failure.
26-
// TODO : Extract the MachinePool labels and taints validation task from 'cloud specifics' section.
26+
// TODO : Extract the NodeGroup labels and taints validation task from 'cloud specifics' section.
2727
func validateConfig(config *Config) {
2828
// Validate based on struct tags.
2929
validate := validator.New(validator.WithRequiredStructEnabled())
@@ -35,38 +35,38 @@ func validateConfig(config *Config) {
3535
switch {
3636
case config.Cloud.AWS != nil:
3737

38-
for _, machinePool := range config.Cloud.AWS.MachinePools {
39-
// Validate MachinePools labels.
38+
for _, nodeGroup := range config.Cloud.AWS.NodeGroups {
39+
// Validate NodeGroups labels.
4040
//
4141
// (1) according to Kubernetes specifications.
42-
if err := labels.Validate(machinePool.Labels); err != nil {
43-
log.Fatalf("MachinePool labels validation failed : %v", err)
42+
if err := labels.Validate(nodeGroup.Labels); err != nil {
43+
log.Fatalf("NodeGroup labels validation failed : %v", err)
4444
}
4545
//
4646
// (2) according to ClusterAPI specifications.
47-
for key := range machinePool.Labels {
47+
for key := range nodeGroup.Labels {
4848
// Check if the label belongs to a domain considered valid by ClusterAPI.
49-
isValidMachinePoolLabelDomain := false
50-
for _, machinePoolLabelDomains := range ValidMachinePoolLabelDomains {
51-
if strings.HasPrefix(key, machinePoolLabelDomains) {
52-
isValidMachinePoolLabelDomain = true
49+
isValidNodeGroupLabelDomain := false
50+
for _, nodeGroupLabelDomains := range ValidNodeGroupLabelDomains {
51+
if strings.HasPrefix(key, nodeGroupLabelDomains) {
52+
isValidNodeGroupLabelDomain = true
5353
break
5454
}
5555
}
56-
if !isValidMachinePoolLabelDomain {
57-
slog.Error("MachinePool label key should belong to one of these domains", slog.Any("domains", ValidMachinePoolLabelDomains))
56+
if !isValidNodeGroupLabelDomain {
57+
slog.Error("NodeGroup label key should belong to one of these domains", slog.Any("domains", ValidNodeGroupLabelDomains))
5858
os.Exit(1)
5959
}
6060
}
6161

6262
taintsAsKVPairs := map[string]string{}
63-
for _, taint := range machinePool.Taints {
63+
for _, taint := range nodeGroup.Taints {
6464
taintsAsKVPairs[taint.Key] = fmt.Sprintf("%s:%s", taint.Value, taint.Effect)
6565
}
6666
//
67-
// Validate MachinePool taints.
67+
// Validate NodeGroup taints.
6868
if err := labels.ValidateTaints(taintsAsKVPairs); err != nil {
69-
log.Fatalf("MachinePool taint validation failed : %v", err)
69+
log.Fatalf("NodeGroup taint validation failed : %v", err)
7070
}
7171
}
7272

constants/constants.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ var (
6868
"argocd-apps/templates/cluster-api.app.yaml.tmpl",
6969
"argocd-apps/cluster-api.values.yaml.tmpl",
7070

71+
// Cluster Autoscaler.
72+
"argocd-apps/templates/cluster-autoscaler.app.yaml.tmpl",
73+
"argocd-apps/cluster-autoscaler.values.yaml.tmpl",
74+
7175
// Traefik.
7276
"argocd-apps/templates/traefik.app.yaml.tmpl",
7377
"argocd-apps/traefik.values.yaml.tmpl",

0 commit comments

Comments
 (0)