-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
userdata_ubuntu.go
115 lines (96 loc) · 2.84 KB
/
userdata_ubuntu.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
package nodebootstrap
import (
"fmt"
"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/kubeconfig"
)
const ubuntu2004ResolveConfPath = "/run/systemd/resolve/resolv.conf"
func makeUbuntuConfig(spec *api.ClusterConfig, ng *api.NodeGroup) ([]configFile, error) {
clientConfigData, err := makeClientConfigData(spec, kubeconfig.HeptioAuthenticatorAWS)
if err != nil {
return nil, err
}
if len(spec.Status.CertificateAuthorityData) == 0 {
return nil, errors.New("invalid cluster config: missing CertificateAuthorityData")
}
kubeletEnvParams := append(makeCommonKubeletEnvParams(ng),
fmt.Sprintf("CLUSTER_DNS=%s", clusterDNS(spec, ng)),
)
// Set resolvConf for Ubuntu 20.04 only, do not override user set value
if ng.AMIFamily == api.NodeImageFamilyUbuntu2004 {
if ng.KubeletExtraConfig == nil {
ng.KubeletExtraConfig = &api.InlineDocument{}
}
if _, ok := (*ng.KubeletExtraConfig)["resolvConf"]; !ok {
(*ng.KubeletExtraConfig)["resolvConf"] = ubuntu2004ResolveConfPath
}
}
kubeletConfigData, err := makeKubeletConfigYAML(spec, ng)
if err != nil {
return nil, err
}
dockerConfigData, err := makeDockerConfigJSON()
if err != nil {
return nil, err
}
files := []configFile{{
dir: configDir,
name: "metadata.env",
contents: strings.Join(makeMetadata(spec), "\n"),
}, {
dir: configDir,
name: "kubelet.env",
contents: strings.Join(kubeletEnvParams, "\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(),
}, {
dir: dockerConfigDir,
name: "daemon.json",
contents: dockerConfigData,
}}
return files, nil
}
// NewUserDataForUbuntu creates new user data for Ubuntu 18.04 & 20.04 nodes
func NewUserDataForUbuntu(spec *api.ClusterConfig, ng *api.NodeGroup) (string, error) {
config := cloudconfig.New()
files, err := makeUbuntuConfig(spec, ng)
if err != nil {
return "", err
}
scripts := []string{}
for _, command := range ng.PreBootstrapCommands {
config.AddShellCommand(command)
}
if ng.OverrideBootstrapCommand != nil {
config.AddShellCommand(*ng.OverrideBootstrapCommand)
} else {
scripts = append(scripts, "bootstrap.ubuntu.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
}