@@ -3,7 +3,12 @@ import * as Tracing from "./observability/tracing";
3
3
import { HarvesterPreviewEnvironment , PreviewEnvironment } from "./util/preview" ;
4
4
import { SpanStatusCode } from "@opentelemetry/api" ;
5
5
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" ;
7
12
import * as fs from "fs" ;
8
13
9
14
// Will be set once tracing has been initialized
@@ -18,6 +23,7 @@ const DRY_RUN = annotations["dry-run"] in annotations || false;
18
23
19
24
const SLICES = {
20
25
VALIDATE_CONFIGURATION : "Validating configuration" ,
26
+ CONFIGURE_K8S : "Configuring k8s access." ,
21
27
CONFIGURE_ACCESS : "Configuring access to relevant resources" ,
22
28
INSTALL_HARVESTER_KUBECONFIG : "Install Harvester kubeconfig" ,
23
29
DELETING_PREVIEW : `Deleting preview environment: ${ previewName } ` ,
@@ -55,7 +61,6 @@ async function deletePreviewEnvironment() {
55
61
56
62
werft . phase ( "Configure access" ) ;
57
63
try {
58
- const GCLOUD_SERVICE_ACCOUNT_PATH = "/mnt/secrets/gcp-sa/service-account.json" ;
59
64
exec ( `gcloud auth activate-service-account --key-file "${ GCLOUD_SERVICE_ACCOUNT_PATH } "` , {
60
65
slice : SLICES . CONFIGURE_ACCESS ,
61
66
} ) ;
@@ -78,6 +83,8 @@ async function deletePreviewEnvironment() {
78
83
werft . fail ( SLICES . INSTALL_HARVESTER_KUBECONFIG , err ) ;
79
84
}
80
85
86
+ configureGlobalKubernetesContext ( )
87
+
81
88
const preview = new HarvesterPreviewEnvironment ( werft , previewName ) ;
82
89
if ( DRY_RUN ) {
83
90
werft . log ( SLICES . DELETING_PREVIEW , `Would have deleted preview ${ preview . name } ` ) ;
@@ -86,6 +93,14 @@ async function deletePreviewEnvironment() {
86
93
}
87
94
}
88
95
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
+
89
104
async function removePreviewEnvironment ( previewEnvironment : PreviewEnvironment ) {
90
105
werft . log ( SLICES . DELETING_PREVIEW , `Starting deletion of all resources related to ${ previewEnvironment . name } ` ) ;
91
106
try {
0 commit comments