-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
userdata_al2.go
125 lines (106 loc) · 3.28 KB
/
userdata_al2.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package nodebootstrap
import (
"strings"
"github.com/kris-nova/logger"
"github.com/pkg/errors"
api "github.com/weaveworks/eksctl/pkg/apis/eksctl.io/v1alpha5"
"github.com/weaveworks/eksctl/pkg/cloudconfig"
"github.com/weaveworks/eksctl/pkg/utils"
"github.com/weaveworks/eksctl/pkg/utils/kubeconfig"
)
func makeAmazonLinux2Config(spec *api.ClusterConfig, ng *api.NodeGroup) ([]configFile, error) {
clientConfigData, err := makeClientConfigData(spec, kubeconfig.AWSEKSAuthenticator)
if err != nil {
return nil, err
}
if len(spec.Status.CertificateAuthorityData) == 0 {
return nil, errors.New("invalid cluster config: missing CertificateAuthorityData")
}
kubeletConfigData, err := makeKubeletConfigYAML(spec, ng)
if err != nil {
return nil, err
}
files := []configFile{{
dir: kubeletDropInUnitDir,
name: "10-eksclt.al2.conf",
isAsset: true,
}, {
dir: configDir,
name: "metadata.env",
contents: strings.Join(makeMetadata(spec), "\n"),
}, {
dir: configDir,
name: "kubelet.env",
contents: strings.Join(makeCommonKubeletEnvParams(ng), "\n"),
}, {
dir: configDir,
name: "kubelet.yaml",
contents: string(kubeletConfigData),
}, {
dir: configDir,
name: "ca.crt",
contents: string(spec.Status.CertificateAuthorityData),
}, {
dir: configDir,
name: "kubeconfig.yaml",
contents: string(clientConfigData),
}, {
dir: configDir,
name: "max_pods.map",
contents: makeMaxPodsMapping(),
}}
if !utils.IsGPUInstanceType(ng.InstanceType) {
dockerConfigData, err := makeDockerConfigJSON()
if err != nil {
return nil, err
}
files = append(files, configFile{dir: dockerConfigDir, name: "daemon.json", contents: dockerConfigData})
}
return files, nil
}
// NewUserDataForAmazonLinux2 creates new user data for Amazon Linux 2 nodes
func NewUserDataForAmazonLinux2(spec *api.ClusterConfig, ng *api.NodeGroup) (string, error) {
config := cloudconfig.New()
files, err := makeAmazonLinux2Config(spec, ng)
if err != nil {
return "", err
}
var scripts []string
if ng.SSH.EnableSSM != nil && *ng.SSH.EnableSSM {
scripts = append(scripts, "install-ssm.al2.sh")
}
// When using GPU instance types, the daemon.json is removed and a service
// override file used instead. We can alter the daemon command by adding
// to the OPTIONS var in /etc/sysconfig/docker
overrideInsert := "sed -i 's/^OPTIONS=\"/&--exec-opt native.cgroupdriver=systemd /' /etc/sysconfig/docker"
if utils.IsGPUInstanceType(ng.InstanceType) {
config.AddShellCommand(overrideInsert)
}
if api.HasMixedInstances(ng) {
for _, it := range ng.InstancesDistribution.InstanceTypes {
if utils.IsGPUInstanceType(it) {
config.AddShellCommand(overrideInsert)
}
}
}
for _, command := range ng.PreBootstrapCommands {
config.AddShellCommand(command)
}
if ng.OverrideBootstrapCommand != nil {
config.AddShellCommand(*ng.OverrideBootstrapCommand)
} else {
if api.IsEnabled(ng.EFAEnabled) {
scripts = append(scripts, "efa.al2.sh")
}
scripts = append(scripts, "bootstrap.al2.sh")
}
if err = addFilesAndScripts(config, files, scripts); err != nil {
return "", err
}
body, err := config.Encode()
if err != nil {
return "", errors.Wrap(err, "encoding user data")
}
logger.Debug("user-data = %s", body)
return body, nil
}