Skip to content

Commit c0175ce

Browse files
committed
cleaning up customer license
1 parent ee23ab0 commit c0175ce

File tree

3 files changed

+69
-4
lines changed

3 files changed

+69
-4
lines changed

.werft/installer-tests.ts

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as https from "https";
33
import { join } from "path";
44
import { exec } from "./util/shell";
55
import { Werft } from "./util/werft";
6+
import { deleteReplicatedLicense } from "./jobs/build/self-hosted-upgrade-tests";
67

78
const context: any = JSON.parse(fs.readFileSync("context.json").toString());
89

@@ -13,6 +14,7 @@ const testConfig: string = process.argv.length > 2 ? process.argv[2] : "STANDARD
1314
const channel: string = annotations.channel || "unstable";
1415
const version: string = annotations.version || "-";
1516
const preview: string = annotations.preview || "false"; // setting to true will not destroy the setup
17+
const customerID: string = annotations.customerID || "";
1618
const upgrade: string = annotations.upgrade || "false"; // setting to true will not KOTS upgrade to the latest version. Set the channel to beta or stable in this case.
1719
const skipTests: string = annotations.skipTests || "false"; // setting to true skips the integration tests
1820
const deps: string = annotations.deps || ""; // options: ["external", "internal"] setting to `external` will ensure that all resource dependencies(storage, db, registry) will be external. if unset, a random selection will be used
@@ -261,6 +263,7 @@ if (config === undefined) {
261263

262264
installerTests(TEST_CONFIGURATIONS[testConfig]).catch((err) => {
263265
cleanup();
266+
deleteReplicatedLicense(werft, customerID);
264267
console.error(err);
265268
process.exit(1);
266269
});
@@ -341,6 +344,9 @@ export async function installerTests(config: TestConfig) {
341344
// if we are not doing preview, we delete the infrastructure
342345
cleanup();
343346
}
347+
348+
deleteReplicatedLicense(werft, customerID)
349+
344350
}
345351

346352
function runIntegrationTests() {

.werft/jobs/build/self-hosted-upgrade-tests.ts

+58-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { exec } from "../../util/shell";
22
import { Werft } from "../../util/werft";
33
import { JobConfig } from "./job-config";
4+
import * as https from "https";
45

56
interface config {
67
phase: string;
@@ -71,16 +72,21 @@ export async function triggerUpgradeTests(werft: Werft, config: JobConfig, usern
7172
export async function triggerSelfHostedPreview(werft: Werft, config: JobConfig, username: string) {
7273
const replicatedChannel = config.replicatedChannel || config.repository.branch;
7374
const cluster = config.cluster || "k3s";
75+
const subdomain = `${replicatedChannel.replace("/", "-").slice(0,10)}-${cluster}`
7476

7577
var licenseFlag: string = ""
78+
var customerID: string = ""
79+
var annotation: string = ""
80+
81+
7682

7783
if(!["stable", "unstable", "beta"].includes(replicatedChannel.toLowerCase())){
7884
werft.phase("get-replicated-license", `Create and download replicated license for ${replicatedChannel}`);
7985

80-
exec(`replicated customer create --channel ${replicatedChannel} --name ${replicatedChannel}`,
86+
exec(`replicated customer create --channel ${replicatedChannel} --name ${config.version}`,
8187
{ slice: "get-replicated-license"})
8288

83-
exec(`replicated customer download-license --customer ${replicatedChannel} > license.yaml`,
89+
exec(`replicated customer download-license --customer ${config.version} > license.yaml`,
8490
{ slice: "get-replicated-license", dontCheckRc: true})
8591

8692
exec(`install -D license.yaml install/licenses/${replicatedChannel}.yaml`,
@@ -89,16 +95,26 @@ export async function triggerSelfHostedPreview(werft: Werft, config: JobConfig,
8995
werft.done("get-replicated-license");
9096

9197
licenseFlag = `-s install/licenses/${replicatedChannel}.yaml`
98+
99+
const ret = exec(`replicated customer ls | grep ${config.version} | awk '{print $1}'`,
100+
{ slice: "get-replicated-license", dontCheckRc: true})
101+
102+
const customerIDS = ret.stdout.split("\n").filter(item => item);
103+
if(customerIDS.length > 0) {
104+
customerID = customerIDS[0].trim()
105+
annotation = `-a customerID=${customerID}`
106+
}
92107
}
93108

109+
exec(`cat install/licenses/${replicatedChannel}.yaml`)
94110

95111
exec(`git config --global user.name "${username}"`);
96112

97-
var annotation = `-a channel=${replicatedChannel} -a preview=true -a skipTests=true -a deps=external`;
113+
annotation = `${annotation} -a channel=${replicatedChannel} -a preview=true -a skipTests=true -a deps=external`;
98114

99115
werft.phase("self-hosted-preview", `Create self-hosted preview in ${cluster}`);
100116

101-
annotation = `${annotation} -a cluster=${cluster} -a updateGitHubStatus=gitpod-io/gitpod`
117+
annotation = `${annotation} -a cluster=${cluster} -a updateGitHubStatus=gitpod-io/gitpod -a subdomain=${subdomain}`
102118

103119
const testFile: string = ".werft/self-hosted-installer-tests.yaml";
104120

@@ -115,6 +131,44 @@ export async function triggerSelfHostedPreview(werft: Werft, config: JobConfig,
115131
if (!config.mainBuild) {
116132
werft.fail("self-hosted-preview", err);
117133
}
134+
deleteReplicatedLicense(werft, customerID)
118135
exec("exit 0");
119136
}
120137
}
138+
139+
export async function deleteReplicatedLicense(werft: Werft, customerID: string) {
140+
if(customerID == "") {
141+
console.log("No customerID found, skipping replicated license cleanup")
142+
return
143+
}
144+
145+
console.log("trying to cleanup replicated license")
146+
werft.phase("delete-replicated-license", "Deletes the replicated license created")
147+
const http = require('https');
148+
149+
const options = {
150+
method: 'POST',
151+
hostname: 'api.replicated.com',
152+
port: null,
153+
path: `/vendor/v3/customer/${customerID}/archive`,
154+
headers: {
155+
Authorization: process.env.REPLICATED_API_TOKEN
156+
}
157+
};
158+
159+
const req = http.request(options, function (res) {
160+
const chunks = [];
161+
162+
res.on('data', function (chunk) {
163+
chunks.push(chunk);
164+
});
165+
166+
res.on('end', function () {
167+
const body = Buffer.concat(chunks);
168+
console.log(body.toString());
169+
});
170+
});
171+
172+
req.end();
173+
werft.done("delete-replicated-license")
174+
}

.werft/self-hosted-installer-tests.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ pod:
135135
secretKeyRef:
136136
name: slack-webhook-urls
137137
key: self_hosted_jobs
138+
- name: REPLICATED_API_TOKEN
139+
valueFrom:
140+
secretKeyRef:
141+
name: replicated
142+
key: token
138143
command:
139144
- bash
140145
- -c

0 commit comments

Comments
 (0)