Skip to content

Commit 03750a9

Browse files
committed
code refactor
1 parent 1faf230 commit 03750a9

File tree

1 file changed

+1
-109
lines changed
  • bootstrap/eks/internal/userdata

1 file changed

+1
-109
lines changed

bootstrap/eks/internal/userdata/node.go

Lines changed: 1 addition & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/alessio/shellescape"
2626
"k8s.io/klog/v2"
2727
"k8s.io/utils/ptr"
28+
2829
eksbootstrapv1 "sigs.k8s.io/cluster-api-provider-aws/v2/bootstrap/eks/api/v1beta2"
2930
"sigs.k8s.io/cluster-api-provider-aws/v2/exp/api/v1beta2"
3031
)
@@ -49,12 +50,6 @@ runcmd:
4950
{{- template "disk_setup" .DiskSetup}}
5051
{{- template "fs_setup" .DiskSetup}}
5152
{{- template "mounts" .Mounts}}
52-
`
53-
54-
// Common MIME header and boundary template.
55-
mimeHeaderTemplate = `MIME-Version: 1.0
56-
Content-Type: multipart/mixed; boundary="{{.Boundary}}"
57-
5853
`
5954

6055
// Shell script part template for AL2023.
@@ -98,111 +93,8 @@ spec:
9893
- "--node-labels={{if and .KubeletExtraArgs (index .KubeletExtraArgs "node-labels")}}{{index .KubeletExtraArgs "node-labels"}}{{else}}eks.amazonaws.com/nodegroup-image={{if .AMIImageID}}{{.AMIImageID}}{{end}},eks.amazonaws.com/capacityType={{if .CapacityType}}{{.CapacityType}}{{else}}ON_DEMAND{{end}},eks.amazonaws.com/nodegroup={{.NodeGroupName}}{{end}}"
9994
10095
--{{.Boundary}}--`
101-
102-
// AL2023-specific templates.
103-
al2023KubeletExtraArgsTemplate = `{{- define "al2023KubeletExtraArgs" -}}
104-
{{- if . }}
105-
- "--node-labels={{range $k, $v := .}}{{$k}}={{$v}}{{end}}"
106-
{{- end -}}
107-
{{- end -}}`
108-
109-
al2023ContainerRuntimeTemplate = `{{- define "al2023ContainerRuntime" -}}
110-
{{- if . -}}
111-
containerRuntime: {{.}}
112-
{{- end -}}
113-
{{- end -}}`
114-
115-
al2023DockerConfigTemplate = `{{- define "al2023DockerConfig" -}}
116-
{{- if and . (ne . "''") -}}
117-
dockerConfig: {{.}}
118-
{{- end -}}
119-
{{- end -}}`
120-
121-
al2023APIRetryAttemptsTemplate = `{{- define "al2023APIRetryAttempts" -}}
122-
{{- if . -}}
123-
apiRetryAttempts: {{.}}
124-
{{- end -}}
125-
{{- end -}}`
126-
127-
al2023PauseContainerTemplate = `{{- define "al2023PauseContainer" -}}
128-
{{- if and .AccountNumber .Version -}}
129-
pauseContainer:
130-
accountNumber: {{.AccountNumber}}
131-
version: {{.Version}}
132-
{{- end -}}
133-
{{- end -}}`
134-
135-
al2023FilesTemplate = `{{- define "al2023Files" -}}
136-
{{- if . -}}
137-
files:{{ range . }}
138-
- path: {{.Path}}
139-
content: |
140-
{{.Content | Indent 8}}{{ if ne .Owner "" }}
141-
owner: {{.Owner}}{{ end }}{{ if ne .Permissions "" }}
142-
permissions: '{{.Permissions}}'{{ end }}{{ end }}
143-
{{- end -}}
144-
{{- end -}}`
145-
146-
al2023DiskSetupTemplate = `{{- define "al2023DiskSetup" -}}
147-
{{- if . -}}
148-
diskSetup:{{ if .Partitions }}
149-
partitions:{{ range .Partitions }}
150-
- device: {{.Device}}
151-
layout: {{.Layout}}{{ if .Overwrite }}
152-
overwrite: {{.Overwrite}}{{ end }}{{ if .TableType }}
153-
tableType: {{.TableType}}{{ end }}{{ end }}{{ end }}{{ if .Filesystems }}
154-
filesystems:{{ range .Filesystems }}
155-
- device: {{.Device}}
156-
filesystem: {{.Filesystem}}
157-
label: {{.Label}}{{ if .Partition }}
158-
partition: {{.Partition}}{{ end }}{{ if .Overwrite }}
159-
overwrite: {{.Overwrite}}{{ end }}{{ if .ExtraOpts }}
160-
extraOpts:{{ range .ExtraOpts }}
161-
- {{.}}{{ end }}{{ end }}{{ end }}{{ end }}
162-
{{- end -}}
163-
{{- end -}}`
164-
165-
al2023MountsTemplate = `{{- define "al2023Mounts" -}}
166-
{{- if . -}}
167-
mounts:{{ range . }}
168-
-{{ range . }}
169-
- {{.}}{{ end }}{{ end }}
170-
{{- end -}}
171-
{{- end -}}`
172-
173-
al2023UsersTemplate = `{{- define "al2023Users" -}}
174-
{{- if . -}}
175-
users:{{ range . }}
176-
- name: {{.Name}}{{ if .Gecos }}
177-
gecos: {{.Gecos}}{{ end }}{{ if .Groups }}
178-
groups: {{.Groups}}{{ end }}{{ if .HomeDir }}
179-
homeDir: {{.HomeDir}}{{ end }}{{ if .Inactive }}
180-
inactive: {{.Inactive}}{{ end }}{{ if .Shell }}
181-
shell: {{.Shell}}{{ end }}{{ if .Passwd }}
182-
passwd: {{.Passwd}}{{ end }}{{ if .PrimaryGroup }}
183-
primaryGroup: {{.PrimaryGroup}}{{ end }}{{ if .LockPassword }}
184-
lockPassword: {{.LockPassword}}{{ end }}{{ if .Sudo }}
185-
sudo: {{.Sudo}}{{ end }}{{ if .SSHAuthorizedKeys }}
186-
sshAuthorizedKeys:{{ range .SSHAuthorizedKeys }}
187-
- {{.}}{{ end }}{{ end }}{{ end }}
188-
{{- end -}}
189-
{{- end -}}`
190-
191-
al2023NTPTemplate = `{{- define "al2023NTP" -}}
192-
{{- if . -}}
193-
ntp:{{ if .Enabled }}
194-
enabled: true{{ end }}{{ if .Servers }}
195-
servers:{{ range .Servers }}
196-
- {{.}}{{ end }}{{ end }}
197-
{{- end -}}
198-
{{- end -}}`
19996
)
20097

201-
// NodeUserData is responsible for generating userdata for EKS nodes.
202-
type NodeUserData struct {
203-
input *NodeInput
204-
}
205-
20698
// NodeInput contains all the information required to generate user data for a node.
20799
type NodeInput struct {
208100
ClusterName string

0 commit comments

Comments
 (0)