Skip to content

Commit 16c25a9

Browse files
committed
[installer] Add upgrade test werft flag
1 parent b1a3665 commit 16c25a9

File tree

12 files changed

+343
-98
lines changed

12 files changed

+343
-98
lines changed

.werft/build.ts

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,81 @@
1-
import * as fs from 'fs';
2-
import { SpanStatusCode } from '@opentelemetry/api';
3-
import { Werft } from './util/werft';
4-
import { reportBuildFailureInSlack } from './util/slack';
5-
import * as Tracing from './observability/tracing'
6-
import * as VM from './vm/vm'
7-
import { buildAndPublish } from './jobs/build/build-and-publish';
8-
import { validateChanges } from './jobs/build/validate-changes';
9-
import { prepare } from './jobs/build/prepare';
10-
import { deployToPreviewEnvironment } from './jobs/build/deploy-to-preview-environment';
11-
import { triggerIntegrationTests } from './jobs/build/trigger-integration-tests';
12-
import { jobConfig } from './jobs/build/job-config';
13-
import { typecheckWerftJobs } from './jobs/build/typecheck-werft-jobs';
1+
import * as fs from "fs";
2+
import { SpanStatusCode } from "@opentelemetry/api";
3+
import { Werft } from "./util/werft";
4+
import { reportBuildFailureInSlack } from "./util/slack";
5+
import * as Tracing from "./observability/tracing";
6+
import * as VM from "./vm/vm";
7+
import { buildAndPublish } from "./jobs/build/build-and-publish";
8+
import { validateChanges } from "./jobs/build/validate-changes";
9+
import { prepare } from "./jobs/build/prepare";
10+
import { deployToPreviewEnvironment } from "./jobs/build/deploy-to-preview-environment";
11+
import { triggerIntegrationTests } from "./jobs/build/trigger-integration-tests";
12+
import { triggerUpgradeTests } from "./jobs/build/self-hosted-upgrade-tests";
13+
import { jobConfig } from "./jobs/build/job-config";
14+
import { typecheckWerftJobs } from "./jobs/build/typecheck-werft-jobs";
1415

1516
// Will be set once tracing has been initialized
16-
let werft: Werft
17-
const context: any = JSON.parse(fs.readFileSync('context.json').toString());
17+
let werft: Werft;
18+
const context: any = JSON.parse(fs.readFileSync("context.json").toString());
1819

1920
Tracing.initialize()
2021
.then(() => {
21-
werft = new Werft("build")
22+
werft = new Werft("build");
2223
})
2324
.then(() => run(context))
2425
.catch((err) => {
2526
werft.rootSpan.setStatus({
2627
code: SpanStatusCode.ERROR,
27-
message: err
28-
})
28+
message: err,
29+
});
2930

30-
console.log('Error', err)
31+
console.log("Error", err);
3132

3233
if (context.Repository.ref === "refs/heads/main") {
3334
reportBuildFailureInSlack(context, err).catch((error: Error) => {
34-
console.error("Failed to send message to Slack", error)
35+
console.error("Failed to send message to Slack", error);
3536
});
3637
}
3738

3839
// Explicitly not using process.exit as we need to flush tracing, see tracing.js
39-
process.exitCode = 1
40+
process.exitCode = 1;
4041
})
4142
.finally(() => {
42-
werft.phase("Stop kubectl port forwards", "Stopping kubectl port forwards")
43-
VM.stopKubectlPortForwards()
43+
werft.phase("Stop kubectl port forwards", "Stopping kubectl port forwards");
44+
VM.stopKubectlPortForwards();
4445

45-
werft.phase("Flushing telemetry", "Flushing telemetry before stopping job")
46-
werft.endAllSpans()
47-
})
46+
werft.phase("Flushing telemetry", "Flushing telemetry before stopping job");
47+
werft.endAllSpans();
48+
});
4849

