@@ -23,10 +23,12 @@ const inCluster = __ENV.IN_CLUSTER === 'true';
23
23
const apiServer = inCluster ? `https://kubernetes.default.svc` : __ENV . KUBE_API ;
24
24
const token = inCluster ? open ( '/var/run/secrets/kubernetes.io/serviceaccount/token' ) : __ENV . KUBE_TOKEN ;
25
25
const useSeparateNamespaces = __ENV . SEPARATE_NAMESPACES === "true" ;
26
+ const deleteDevWorkspaceAfterReady = __ENV . DELETE_DEVWORKSPACE_AFTER_READY === "true" ;
26
27
const operatorNamespace = __ENV . DWO_NAMESPACE || 'openshift-operators' ;
27
28
const externalDevWorkspaceLink = __ENV . DEVWORKSPACE_LINK || '' ;
28
29
const shouldCreateAutomountResources = ( __ENV . CREATE_AUTOMOUNT_RESOURCES || 'false' ) === 'true' ;
29
30
const maxVUs = Number ( __ENV . MAX_VUS || 50 ) ;
31
+ const maxDevWorkspaces = Number ( __ENV . MAX_DEVWORKSPACES || - 1 ) ;
30
32
const devWorkspaceReadyTimeout = Number ( __ENV . DEV_WORKSPACE_READY_TIMEOUT_IN_SECONDS || 600 ) ;
31
33
const autoMountConfigMapName = 'dwo-load-test-automount-configmap' ;
32
34
const autoMountSecretName = 'dwo-load-test-automount-secret' ;
@@ -87,6 +89,12 @@ export function setup() {
87
89
}
88
90
89
91
export default function ( ) {
92
+ if ( maxDevWorkspaces > 0 ) {
93
+ const totalDevWorkspaces = getDevWorkspacesFromApiServer ( ) . length ;
94
+ if ( totalDevWorkspaces > maxDevWorkspaces ) {
95
+ return ;
96
+ }
97
+ }
90
98
const vuId = __VU ;
91
99
const iteration = __ITER ;
92
100
const crName = `dw-test-${ vuId } -${ iteration } ` ;
@@ -104,7 +112,9 @@ export default function () {
104
112
const devWorkspaceCreated = createNewDevWorkspace ( namespace , vuId , iteration ) ;
105
113
if ( devWorkspaceCreated ) {
106
114
waitUntilDevWorkspaceIsReady ( vuId , crName , namespace ) ;
107
- deleteDevWorkspace ( crName , namespace ) ;
115
+ if ( deleteDevWorkspaceAfterReady ) {
116
+ deleteDevWorkspace ( crName , namespace ) ;
117
+ }
108
118
}
109
119
} catch ( error ) {
110
120
console . error ( `Load test for ${ vuId } -${ iteration } failed:` , error . message ) ;
@@ -434,6 +444,23 @@ function downloadAndParseExternalWorkspace(externalDevWorkspaceLink) {
434
444
return manifest ;
435
445
}
436
446
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
+
437
464
function generateDevWorkspaceToCreate ( vuId , iteration , namespace ) {
438
465
const name = `dw-test-${ vuId } -${ iteration } ` ;
439
466
let devWorkspace = { } ;
0 commit comments