Skip to content

Commit 2b2db1a

Browse files
committed
WIP: Move manifest to TS
1 parent 01f3831 commit 2b2db1a

File tree

3 files changed

+99
-13
lines changed

3 files changed

+99
-13
lines changed

.werft/build.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { createHash } from "crypto";
1414
import { InstallMonitoringSatelliteParams, installMonitoringSatellite, observabilityStaticChecks } from './observability/monitoring-satellite';
1515
import { SpanStatusCode } from '@opentelemetry/api';
1616
import * as Tracing from './observability/tracing'
17+
import * as VM from './vm/vm'
1718

1819
// Will be set once tracing has been initialized
1920
let werft: Werft
@@ -264,19 +265,6 @@ export async function build(context, version) {
264265
return
265266
}
266267

267-
if (withVM) {
268-
// Ask Harvester to boot the VM and wait for it to be ready.
269-
270-
// Werft would need to download the kubeconfig file and place it under
271-
// ~/.kube/config-harvester
272-
// For now we could just place the kubeconfig in a k8s secret and mount it.
273-
// and then use --kubeconfig <path to secret> for kubectl invocations
274-
//
275-
// kubectl get vms would be a first good prototype invocation.
276-
exec(`kubectl --kubeconfig /mnt/secrets/harvester-kubeconfig/harvester-kubeconfig.yml get vms`)
277-
return
278-
}
279-
280268
const destname = version.split(".")[0];
281269
const namespace = `staging-${destname}`;
282270
const domain = `${destname}.staging.gitpod-dev.com`;
@@ -297,6 +285,19 @@ export async function build(context, version) {
297285
withObservability,
298286
};
299287

288+
if (withVM) {
289+
werft.phase("vm", "Start VM");
290+
VM.startVM({ name: destname })
291+
292+
//TODO:
293+
// Wait for the VM to start
294+
// Once started grab the kubeconfg from inside the booted VM and set it as the kubeconfg for the rest of the job
295+
// Using the Harvester cluster start a proxy to the booted VM so kubectl can communicate with the cluster in the VM
296+
// When it is using the new kubeconfig.
297+
298+
return
299+
}
300+
300301
werft.phase(phases.PREDEPLOY, "Checking for existing installations...");
301302
// the context namespace is not set at this point
302303
const hasGitpodHelmInstall = exec(`helm status ${helmInstallName} -n ${deploymentConfig.namespace}`, {slice: "check for Helm install", dontCheckRc: true}).code === 0;

.werft/vm/manifests.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
2+
type VirtualMachineManifestArguments = {
3+
name: string
4+
claimName: string
5+
}
6+
7+
export function VirtualMachineManifest({ name, claimName }: VirtualMachineManifestArguments) {
8+
return `
9+
apiVersion: kubevirt.io/v1
10+
type: kubevirt.io.virtualmachine
11+
kind: VirtualMachine
12+
metadata:
13+
namespace: default
14+
annotations:
15+
harvesterhci.io/volumeClaimTemplates: >-
16+
[{"metadata":{"name":"${claimName}","annotations":{"harvesterhci.io/imageId":"default/image-cjlm2"}},"spec":{"accessModes":["ReadWriteMany"],"resources":{"requests":{"storage":"10Gi"}},"volumeMode":"Block","storageClassName":"longhorn-image-cjlm2"}}]
17+
network.harvesterhci.io/ips: "[]"
18+
labels:
19+
harvesterhci.io/creator: harvester
20+
harvesterhci.io/os: ubuntu
21+
name: ${name}
22+
spec:
23+
running: true
24+
template:
25+
metadata:
26+
annotations:
27+
harvesterhci.io/sshNames: "[]"
28+
labels:
29+
harvesterhci.io/vmName: ${name}
30+
spec:
31+
domain:
32+
machine:
33+
type: q35
34+
cpu:
35+
cores: 1
36+
sockets: 1
37+
threads: 1
38+
devices:
39+
inputs:
40+
- bus: usb
41+
name: tablet
42+
type: tablet
43+
interfaces:
44+
- masquerade: {}
45+
model: virtio
46+
name: default
47+
disks:
48+
- name: disk-0
49+
disk:
50+
bus: virtio
51+
bootOrder: 1
52+
resources:
53+
limits:
54+
memory: 2Gi
55+
cpu: 1
56+
evictionStrategy: LiveMigrate
57+
hostname: ${name}
58+
networks:
59+
- pod: {}
60+
name: default
61+
volumes:
62+
- name: disk-0
63+
persistentVolumeClaim:
64+
claimName: ${claimName}
65+
`
66+
}

.werft/vm/vm.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { exec } from '../util/shell';
2+
3+
import * as Manifests from './manifests'
4+
5+
/**
6+
* Start a VM
7+
* Does not wait for the VM to be ready.
8+
*/
9+
export function startVM(options: { name: string }) {
10+
const claimName = `${options.name}-${Date.now()}`
11+
const manifest = Manifests.VirtualMachineManifest({ name: options.name, claimName })
12+
const r = exec(`
13+
cat <<EOF | kubectl --kubeconfig /mnt/secrets/harvester-kubeconfig/harvester-kubeconfig.yml -n default apply -f -
14+
${manifest}
15+
EOF
16+
`)
17+
}
18+
19+

0 commit comments

Comments
 (0)