Skip to content

Commit 92465e8

Browse files
vulkoingimroboquat
authored andcommitted
Fix preview delete job
1 parent 292a5d6 commit 92465e8

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

.werft/platform-delete-preview-environment.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ import * as Tracing from "./observability/tracing";
33
import { HarvesterPreviewEnvironment, PreviewEnvironment } from "./util/preview";
44
import { SpanStatusCode } from "@opentelemetry/api";
55
import { exec } from "./util/shell";
6-
import { CORE_DEV_KUBECONFIG_PATH, HARVESTER_KUBECONFIG_PATH } from "./jobs/build/const";
6+
import {
7+
CORE_DEV_KUBECONFIG_PATH,
8+
GCLOUD_SERVICE_ACCOUNT_PATH,
9+
GLOBAL_KUBECONFIG_PATH,
10+
HARVESTER_KUBECONFIG_PATH
11+
} from "./jobs/build/const";
712
import * as fs from "fs";
813

914
// Will be set once tracing has been initialized
@@ -18,6 +23,7 @@ const DRY_RUN = annotations["dry-run"] in annotations || false;
1823

1924
const SLICES = {
2025
VALIDATE_CONFIGURATION: "Validating configuration",
26+
CONFIGURE_K8S: "Configuring k8s access.",
2127
CONFIGURE_ACCESS: "Configuring access to relevant resources",
2228
INSTALL_HARVESTER_KUBECONFIG: "Install Harvester kubeconfig",
2329
DELETING_PREVIEW: `Deleting preview environment: ${previewName}`,
@@ -55,7 +61,6 @@ async function deletePreviewEnvironment() {
5561

5662
werft.phase("Configure access");
5763
try {
58-
const GCLOUD_SERVICE_ACCOUNT_PATH = "/mnt/secrets/gcp-sa/service-account.json";
5964
exec(`gcloud auth activate-service-account --key-file "${GCLOUD_SERVICE_ACCOUNT_PATH}"`, {
6065
slice: SLICES.CONFIGURE_ACCESS,
6166
});
@@ -78,6 +83,8 @@ async function deletePreviewEnvironment() {
7883
werft.fail(SLICES.INSTALL_HARVESTER_KUBECONFIG, err);
7984
}
8085

86+
configureGlobalKubernetesContext()
87+
8188
const preview = new HarvesterPreviewEnvironment(werft, previewName);
8289
if (DRY_RUN) {
8390
werft.log(SLICES.DELETING_PREVIEW, `Would have deleted preview ${preview.name}`);
@@ -86,6 +93,14 @@ async function deletePreviewEnvironment() {
8693
}
8794
}
8895

96+
function configureGlobalKubernetesContext() {
97+
const rc = exec(`previewctl get-credentials --gcp-service-account=${GCLOUD_SERVICE_ACCOUNT_PATH} --kube-save-path=${GLOBAL_KUBECONFIG_PATH}`, { slice: SLICES.CONFIGURE_K8S }).code;
98+
99+
if (rc != 0) {
100+
throw new Error("Failed to configure global kubernetes context.");
101+
}
102+
}
103+
89104
async function removePreviewEnvironment(previewEnvironment: PreviewEnvironment) {
90105
werft.log(SLICES.DELETING_PREVIEW, `Starting deletion of all resources related to ${previewEnvironment.name}`);
91106
try {

0 commit comments

Comments
 (0)