Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 20 additions & 19 deletions pkg/nodebootstrap/userdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ const (
)

type configFile struct {
content string
isAsset bool
dir string
name string
contents string
isAsset bool
}

type configFiles = map[string]map[string]configFile

func getAsset(name string) (string, error) {
data, err := Asset(name)
if err != nil {
Expand All @@ -40,24 +40,25 @@ func getAsset(name string) (string, error) {
return string(data), nil
}

func addFilesAndScripts(config *cloudconfig.CloudConfig, files configFiles, scripts []string) error {
for dir, fileNames := range files {
for fileName, file := range fileNames {
f := cloudconfig.File{
Path: dir + fileName,
}
if file.isAsset {
data, err := getAsset(fileName)
if err != nil {
return err
}
f.Content = data
} else {
f.Content = file.content
func addFilesAndScripts(config *cloudconfig.CloudConfig, files []configFile, scripts []string) error {
for _, file := range files {
f := cloudconfig.File{
Path: file.dir + file.name,
}

if file.isAsset {
data, err := getAsset(file.name)
if err != nil {
return err
}
config.AddFile(f)
f.Content = data
} else {
f.Content = file.contents
}

config.AddFile(f)
}

for _, scriptName := range scripts {
data, err := getAsset(scriptName)
if err != nil {
Expand Down
69 changes: 47 additions & 22 deletions pkg/nodebootstrap/userdata_al2.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import (
"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) (configFiles, error) {
func makeAmazonLinux2Config(spec *api.ClusterConfig, ng *api.NodeGroup) ([]configFile, error) {
clientConfigData, err := makeClientConfigData(spec, kubeconfig.AWSEKSAuthenticator)
if err != nil {
return nil, err
Expand All @@ -25,27 +26,43 @@ func makeAmazonLinux2Config(spec *api.ClusterConfig, ng *api.NodeGroup) (configF
return nil, err
}

dockerConfigData, err := makeDockerConfigJSON(spec, ng)
if err != nil {
return nil, err
}

files := configFiles{
kubeletDropInUnitDir: {
"10-eksclt.al2.conf": {isAsset: true},
},
configDir: {
"metadata.env": {content: strings.Join(makeMetadata(spec), "\n")},
"kubelet.env": {content: strings.Join(makeCommonKubeletEnvParams(ng), "\n")},
"kubelet.yaml": {content: string(kubeletConfigData)},
// TODO: https://github.com/weaveworks/eksctl/issues/161
"ca.crt": {content: string(spec.Status.CertificateAuthorityData)},
"kubeconfig.yaml": {content: string(clientConfigData)},
"max_pods.map": {content: makeMaxPodsMapping()},
},
dockerConfigDir: {
"daemon.json": {content: string(dockerConfigData)},
},
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(spec, ng)
if err != nil {
return nil, err
}

files = append(files, configFile{dir: dockerConfigDir, name: "daemon.json", contents: string(dockerConfigData)})
}

return files, nil
Expand All @@ -66,6 +83,14 @@ func NewUserDataForAmazonLinux2(spec *api.ClusterConfig, ng *api.NodeGroup) (str
scripts = append(scripts, "install-ssm.al2.sh")
}

// This is the worst but I am very tired
// 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
if utils.IsGPUInstanceType(ng.InstanceType) {
config.AddShellCommand("sed -i 's/^OPTIONS=\"/&--exec-opt native.cgroupdriver=systemd /' /etc/sysconfig/docker")
}

for _, command := range ng.PreBootstrapCommands {
config.AddShellCommand(command)
}
Expand Down
45 changes: 30 additions & 15 deletions pkg/nodebootstrap/userdata_ubuntu.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

const ubuntu2004ResolveConfPath = "/run/systemd/resolve/resolv.conf"

func makeUbuntuConfig(spec *api.ClusterConfig, ng *api.NodeGroup) (configFiles, error) {
func makeUbuntuConfig(spec *api.ClusterConfig, ng *api.NodeGroup) ([]configFile, error) {
clientConfigData, err := makeClientConfigData(spec, kubeconfig.HeptioAuthenticatorAWS)
if err != nil {
return nil, err
Expand Down Expand Up @@ -47,20 +47,35 @@ func makeUbuntuConfig(spec *api.ClusterConfig, ng *api.NodeGroup) (configFiles,
return nil, err
}

files := configFiles{
configDir: {
"metadata.env": {content: strings.Join(makeMetadata(spec), "\n")},
"kubelet.env": {content: strings.Join(kubeletEnvParams, "\n")},
"kubelet.yaml": {content: string(kubeletConfigData)},
// TODO: https://github.com/weaveworks/eksctl/issues/161
"ca.crt": {content: string(spec.Status.CertificateAuthorityData)},
"kubeconfig.yaml": {content: string(clientConfigData)},
"max_pods.map": {content: makeMaxPodsMapping()},
},
dockerConfigDir: {
"daemon.json": {content: string(dockerConfigData)},
},
}
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: string(dockerConfigData),
}}

return files, nil
}
Expand Down