4950
async function run(context: any) {
50-
const config = jobConfig(werft, context)
51+
const config = jobConfig(werft, context);
5152

52-
await validateChanges(werft, config)
53-
await prepare(werft, config)
54-
await typecheckWerftJobs(werft)
55-
await buildAndPublish(werft, config)
53+
await validateChanges(werft, config);
54+
await prepare(werft, config);
55+
if (config.withUpgradeTests) {
56+
// this will trigger an upgrade test on a self-hosted gitpod instance on a new cluster.
57+
await triggerUpgradeTests(werft, config, context.Owner);
58+
return;
59+
}
60+
await typecheckWerftJobs(werft);
61+
await buildAndPublish(werft, config);
5662

5763
if (config.noPreview) {
5864
werft.phase("deploy", "not deploying");
5965
console.log("no-preview or publish-release is set");
60-
return
66+
return;
6167
}
6268

6369
try {
64-
await deployToPreviewEnvironment(werft, config)
70+
await deployToPreviewEnvironment(werft, config);
6571
} catch (e) {
6672
// We currently don't support concurrent deployments to the same preview environment.
6773
// Until we do we don't want errors to mark the main build as failed.
6874
if (config.mainBuild) {
69-
return
75+
return;
7076
}
71-
throw e
77+
throw e;
7278
}
7379

74-
await triggerIntegrationTests(werft, config, context.Owner)
80+
await triggerIntegrationTests(werft, config, context.Owner);
7581
}

.werft/installer-tests.ts

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import { Werft } from "./util/werft";
44

55
const testConfig: string = process.argv.length > 2 ? process.argv[2] : "STANDARD_K3S_TEST";
66
// we can provide the version of the gitpod to install (eg: 2022.4.2)
7-
const version: string = process.argv.length > 3 ? process.argv[3] : "";
7+
// "-" is the default value which will install the latest version
8+
const version: string = process.argv.length > 3 ? process.argv[3] : "-";
9+
10+
const channel: string = process.argv.length > 4 ? process.argv[4] : "unstable";
811

912
const makefilePath: string = join("install/tests");
1013

