@@ -108,19 +108,48 @@ export class DevWorkspaceConfigurationHelper {
108108 }
109109
110110 /**
111- * add missed attributes to fix issues CRW-8922, CRW-9187 .
111+ * add Dev Spaces attributes and match the SCC to the configured container capabilities .
112112 */
113113 addMissedDevWorkspaceConfigAttributes (
114114 devfileContextDevWorkspace : DevfileContext ,
115115 storageType : string | undefined = API_TEST_CONSTANTS . TS_API_TEST_STORAGE_TYPE
116116 ) : void {
117117 Logger . debug ( ) ;
118- devfileContextDevWorkspace . devWorkspace ?. spec ?. template &&
119- ( devfileContextDevWorkspace . devWorkspace . spec . template . attributes = YAML . parse ( `
120- controller.devfile.io/devworkspace-config:
121- name: devworkspace-config
122- namespace: openshift-devspaces
123- controller.devfile.io/scc: container-build
124- controller.devfile.io/storage-type: ${ storageType } ` ) ) ;
118+ const template : V1alpha2DevWorkspaceTemplate [ 'spec' ] = devfileContextDevWorkspace . devWorkspace ?. spec ?. template ;
119+ if ( ! template ) {
120+ return ;
121+ }
122+
123+ const devSpacesNamespace : string = 'openshift-devspaces' ;
124+ const devEnvironments : {
125+ disableContainerRunCapabilities ?: boolean ;
126+ disableContainerBuildCapabilities ?: boolean ;
127+ containerRunConfiguration ?: { openShiftSecurityContextConstraint ?: string } ;
128+ containerBuildConfiguration ?: { openShiftSecurityContextConstraint ?: string } ;
129+ } = JSON . parse (
130+ this . shellExecutor . executeArbitraryShellScript (
131+ `oc get checluster -n ${ devSpacesNamespace } -o jsonpath='{.items[0].spec.devEnvironments}'`
132+ )
133+ ) ;
134+
135+ template . attributes = {
136+ ...template . attributes ,
137+ 'controller.devfile.io/devworkspace-config' : {
138+ name : 'devworkspace-config' ,
139+ namespace : devSpacesNamespace
140+ } ,
141+ 'controller.devfile.io/storage-type' : storageType
142+ } ;
143+
144+ // container run takes precedence when both run and build capabilities are enabled.
145+ if ( devEnvironments . disableContainerRunCapabilities === false ) {
146+ template . attributes [ 'controller.devfile.io/scc' ] =
147+ devEnvironments . containerRunConfiguration ?. openShiftSecurityContextConstraint || 'container-run' ;
148+ } else if ( devEnvironments . disableContainerBuildCapabilities !== true ) {
149+ template . attributes [ 'controller.devfile.io/scc' ] =
150+ devEnvironments . containerBuildConfiguration ?. openShiftSecurityContextConstraint || 'container-build' ;
151+ } else {
152+ delete template . attributes [ 'controller.devfile.io/scc' ] ;
153+ }
125154 }
126155}
0 commit comments