/
cluster_config.go
67 lines (63 loc) · 1.49 KB
/
cluster_config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package eksctl
import (
"bytes"
"log"
"text/template"
)
const configYAMLTemplate = `
---
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
name: "{{.ClusterName}}"
region: "{{.Region}}"
{{- if .KubernetesVersion}}
version: "{{.KubernetesVersion}}"
{{- end}}
managedNodeGroups:
- name: managed
{{- if .AMI}}
ami: "{{.AMI}}"
{{- end}}
amiFamily: AmazonLinux2
{{- if .InstanceTypes}}
instanceTypes:
{{- range $instanceType := .InstanceTypes}}
- "{{$instanceType}}"
{{- end}}
{{- end}}
{{- if gt .Nodes 0}}
minSize: {{.Nodes}}
maxSize: {{.Nodes}}
desiredCapacity: {{.Nodes}}
{{- end}}
{{- if .AMI}}
overrideBootstrapCommand: |
#!/bin/bash
source /var/lib/cloud/scripts/eksctl/bootstrap.helper.sh
/etc/eks/bootstrap.sh {{.ClusterName}} --kubelet-extra-args "--node-labels=${NODE_LABELS}"
{{- end}}
`
type clusterConfigTemplateParams struct {
UpOptions
ClusterName string
Region string
}
func (d *deployer) RenderClusterConfig() ([]byte, error) {
templateParams := clusterConfigTemplateParams{
UpOptions: *d.UpOptions,
ClusterName: d.commonOptions.RunID(),
Region: d.awsConfig.Region,
}
log.Printf("rendering cluster config template with params: %+v", templateParams)
t, err := template.New("configYAML").Parse(configYAMLTemplate)
if err != nil {
return nil, err
}
var buf bytes.Buffer
err = t.Execute(&buf, templateParams)
if err != nil {
return nil, err
}
return buf.Bytes(), nil
}