@@ -23,10 +23,12 @@ const inCluster = __ENV.IN_CLUSTER === 'true';
2323const apiServer = inCluster ? `https://kubernetes.default.svc` : __ENV . KUBE_API ;
2424const token = inCluster ? open ( '/var/run/secrets/kubernetes.io/serviceaccount/token' ) : __ENV . KUBE_TOKEN ;
2525const useSeparateNamespaces = __ENV . SEPARATE_NAMESPACES === "true" ;
26+ const deleteDevWorkspaceAfterReady = __ENV . DELETE_DEVWORKSPACE_AFTER_READY === "true" ;
2627const operatorNamespace = __ENV . DWO_NAMESPACE || 'openshift-operators' ;
2728const externalDevWorkspaceLink = __ENV . DEVWORKSPACE_LINK || '' ;
2829const shouldCreateAutomountResources = ( __ENV . CREATE_AUTOMOUNT_RESOURCES || 'false' ) === 'true' ;
2930const maxVUs = Number ( __ENV . MAX_VUS || 50 ) ;
31+ const maxDevWorkspaces = Number ( __ENV . MAX_DEVWORKSPACES || - 1 ) ;
3032const devWorkspaceReadyTimeout = Number ( __ENV . DEV_WORKSPACE_READY_TIMEOUT_IN_SECONDS || 600 ) ;
3133const autoMountConfigMapName = 'dwo-load-test-automount-configmap' ;
3234const autoMountSecretName = 'dwo-load-test-automount-secret' ;
@@ -87,6 +89,12 @@ export function setup() {
8789}
8890
8991export default function ( ) {
92+ if ( maxDevWorkspaces > 0 ) {
93+ const totalDevWorkspaces = getDevWorkspacesFromApiServer ( ) . length ;
94+ if ( totalDevWorkspaces > maxDevWorkspaces ) {
95+ return ;
96+ }
97+ }
9098 const vuId = __VU ;
9199 const iteration = __ITER ;
92100 const crName = `dw-test-${ vuId } -${ iteration } ` ;
@@ -104,7 +112,9 @@ export default function () {
104112 const devWorkspaceCreated = createNewDevWorkspace ( namespace , vuId , iteration ) ;
105113 if ( devWorkspaceCreated ) {
106114 waitUntilDevWorkspaceIsReady ( vuId , crName , namespace ) ;
107- deleteDevWorkspace ( crName , namespace ) ;
115+ if ( deleteDevWorkspaceAfterReady ) {
116+ deleteDevWorkspace ( crName , namespace ) ;
117+ }
108118 }
109119 } catch ( error ) {
110120 console . error ( `Load test for ${ vuId } -${ iteration } failed:` , error . message ) ;
@@ -434,6 +444,23 @@ function downloadAndParseExternalWorkspace(externalDevWorkspaceLink) {
434444 return manifest ;
435445}
436446
447+ function getDevWorkspacesFromApiServer ( ) {
448+ const basePath = useSeparateNamespaces
449+ ? `${ apiServer } /apis/workspace.devfile.io/v1alpha2/devworkspaces`
450+ : `${ apiServer } /apis/workspace.devfile.io/v1alpha2/namespaces/${ loadTestNamespace } /devworkspaces` ;
451+
452+ const url = `${ basePath } ?labelSelector=${ labelKey } %3D${ labelType } ` ;
453+ const res = http . get ( url , { headers } ) ;
454+
455+ if ( res . status !== 200 ) {
456+ console . error ( `Failed to fetch DevWorkspaces: ${ res . status } ${ res . body } ` ) ;
457+ return [ ] ;
458+ }
459+
460+ const body = JSON . parse ( res . body ) ;
461+ return body . items . map ( ( dw ) => dw . metadata . name ) ;
462+ }
463+
437464function generateDevWorkspaceToCreate ( vuId , iteration , namespace ) {
438465 const name = `dw-test-${ vuId } -${ iteration } ` ;
439466 let devWorkspace = { } ;
0 commit comments