@@ -41,14 +44,19 @@ const INFRA_PHASES: { [name: string]: InfraConfig } = {
4144
makeTarget: "managed-dns",
4245
description: "Sets up external-dns & cloudDNS config",
4346
},
47+
GENERATE_KOTS_CONFIG: {
48+
phase: "generate-kots-config",
49+
makeTarget: "generate-kots-config",
50+
description: `Generate KOTS Config file`,
51+
},
4452
INSTALL_GITPOD_IGNORE_PREFLIGHTS: {
4553
phase: "install-gitpod-without-preflights",
46-
makeTarget: `kots-install channel=unstable version=${version} preflights=false`, // this is a bit of a hack, for now we pass params like this
54+
makeTarget: `kots-install channel=${channel} version=${version} preflights=false`, // this is a bit of a hack, for now we pass params like this
4755
description: "Install gitpod using kots community edition without preflights",
4856
},
4957
INSTALL_GITPOD: {
5058
phase: "install-gitpod",
51-
makeTarget: `kots-install channel=unstable version=${version} preflights=true`,
59+
makeTarget: `kots-install channel=${channel} version=${version} preflights=true`,
5260
description: "Install gitpod using kots community edition",
5361
},
5462
CHECK_INSTALLATION: {
@@ -57,6 +65,11 @@ const INFRA_PHASES: { [name: string]: InfraConfig } = {
5765
makeTarget: "check-gitpod-installation",
5866
description: "Check gitpod installation",
5967
},
68+
KOTS_UPGRADE: {
69+
phase: "kots-upgrade",
70+
makeTarget: "kots-uprgade",
71+
description: "Upgrade Gitpod installation to latest version using KOTS CLI",
72+
},
6073
RUN_INTEGRATION_TESTS: {
6174
phase: "run-integration-tests",
6275
makeTarget: "run-tests",
@@ -88,21 +101,37 @@ const TEST_CONFIGURATIONS: { [name: string]: TestConfig } = {
88101
"STANDARD_GKE_CLUSTER",
89102
"CERT_MANAGER",
90103
"GCP_MANAGED_DNS",
104+
"GENERATE_KOTS_CONFIG",
91105
"INSTALL_GITPOD",
92106
"CHECK_INSTALLATION",
93107
"RUN_INTEGRATION_TESTS",
94108
"RESULTS",
95109
"DESTROY",
96110
],
97111
},
112+
STANDARD_GKE_UPGRADE_TEST: {
113+
DESCRIPTION: `Deploy Gitpod on GKE, and test upgrade from ${version} to latest version`,
114+
PHASES: [
115+
"STANDARD_GKE_CLUSTER",
116+
"CERT_MANAGER",
117+
"GCP_MANAGED_DNS",
118+
"GENERATE_KOTS_CONFIG",
119+
"INSTALL_GITPOD",
120+
"CHECK_INSTALLATION",
121+
"KOTS_UPGRADE",
122+
"CHECK_INSTALLATION",
123+
"DESTROY",
124+
],
125+
},
98126
STANDARD_K3S_TEST: {
99127
DESCRIPTION:
100128
"Deploy Gitpod on a K3s cluster, created on a GCP instance," +
101129
" with managed DNS and run integrations tests",
102130
PHASES: [
103131
"STANDARD_K3S_CLUSTER_ON_GCP",
104132
"CERT_MANAGER",
105-
"INSTALL_GITPOD_IGNORE_PREFLIGHTS",
133+
"GENERATE_KOTS_CONFIG",
134+
"INSTALL_GITPOD",
106135
"CHECK_INSTALLATION",
107136
"RUN_INTEGRATION_TESTS",
108137
"RESULTS",
@@ -113,8 +142,9 @@ const TEST_CONFIGURATIONS: { [name: string]: TestConfig } = {
113142
DESCRIPTION: "Create a SH Gitpod preview environment on a K3s cluster, created on a GCP instance",
114143
PHASES: [
115144
"STANDARD_K3S_CLUSTER_ON_GCP",
116-
"GCP_MANAGED_DNS",
117-
"INSTALL_GITPOD_IGNORE_PREFLIGHTS",
145+
"CERT_MANAGER",
146+
"GENERATE_KOTS_CONFIG",
147+
"INSTALL_GITPOD",
118148
"CHECK_INSTALLATION",
119149
"RESULTS",
120150
],
@@ -144,8 +174,9 @@ function getKubeconfig() {
144174
export async function installerTests(config: TestConfig) {
145175
console.log(config.DESCRIPTION);
146176
for (let phase of config.PHASES) {
147-
const phaseSteps = INFRA_PHASES[phase];
148-
const ret = callMakeTargets(phaseSteps.phase, phaseSteps.description, phaseSteps.makeTarget);
177+
const args = phase.split(" ");
178+
const phaseSteps = INFRA_PHASES[args[0]];
179+
const ret = callMakeTargets(phaseSteps.phase, phaseSteps.description, phaseSteps.makeTarget, args.slice(1));
149180
if (ret) {
150181
// there is not point in continuing if one stage fails
151182
// TODO: maybe add failable, phases
@@ -154,8 +185,8 @@ export async function installerTests(config: TestConfig) {
154185
}
155186
}
156187

157-
function callMakeTargets(phase: string, description: string, makeTarget: string) {
158-
werft.phase(phase, description);
188+
function callMakeTargets(phase: string, description: string, makeTarget: string, args: string[]) {
189+
werft.phase(phase, `${description} ${args}`);
159190

160191
const response = exec(`make -C ${makefilePath} ${makeTarget}`, { slice: "call-make-target", dontCheckRc: true });
161192

@@ -170,6 +201,10 @@ function callMakeTargets(phase: string, description: string, makeTarget: string)
170201
return response.code;
171202
}
172203

204+
function sample(stages: string[]): string {
205+
return stages[Math.floor(Math.random() * stages.length)];
206+
}
207+
173208
function cleanup() {
174209
const phase = "destroy-infrastructure";
175210
werft.phase(phase, "Destroying all the created resources");

0 commit comments

Comments
 (0)