Skip to content

Fix preview delete job #14172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions .werft/platform-delete-preview-environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import * as Tracing from "./observability/tracing";
import { HarvesterPreviewEnvironment, PreviewEnvironment } from "./util/preview";
import { SpanStatusCode } from "@opentelemetry/api";
import { exec } from "./util/shell";
import { CORE_DEV_KUBECONFIG_PATH, HARVESTER_KUBECONFIG_PATH } from "./jobs/build/const";
import {
CORE_DEV_KUBECONFIG_PATH,
GCLOUD_SERVICE_ACCOUNT_PATH,
GLOBAL_KUBECONFIG_PATH,
HARVESTER_KUBECONFIG_PATH
} from "./jobs/build/const";
import * as fs from "fs";

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

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

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

configureGlobalKubernetesContext()

const preview = new HarvesterPreviewEnvironment(werft, previewName);
if (DRY_RUN) {
werft.log(SLICES.DELETING_PREVIEW, `Would have deleted preview ${preview.name}`);
Expand All @@ -86,6 +93,14 @@ async function deletePreviewEnvironment() {
}
}

function configureGlobalKubernetesContext() {
const rc = exec(`previewctl get-credentials --gcp-service-account=${GCLOUD_SERVICE_ACCOUNT_PATH} --kube-save-path=${GLOBAL_KUBECONFIG_PATH}`, { slice: SLICES.CONFIGURE_K8S }).code;

if (rc != 0) {
throw new Error("Failed to configure global kubernetes context.");
}
}

async function removePreviewEnvironment(previewEnvironment: PreviewEnvironment) {
werft.log(SLICES.DELETING_PREVIEW, `Starting deletion of all resources related to ${previewEnvironment.name}`);
try {
Expand Down