1
+ import * as fs from "fs" ;
2
+
1
3
type NamespaceManifestOptions = {
2
- namespace : string
3
- }
4
+ namespace : string ;
5
+ } ;
4
6
5
7
export function NamespaceManifest ( { namespace } : NamespaceManifestOptions ) {
6
- return `
8
+ return `
7
9
apiVersion: v1
8
10
kind: Namespace
9
11
metadata:
10
12
name: ${ namespace }
11
- `
13
+ ` ;
12
14
}
13
15
14
16
type VirtualMachineManifestArguments = {
15
- vmName : string
16
- namespace : string
17
- claimName : string
18
- userDataSecretName : string
19
- }
17
+ vmName : string ;
18
+ namespace : string ;
19
+ claimName : string ;
20
+ userDataSecretName : string ;
21
+ } ;
20
22
21
- export function VirtualMachineManifest ( { vmName, namespace, claimName, userDataSecretName } : VirtualMachineManifestArguments ) {
22
- return `
23
+ export function VirtualMachineManifest ( {
24
+ vmName,
25
+ namespace,
26
+ claimName,
27
+ userDataSecretName,
28
+ } : VirtualMachineManifestArguments ) {
29
+ return `
23
30
apiVersion: kubevirt.io/v1
24
31
type: kubevirt.io.virtualmachine
25
32
kind: VirtualMachine
@@ -89,16 +96,16 @@ spec:
89
96
secretRef:
90
97
name: ${ userDataSecretName }
91
98
92
- `
99
+ ` ;
93
100
}
94
101
95
102
type ServiceManifestOptions = {
96
- vmName : string
97
- namespace : string
98
- }
103
+ vmName : string ;
104
+ namespace : string ;
105
+ } ;
99
106
100
107
export function ServiceManifest ( { vmName, namespace } : ServiceManifestOptions ) {
101
- return `
108
+ return `
102
109
apiVersion: v1
103
110
kind: Service
104
111
metadata:
@@ -137,12 +144,12 @@ spec:
137
144
selector:
138
145
harvesterhci.io/vmName: ${ vmName }
139
146
type: ClusterIP
140
- `
147
+ ` ;
141
148
}
142
149
143
150
type LBServiceManifestOptions = {
144
- name : string
145
- }
151
+ name : string ;
152
+ } ;
146
153
147
154
export function LBServiceManifest ( { name } : LBServiceManifestOptions ) {
148
155
return `
@@ -164,15 +171,15 @@ spec:
164
171
selector:
165
172
gitpod.io/lbName: ${ name }
166
173
type: LoadBalancer
167
- `
174
+ ` ;
168
175
}
169
176
170
177
type LBDeployManifestOptions = {
171
- name : string
172
- }
178
+ name : string ;
179
+ } ;
173
180
174
181
export function LBDeployManifest ( { name } : LBDeployManifestOptions ) {
175
- return `
182
+ return `
176
183
apiVersion: apps/v1
177
184
kind: Deployment
178
185
metadata:
@@ -216,17 +223,20 @@ spec:
216
223
mountPath: /mnt/kubeconfig/
217
224
serviceAccount: proxy
218
225
enableServiceLinks: false
219
- `
226
+ ` ;
220
227
}
221
228
222
229
type UserDataSecretManifestOptions = {
223
- vmName : string
224
- namespace : string ,
225
- secretName : string
226
- }
230
+ vmName : string ;
231
+ namespace : string ;
232
+ secretName : string ;
233
+ } ;
227
234
228
235
export function UserDataSecretManifest ( { vmName, namespace, secretName } : UserDataSecretManifestOptions ) {
229
- const userdata = Buffer . from ( `#cloud-config
236
+ const dockerhubUser = fs . readFileSync ( "/mnt/secrets/harvester-k3s-dockerhub-pull-account/username" ) . toString ( ) ;
237
+ const dockerhubPasswd = fs . readFileSync ( "/mnt/secrets/harvester-k3s-dockerhub-pull-account/password" ) . toString ( ) ;
238
+ const userdata = Buffer . from (
239
+ `#cloud-config
230
240
users:
231
241
- name: ubuntu
232
242
sudo: "ALL=(ALL) NOPASSWD: ALL"
@@ -255,6 +265,7 @@ write_files:
255
265
permission: 0644
256
266
owner: root
257
267
content: 'Port 2200'
268
+
258
269
- path: /usr/local/bin/bootstrap-k3s.sh
259
270
permissions: 0744
260
271
owner: root
@@ -263,6 +274,13 @@ write_files:
263
274
264
275
set -eo pipefail
265
276
277
+ cat <<EOF >> /etc/containerd/config.toml
278
+ [plugins."io.containerd.grpc.v1.cri".registry.configs."registry-1.docker.io".auth]
279
+ username = "${ dockerhubUser } "
280
+ password = "${ dockerhubPasswd } "
281
+ EOF
282
+ sudo systemctl restart containerd.service
283
+
266
284
# inspired by https://github.com/gitpod-io/ops/blob/main/deploy/workspace/templates/bootstrap.sh
267
285
268
286
# Install k3s
@@ -312,8 +330,9 @@ write_files:
312
330
EOF
313
331
runcmd:
314
332
- bash /etc/disable-services.sh
315
- - bash /usr/local/bin/bootstrap-k3s.sh` ) . toString ( "base64" )
316
- return `
333
+ - bash /usr/local/bin/bootstrap-k3s.sh` ,
334
+ ) . toString ( "base64" ) ;
335
+ return `
317
336
apiVersion: v1
318
337
type: secret
319
338
kind: Secret
@@ -323,5 +342,5 @@ data:
323
342
metadata:
324
343
name: ${ secretName }
325
344
namespace: ${ namespace }
326
- `
345
+ ` ;
327
346
}
0 commit comments