11import { werft } from './util/shell' ;
22import { wipePreviewEnvironment , listAllPreviewNamespaces } from './util/kubectl' ;
3+ import fs from 'fs' ;
34
45
5- async function wipeDevstaging ( ) {
6+ async function wipeDevstaging ( pathToKubeConfig : string ) {
67 const namespace_raw = process . env . NAMESPACE ;
78 const namespaces : string [ ] = [ ] ;
89 if ( namespace_raw === "<no value>" || ! namespace_raw ) {
910 werft . log ( 'wipe' , "Going to wipe all namespaces" ) ;
10- listAllPreviewNamespaces ( "" )
11+ listAllPreviewNamespaces ( pathToKubeConfig )
1112 . map ( ns => namespaces . push ( ns ) ) ;
1213 } else {
1314 werft . log ( 'wipe' , `Going to wipe namespace ${ namespace_raw } ` ) ;
1415 namespaces . push ( namespace_raw ) ;
1516 }
1617
1718 for ( const namespace of namespaces ) {
18- await wipePreviewEnvironment ( "" , "gitpod" , namespace , { slice : 'wipe' } ) ;
19+ await wipePreviewEnvironment ( pathToKubeConfig , "gitpod" , namespace , { slice : 'wipe' } ) ;
1920 }
2021 werft . done ( 'wipe' ) ;
2122}
2223
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