@@ -14,10 +14,11 @@ metadata:
14
14
type VirtualMachineManifestArguments = {
15
15
vmName : string
16
16
namespace : string
17
- claimName : string ,
17
+ claimName : string
18
+ userDataSecretName : string
18
19
}
19
20
20
- export function VirtualMachineManifest ( { vmName, namespace, claimName } : VirtualMachineManifestArguments ) {
21
+ export function VirtualMachineManifest ( { vmName, namespace, claimName, userDataSecretName } : VirtualMachineManifestArguments ) {
21
22
return `
22
23
apiVersion: kubevirt.io/v1
23
24
type: kubevirt.io.virtualmachine
@@ -75,23 +76,11 @@ spec:
75
76
claimName: ${ claimName }
76
77
- name: cloudinitdisk
77
78
cloudInitNoCloud:
78
- userData: |-
79
- #cloud-config
80
- users:
81
- - name: ubuntu
82
- sudo: "ALL=(ALL) NOPASSWD: ALL"
83
- ssh_authorized_keys:
84
- - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC/aB/HYsb56V0NBOEab6j33v3LIxRiGqG4fmidAryAXevLyTANJPF8m44KSzSQg7AI7PMy6egxQp/JqH2b+3z1cItWuHZSU+klsKNuf5HxK7AOrND3ahbejZfyYewtKFQ3X9rv5Sk8TAR5gw5oPbkTR61jiLa58Sw7UkhLm2EDguGASb6mBal8iboiF8Wpl8QIvPmJaGIOY2YwXLepwFA3S3kVqW88eh2WFmjTMre5ASLguYNkHXjyb/TuhVFzAvphzpl84RAaEyjKYnk45fh4xRXx+oKqlfKRJJ/Owxa7SmGO+/4rWb3chdnpodHeu7XjERmjYLY+r46sf6n6ySgEht1xAWjMb1uqZqkDx+fDDsjFSeaN3ncX6HSoDOrphFmXYSwaMpZ8v67A791fuUPrMLC+YMckhTuX2g4i3XUdumIWvhaMvKhy/JRRMsfUH0h+KAkBLI6tn5ozoXiQhgM4SAE5HsMr6CydSIzab0yY3sq0avmZgeoc78+8PKPkZG1zRMEspV/hKKBC8hq7nm0bu4IgzuEIYHowOD8svqA0ufhDWxTt6A4Jo0xDzhFyKme7KfmW7SIhpejf3T1Wlf+QINs1hURr8LSOZEyY2SzYmAoQ49N0SSPb5xyG44cptpKcj0WCAJjBJoZqz0F5x9TjJ8XToB5obyJfRHD1JjxoMQ== [email protected]
85
- chpasswd:
86
- list: |
87
- ubuntu:ubuntu
88
- expire: False
89
- runcmd:
90
- - curl -sfL https://get.k3s.io | sh -
91
- - sleep 10
92
- - kubectl label nodes ${ vmName } gitpod.io/workload_meta=true gitpod.io/workload_ide=true gitpod.io/workload_workspace_services=true gitpod.io/workload_workspace_regular=true gitpod.io/workload_workspace_headless=true gitpod.io/workspace_0=true gitpod.io/workspace_1=true gitpod.io/workspace_2=true
93
- - kubectl create ns certs
94
- - kubectl apply -f https://github.com/jetstack/cert-manager/releases/download/v1.6.1/cert-manager.yaml
79
+ networkDataSecretRef:
80
+ name: ${ userDataSecretName }
81
+ secretRef:
82
+ name: ${ userDataSecretName }
83
+
95
84
`
96
85
}
97
86
@@ -132,6 +121,82 @@ spec:
132
121
}
133
122
134
123
type UserDataSecretManifestOptions = {
124
+ vmName : string
135
125
namespace : string ,
136
126
secretName : string
137
127
}
128
+
129
+ export function UserDataSecretManifest ( { vmName, namespace, secretName } : UserDataSecretManifestOptions ) {
130
+ const userdata = Buffer . from ( `#cloud-config
131
+ users:
132
+ - name: ubuntu
133
+ sudo: "ALL=(ALL) NOPASSWD: ALL"
134
+ ssh_authorized_keys:
135
+ - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC/aB/HYsb56V0NBOEab6j33v3LIxRiGqG4fmidAryAXevLyTANJPF8m44KSzSQg7AI7PMy6egxQp/JqH2b+3z1cItWuHZSU+klsKNuf5HxK7AOrND3ahbejZfyYewtKFQ3X9rv5Sk8TAR5gw5oPbkTR61jiLa58Sw7UkhLm2EDguGASb6mBal8iboiF8Wpl8QIvPmJaGIOY2YwXLepwFA3S3kVqW88eh2WFmjTMre5ASLguYNkHXjyb/TuhVFzAvphzpl84RAaEyjKYnk45fh4xRXx+oKqlfKRJJ/Owxa7SmGO+/4rWb3chdnpodHeu7XjERmjYLY+r46sf6n6ySgEht1xAWjMb1uqZqkDx+fDDsjFSeaN3ncX6HSoDOrphFmXYSwaMpZ8v67A791fuUPrMLC+YMckhTuX2g4i3XUdumIWvhaMvKhy/JRRMsfUH0h+KAkBLI6tn5ozoXiQhgM4SAE5HsMr6CydSIzab0yY3sq0avmZgeoc78+8PKPkZG1zRMEspV/hKKBC8hq7nm0bu4IgzuEIYHowOD8svqA0ufhDWxTt6A4Jo0xDzhFyKme7KfmW7SIhpejf3T1Wlf+QINs1hURr8LSOZEyY2SzYmAoQ49N0SSPb5xyG44cptpKcj0WCAJjBJoZqz0F5x9TjJ8XToB5obyJfRHD1JjxoMQ== [email protected]
136
+ chpasswd:
137
+ list: |
138
+ ubuntu:ubuntu
139
+ expire: False
140
+ write_files:
141
+ - path: /usr/local/bin/bootstrap-k3s.sh
142
+ permissions: 0744
143
+ owner: root
144
+ content: |
145
+ #!/bin/bash
146
+
147
+ set -eo pipefail
148
+
149
+ # inspired by https://github.com/gitpod-io/ops/blob/main/deploy/workspace/templates/bootstrap.sh
150
+
151
+ # Install k3s
152
+ export INSTALL_K3S_SKIP_DOWNLOAD=true
153
+
154
+ /usr/local/bin/install-k3s.sh \
155
+ --token "1234" \
156
+ --node-ip "$(hostname -I | cut -d ' ' -f1)" \
157
+ --node-label "cloud.google.com/gke-nodepool=control-plane-pool" \
158
+ --container-runtime-endpoint=/var/run/containerd/containerd.sock \
159
+ --write-kubeconfig-mode 444 \
160
+ --disable servicelb \
161
+ --disable traefik \
162
+ --disable local-storage \
163
+ --disable metrics-server \
164
+ --flannel-backend=none \
165
+ --kubelet-arg config=/etc/kubernetes/kubelet-config.json \
166
+ --kubelet-arg feature-gates=LocalStorageCapacityIsolation=true \
167
+ --kubelet-arg feature-gates=LocalStorageCapacityIsolationFSQuotaMonitoring=true \
168
+ --kube-apiserver-arg feature-gates=LocalStorageCapacityIsolation=true \
169
+ --kube-apiserver-arg feature-gates=LocalStorageCapacityIsolationFSQuotaMonitoring=true \
170
+ --cluster-init
171
+
172
+ kubectl label nodes ${ vmName } \
173
+ gitpod.io/workload_meta=true \
174
+ gitpod.io/workload_ide=true \
175
+ gitpod.io/workload_workspace_services=true \
176
+ gitpod.io/workload_workspace_regular=true \
177
+ gitpod.io/workload_workspace_headless=true \
178
+ gitpod.io/workspace_0=true \
179
+ gitpod.io/workspace_1=true \
180
+ gitpod.io/workspace_2=true
181
+
182
+ kubectl apply -f /var/lib/gitpod/manifests/calico.yaml
183
+ kubectl apply -f /var/lib/gitpod/manifests/cert-manager.yaml
184
+ kubectl apply -f /var/lib/gitpod/manifests/metrics-server.yaml
185
+
186
+ cat <<EOF >> /root/.bashrc
187
+ export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
188
+ EOF
189
+ runcmd:
190
+ - bash /usr/local/bin/bootstrap-k3s.sh` ) . toString ( "base64" )
191
+ return `
192
+ apiVersion: v1
193
+ type: secret
194
+ kind: Secret
195
+ data:
196
+ networkdata: ""
197
+ userdata: ${ userdata }
198
+ metadata:
199
+ name: ${ secretName }
200
+ namespace: ${ namespace }
201
+ `
202
+ }
0 commit comments