1
1
import { werft } from './util/shell' ;
2
2
import { wipePreviewEnvironment , listAllPreviewNamespaces } from './util/kubectl' ;
3
+ import fs from 'fs' ;
3
4
4
5
5
- async function wipeDevstaging ( ) {
6
+ async function wipeDevstaging ( pathToKubeConfig : string ) {
6
7
const namespace_raw = process . env . NAMESPACE ;
7
8
const namespaces : string [ ] = [ ] ;
8
9
if ( namespace_raw === "<no value>" || ! namespace_raw ) {
9
10
werft . log ( 'wipe' , "Going to wipe all namespaces" ) ;
10
- listAllPreviewNamespaces ( "" )
11
+ listAllPreviewNamespaces ( pathToKubeConfig )
11
12
. map ( ns => namespaces . push ( ns ) ) ;
12
13
} else {
13
14
werft . log ( 'wipe' , `Going to wipe namespace ${ namespace_raw } ` ) ;
14
15
namespaces . push ( namespace_raw ) ;
15
16
}
16
17
17
18
for ( const namespace of namespaces ) {
18
- await wipePreviewEnvironment ( "" , "gitpod" , namespace , { slice : 'wipe' } ) ;
19
+ await wipePreviewEnvironment ( pathToKubeConfig , "gitpod" , namespace , { slice : 'wipe' } ) ;
19
20
}
20
21
werft . done ( 'wipe' ) ;
21
22
}
22
23
23
- wipeDevstaging ( )
24
+ wipeDevstaging ( "" )
25
+ // if we have "/workspace/k3s-external.yaml" present that means a k3s ws cluster
26
+ // exists, therefore, delete corresponding preview deployment from that cluster too
27
+ // NOTE: Even for a non k3s ws deployment we will attempt to clean the preview.
28
+ // This saves us from writing complex logic of querying meta cluster for registered workspaces
29
+ // Since we use the same namespace to deploy in both dev and k3s cluster, this is safe
30
+ if ( fs . existsSync ( "/workspace/k3s-external.yaml" ) ) {
31
+ wipeDevstaging ( "/workspace/k3s-external.yaml" )
32
+ }
0 commit comments