Skip to content

Commit af9728b

Browse files
author
Prince Rachit Sinha
committed
Refactor to support k3s ws deployment
1 parent 71e54a4 commit af9728b

File tree

2 files changed

+152
-73
lines changed

2 files changed

+152
-73
lines changed

.werft/build.ts

Lines changed: 113 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -298,18 +298,16 @@ export async function deployToDev(deploymentConfig: DeploymentConfig, workspaceF
298298
try {
299299
if (deploymentConfig.cleanSlateDeployment) {
300300
// re-create namespace
301-
await wipeAndRecreateNamespace("", helmInstallName, namespace, { slice: 'prep' });
302-
// cleanup non-namespace objects
303-
werft.log("predeploy cleanup", "removing old unnamespaced objects - this might take a while");
304-
try {
305-
deleteNonNamespaceObjects("", namespace, destname, { slice: 'predeploy cleanup' })
306-
werft.done('predeploy cleanup');
307-
} catch (err) {
308-
werft.fail('predeploy cleanup', err);
301+
for (const pathToKubeConfig in [""]) {
302+
await cleanStateEnv(pathToKubeConfig);
309303
}
304+
310305
} else {
311-
createNamespace("", namespace, { slice: 'prep' });
306+
for (const pathToKubeConfig in [""]) {
307+
createNamespace(pathToKubeConfig, namespace, { slice: 'prep' });
308+
}
312309
}
310+
// check how this affects further steps
313311
setKubectlContextNamespace(namespace, { slice: 'prep' });
314312
namespaceRecreatedResolve(); // <-- signal for certificate
315313
werft.done('prep');
@@ -350,67 +348,43 @@ export async function deployToDev(deploymentConfig: DeploymentConfig, workspaceF
350348
// core-dev specific section end
351349

352350
// deployment config
353-
let flags = "";
354-
flags += ` --namespace ${namespace}`;
355-
flags += ` --set components.imageBuilder.hostDindData=/mnt/disks/ssd0/docker-${namespace}`;
356-
flags += ` --set version=${version}`;
357-
flags += ` --set hostname=${domain}`;
358-
flags += ` --set devBranch=${destname}`;
359-
flags += ` --set components.wsDaemon.servicePort=${wsdaemonPort}`;
360-
flags += ` --set components.registryFacade.ports.registry.servicePort=${registryNodePort}`;
361-
workspaceFeatureFlags.forEach((f, i) => {
362-
flags += ` --set components.server.defaultFeatureFlags[${i}]='${f}'`
363-
})
364-
if (dynamicCPULimits) {
365-
flags += ` -f ../.werft/values.variant.cpuLimits.yaml`;
366-
}
367-
if (withWsCluster) {
368-
// Create redirect ${withWsCluster.shortname} -> ws-proxy.${wsCluster.dstNamespace}
369-
flags += ` --set components.proxy.withWsCluster.shortname=${withWsCluster.shortname}`;
370-
flags += ` --set components.proxy.withWsCluster.namespace=${withWsCluster.namespace}`;
371-
}
372-
if (wsCluster) {
373-
flags += ` --set hostname=${wsCluster.domain}`;
374-
flags += ` --set installation.shortname=${wsCluster.shortname}`;
375-
376-
flags += ` -f ../.werft/values.wsCluster.yaml`;
377-
}
378-
if ((deploymentConfig.analytics || "").startsWith("segment|")) {
379-
flags += ` --set analytics.writer=segment`;
380-
flags += ` --set analytics.segmentKey=${deploymentConfig.analytics!.substring("segment|".length)}`
381-
} else if (!!deploymentConfig.analytics) {
382-
flags += ` --set analytics.writer=${deploymentConfig.analytics!}`;
383-
}
351+
let commonFlags = addDeploymentFlags();
384352

385-
werft.log("helm", "extracting versions");
386353
try {
387-
exec(`docker run --rm eu.gcr.io/gitpod-core-dev/build/versions:${version} cat /versions.yaml | tee versions.yaml`);
354+
shell.cd("chart");
355+
werft.log('helm', 'installing Gitpod');
356+
357+
installGitpod(commonFlags);
358+
installGitpodOnK3sWsCluster(commonFlags, "/workspace/k3s-external.yaml");
359+
360+
werft.log('helm', 'done');
361+
werft.done('helm');
388362
} catch (err) {
389-
werft.fail('helm', err);
363+
werft.fail('deploy', err);
364+
} finally {
365+
// produce the result independently of Helm succeding, so that in case Helm fails we still have the URL.
366+
exec(`werft log result -d "dev installation" -c github url ${url}/workspaces/`);
390367
}
391-
const pathToVersions = `${shell.pwd().toString()}/versions.yaml`;
392-
flags += ` -f ${pathToVersions}`;
393368

394-
if (!certificatePromise) {
395-
// it's not possible to set certificatesSecret={} so we set secretName to empty string
396-
flags += ` --set certificatesSecret.secretName=""`;
369+
if (certificatePromise) {
370+
// Delay success until certificate is actually present
371+
werft.log('certificate', "awaiting promised certificate")
372+
try {
373+
await certificatePromise;
374+
werft.done('certificate');
375+
} catch (err) {
376+
werft.log('certificate', err.toString()); // This ensures the err message is picked up by the werft UI
377+
werft.fail('certificate', err);
378+
}
397379
}
398380

399-
try {
400-
shell.cd("chart");
401-
werft.log('helm', 'installing Gitpod');
402-
381+
function installGitpod(commonFlags: string) {
382+
let flags = commonFlags
403383
if (storage === "gcp") {
404-
exec("kubectl get secret gcp-sa-cloud-storage-dev-sync-key -n werft -o yaml | yq d - metadata | yq w - metadata.name remote-storage-gcloud | kubectl apply -f -")
384+
exec("kubectl get secret gcp-sa-cloud-storage-dev-sync-key -n werft -o yaml | yq d - metadata | yq w - metadata.name remote-storage-gcloud | kubectl apply -f -");
405385
flags += ` -f ../.werft/values.dev.gcp-storage.yaml`;
406386
}
407387

408-
if (deploymentConfig.installEELicense) {
409-
// We're adding the license rather late just to prevent accidentially printing it.
410-
// If anyone got ahold of the license not much would be lost, but hey, no need to plaster it on the walls.
411-
flags += ` --set license=${fs.readFileSync('/mnt/secrets/gpsh-coredev/license').toString()}`
412-
}
413-
414388
exec(`helm dependencies up`);
415389
exec(`/usr/local/bin/helm3 upgrade --install --timeout 10m -f ../.werft/values.dev.yaml ${flags} ${helmInstallName} .`);
416390
exec(`kubectl apply -f ../.werft/jaeger.yaml`);
@@ -421,25 +395,91 @@ export async function deployToDev(deploymentConfig: DeploymentConfig, workspaceF
421395
werft.log('helm', `Sweeper version: ${sweeperVersion}`);
422396
exec(`/usr/local/bin/helm3 upgrade --install --set image.version=${sweeperVersion} --set command="werft run github -a namespace=${namespace} --remote-job-path .werft/wipe-devstaging.yaml github.com/gitpod-io/gitpod:main" sweeper ../dev/charts/sweeper`);
423397
}
398+
}
399+
400+
function installGitpodOnK3sWsCluster(commonFlags: string, pathToKubeConfig: string) {
401+
if(!k3sWsCluster){
402+
return
403+
}
404+
let flags = commonFlags
405+
flags += ` -f ../.werft/values.k3sWsCluster.yaml`;
406+
if (storage === "gcp") {
407+
// notice below that we are not using the k3s cluster to get the gcp-sa-cloud-storage-dev-sync-key. As it is present in the dev cluster only
408+
exec("kubectl get secret gcp-sa-cloud-storage-dev-sync-key -n werft -o yaml | yq d - metadata | yq w - metadata.name remote-storage-gcloud > remote-storage-gcloud.yaml");
409+
// After storing the yaml we apply it to the k3s cluster
410+
exec(`export KUBECONFIG=${pathToKubeConfig} && kubectl apply -f remote-storage-gcloud.yaml`)
411+
flags += ` -f ../.werft/values.dev.gcp-storage.yaml`;
412+
}
424413

425-
werft.log('helm', 'done');
426-
werft.done('helm');
427-
} catch (err) {
428-
werft.fail('deploy', err);
429-
} finally {
430-
// produce the result independently of Helm succeding, so that in case Helm fails we still have the URL.
431-
exec(`werft log result -d "dev installation" -c github url ${url}/workspaces/`);
414+
exec(`export KUBECONFIG=${pathToKubeConfig} && helm dependencies up`);
415+
exec(`export KUBECONFIG=${pathToKubeConfig} && /usr/local/bin/helm3 upgrade --install --timeout 10m -f ../.werft/values.dev.yaml ${flags} ${helmInstallName} .`);
416+
// exec(`export KUBECONFIG=${pathToKubeConfig} && kubectl apply -f ../.werft/jaeger.yaml`);
432417
}
433418

434-
if (certificatePromise) {
435-
// Delay success until certificate is actually present
436-
werft.log('certificate', "awaiting promised certificate")
419+
function addDeploymentFlags() {
420+
let flags = ""
421+
flags += ` --namespace ${namespace}`;
422+
flags += ` --set components.imageBuilder.hostDindData=/mnt/disks/ssd0/docker-${namespace}`;
423+
flags += ` --set version=${version}`;
424+
flags += ` --set hostname=${domain}`;
425+
flags += ` --set devBranch=${destname}`;
426+
flags += ` --set components.wsDaemon.servicePort=${wsdaemonPort}`;
427+
flags += ` --set components.registryFacade.ports.registry.servicePort=${registryNodePort}`;
428+
workspaceFeatureFlags.forEach((f, i) => {
429+
flags += ` --set components.server.defaultFeatureFlags[${i}]='${f}'`;
430+
});
431+
if (dynamicCPULimits) {
432+
flags += ` -f ../.werft/values.variant.cpuLimits.yaml`;
433+
}
434+
if (withWsCluster) {
435+
// Create redirect ${withWsCluster.shortname} -> ws-proxy.${wsCluster.dstNamespace}
436+
flags += ` --set components.proxy.withWsCluster.shortname=${withWsCluster.shortname}`;
437+
flags += ` --set components.proxy.withWsCluster.namespace=${withWsCluster.namespace}`;
438+
}
439+
if (wsCluster) {
440+
flags += ` --set hostname=${wsCluster.domain}`;
441+
flags += ` --set installation.shortname=${wsCluster.shortname}`;
442+
443+
flags += ` -f ../.werft/values.wsCluster.yaml`;
444+
}
445+
if ((deploymentConfig.analytics || "").startsWith("segment|")) {
446+
flags += ` --set analytics.writer=segment`;
447+
flags += ` --set analytics.segmentKey=${deploymentConfig.analytics!.substring("segment|".length)}`;
448+
} else if (!!deploymentConfig.analytics) {
449+
flags += ` --set analytics.writer=${deploymentConfig.analytics!}`;
450+
}
451+
452+
werft.log("helm", "extracting versions");
437453
try {
438-
await certificatePromise;
439-
werft.done('certificate');
454+
exec(`docker run --rm eu.gcr.io/gitpod-core-dev/build/versions:${version} cat /versions.yaml | tee versions.yaml`);
440455
} catch (err) {
441-
werft.log('certificate', err.toString()); // This ensures the err message is picked up by the werft UI
442-
werft.fail('certificate', err);
456+
werft.fail('helm', err);
457+
}
458+
const pathToVersions = `${shell.pwd().toString()}/versions.yaml`;
459+
flags += ` -f ${pathToVersions}`;
460+
461+
if (!certificatePromise) {
462+
// it's not possible to set certificatesSecret={} so we set secretName to empty string
463+
flags += ` --set certificatesSecret.secretName=""`;
464+
}
465+
466+
if (deploymentConfig.installEELicense) {
467+
// We're adding the license rather late just to prevent accidentially printing it.
468+
// If anyone got ahold of the license not much would be lost, but hey, no need to plaster it on the walls.
469+
flags += ` --set license=${fs.readFileSync('/mnt/secrets/gpsh-coredev/license').toString()}`
470+
}
471+
return flags;
472+
}
473+
474+
async function cleanStateEnv(pathToKubeConfig: string) {
475+
await wipeAndRecreateNamespace(pathToKubeConfig, helmInstallName, namespace, { slice: 'prep' });
476+
// cleanup non-namespace objects
477+
werft.log("predeploy cleanup", "removing old unnamespaced objects - this might take a while");
478+
try {
479+
deleteNonNamespaceObjects(pathToKubeConfig, namespace, destname, { slice: 'predeploy cleanup' });
480+
werft.done('predeploy cleanup');
481+
} catch (err) {
482+
werft.fail('predeploy cleanup', err);
443483
}
444484
}
445485

.werft/values.k3sWsCluster.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
components:
3+
proxy:
4+
disabled: true
5+
6+
wsProxy:
7+
hostHeader: Host
8+
9+
wsManagerBridge:
10+
disabled: true
11+
12+
server:
13+
disabled: true
14+
15+
messagebus:
16+
disabled: true
17+
18+
dashboard:
19+
disabled: true
20+
21+
dbMigrations:
22+
disabled: true
23+
24+
db:
25+
autoMigrate: false
26+
27+
imageBuilder:
28+
disabled: true
29+
30+
minio:
31+
enabled: false
32+
accessKey: EXAMPLEvalue
33+
secretKey: Someone.Should/ReallyChangeThisKey!!
34+
35+
mysql:
36+
enabled: false
37+
38+
registry-facade:
39+
enabled: false

0 commit comments

Comments
 (0)