-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
windows.go
116 lines (100 loc) · 2.63 KB
/
windows.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
package nodebootstrap
import (
"encoding/base64"
"fmt"
"strconv"
"strings"
"github.com/kris-nova/logger"
api "github.com/weaveworks/eksctl/pkg/apis/eksctl.io/v1alpha5"
"github.com/weaveworks/eksctl/pkg/nodebootstrap/utils"
)
type Windows struct {
clusterConfig *api.ClusterConfig
ng *api.NodeGroup
}
type keyValue struct {
key string
value string
}
func NewWindowsBootstrapper(clusterConfig *api.ClusterConfig, ng *api.NodeGroup) *Windows {
return &Windows{
clusterConfig: clusterConfig,
ng: ng,
}
}
func (b *Windows) UserData() (string, error) {
bootstrapCommands := []string{
`<powershell>
[string]$EKSBootstrapScriptFile = "$env:ProgramFiles\Amazon\EKS\Start-EKSBootstrap.ps1"`,
}
bootstrapCommands = append(bootstrapCommands, b.ng.PreBootstrapCommands...)
eksBootstrapCommand := fmt.Sprintf("& $EKSBootstrapScriptFile %s 3>&1 4>&1 5>&1 6>&1", b.makeBootstrapParams())
bootstrapCommands = append(bootstrapCommands,
eksBootstrapCommand,
"</powershell>",
)
userData := base64.StdEncoding.EncodeToString([]byte(strings.Join(bootstrapCommands, "\n")))
logger.Debug("user-data = %s", userData)
return userData, nil
}
func (b *Windows) makeBootstrapParams() string {
params := []keyValue{
{
key: "EKSClusterName",
value: b.clusterConfig.Metadata.Name,
},
{
key: "APIServerEndpoint",
value: b.clusterConfig.Status.Endpoint,
},
{
key: "Base64ClusterCA",
value: base64.StdEncoding.EncodeToString(b.clusterConfig.Status.CertificateAuthorityData),
},
{
key: "DNSClusterIP",
value: b.ng.ClusterDNS,
},
{
key: "KubeletExtraArgs",
value: b.makeKubeletOptions(),
},
}
return formatWindowsParams(params)
}
func (b *Windows) makeKubeletOptions() string {
kubeletOptions := []keyValue{
{
key: "node-labels",
value: formatLabels(b.ng.Labels),
},
{
key: "register-with-taints",
value: utils.FormatTaints(b.ng.Taints),
},
}
if b.ng.MaxPodsPerNode != 0 {
kubeletOptions = append(kubeletOptions, keyValue{
key: "max-pods",
value: strconv.Itoa(b.ng.MaxPodsPerNode),
})
}
return toCLIArgs(kubeletOptions)
}
// formatWindowsParams formats params into `-key "value"`, ignoring keys with empty values
func formatWindowsParams(params []keyValue) string {
var args []string
for _, param := range params {
if param.value != "" {
args = append(args, fmt.Sprintf("-%s %q", param.key, param.value))
}
}
return strings.Join(args, " ")
}
func toCLIArgs(params []keyValue) string {
var args []string
for _, param := range params {
args = append(args, fmt.Sprintf("--%s=%s", param.key, param.value))
}
return strings.Join(args, " ")
}