@@ -229,11 +229,6 @@ func (r *CheUserNamespaceReconciler) Reconcile(ctx context.Context, req ctrl.Req
229229 return ctrl.Result {}, err
230230 }
231231
232- if err = r .reconcileProxySettings (ctx , req .Name , checluster , deployContext ); err != nil {
233- logrus .Errorf ("Failed to reconcile proxy settings into namespace '%s': %v" , req .Name , err )
234- return ctrl.Result {}, err
235- }
236-
237232 // Deprecated [CRW-6792].
238233 // All certificates are mounted into /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
239234 // and automatically added to the system trust store.
@@ -243,13 +238,8 @@ func (r *CheUserNamespaceReconciler) Reconcile(ctx context.Context, req ctrl.Req
243238 return ctrl.Result {}, err
244239 }
245240
246- if err = r .reconcileIdleSettings (ctx , req .Name , checluster , deployContext ); err != nil {
247- logrus .Errorf ("Failed to reconcile idle settings into namespace '%s': %v" , req .Name , err )
248- return ctrl.Result {}, err
249- }
250-
251- if err = r .reconcileEditorSettings (deployContext , req .Name , checluster ); err != nil {
252- logrus .Errorf ("Failed to reconcile editor settings into namespace '%s': %v" , req .Name , err )
241+ if err = r .reconcileUserSettings (deployContext , req .Name , checluster ); err != nil {
242+ logrus .Errorf ("Failed to reconcile user settings into namespace '%s': %v" , req .Name , err )
253243 return ctrl.Result {}, err
254244 }
255245
@@ -333,152 +323,77 @@ func (r *CheUserNamespaceReconciler) reconcileTrustedCerts(ctx context.Context,
333323 return err
334324}
335325
336- func (r * CheUserNamespaceReconciler ) reconcileProxySettings (ctx context.Context , targetNs string , checluster * chev2.CheCluster , deployContext * chetypes.DeployContext ) error {
337- if err := deleteLegacyObject ("proxy-settings" , & corev1.ConfigMap {}, targetNs , checluster , deployContext ); err != nil {
338- return err
339- }
340- proxyConfig , err := che .GetProxyConfiguration (deployContext )
341- if err != nil {
342- return err
343- }
344-
345- if proxyConfig == nil {
346- return nil
347- }
348-
349- proxySettings := map [string ]string {}
350- if proxyConfig .HttpProxy != "" {
351- proxySettings ["HTTP_PROXY" ] = proxyConfig .HttpProxy
352- proxySettings ["http_proxy" ] = proxyConfig .HttpProxy
353- }
354- if proxyConfig .HttpsProxy != "" {
355- proxySettings ["HTTPS_PROXY" ] = proxyConfig .HttpsProxy
356- proxySettings ["https_proxy" ] = proxyConfig .HttpsProxy
357- }
358- if proxyConfig .NoProxy != "" {
359- proxySettings ["NO_PROXY" ] = proxyConfig .NoProxy
360- proxySettings ["no_proxy" ] = proxyConfig .NoProxy
326+ func (r * CheUserNamespaceReconciler ) reconcileUserSettings (
327+ deployContext * chetypes.DeployContext ,
328+ targetNs string ,
329+ checluster * chev2.CheCluster ,
330+ ) error {
331+ cm2Delete := []string {
332+ prefixedName ("editor-settings" ),
333+ prefixedName ("idle-settings" ),
334+ prefixedName ("proxy-settings" ),
335+ checluster .Name + "-" + checluster .Namespace + "-proxy-settings" , // legacy name
361336 }
362337
363- key := client. ObjectKey { Name : prefixedName ( "proxy-settings" ), Namespace : targetNs }
364- cfg := & corev1. ConfigMap {}
365- exists := true
366- if err := r . client . Get ( ctx , key , cfg ); err != nil {
367- if errors . IsNotFound ( err ) {
368- exists = false
369- } else {
338+ // delete previously created CMs
339+ for _ , name := range cm2Delete {
340+ if _ , err := deploy . Delete (
341+ deployContext ,
342+ client. ObjectKey { Name : name , Namespace : targetNs },
343+ & corev1. ConfigMap {},
344+ ); err != nil {
370345 return err
371346 }
372347 }
373348
374- if len (proxySettings ) == 0 {
375- if exists {
376- if err := r .client .Delete (ctx , cfg ); err != nil {
377- return err
378- }
379- }
380- return nil
381- }
349+ name := prefixedName ("user-settings" )
382350
383- requiredLabels := defaults .AddStandardLabelsForComponent (checluster , userSettingsComponentLabelValue , map [string ]string {
384- dwconstants .DevWorkspaceMountLabel : "true" ,
385- dwconstants .DevWorkspaceWatchConfigMapLabel : "true" ,
386- })
387- requiredAnnos := map [string ]string {
351+ annotations := map [string ]string {
388352 dwconstants .DevWorkspaceMountAsAnnotation : "env" ,
389353 }
354+ labels := defaults .AddStandardLabelsForComponent (checluster ,
355+ userSettingsComponentLabelValue ,
356+ map [string ]string {
357+ dwconstants .DevWorkspaceMountLabel : "true" ,
358+ dwconstants .DevWorkspaceWatchConfigMapLabel : "true" ,
359+ })
390360
391- cfg = & corev1.ConfigMap {
392- TypeMeta : metav1.TypeMeta {
393- Kind : "ConfigMap" ,
394- APIVersion : "v1" ,
395- },
396- ObjectMeta : metav1.ObjectMeta {
397- Name : prefixedName ("proxy-settings" ),
398- Namespace : targetNs ,
399- Labels : requiredLabels ,
400- Annotations : requiredAnnos ,
401- },
402- Data : proxySettings ,
403- }
404-
405- _ , err = deploy .Sync (deployContext , cfg , deploy .ConfigMapDiffOpts )
406- return err
407- }
408-
409- func (r * CheUserNamespaceReconciler ) reconcileIdleSettings (ctx context.Context , targetNs string , checluster * chev2.CheCluster , deployContext * chetypes.DeployContext ) error {
410-
411- if checluster .Spec .DevEnvironments .SecondsOfInactivityBeforeIdling == nil && checluster .Spec .DevEnvironments .SecondsOfRunBeforeIdling == nil {
412- return nil
413- }
414- configMapName := prefixedName ("idle-settings" )
415- cfg := & corev1.ConfigMap {}
361+ data := map [string ]string {}
416362
417- requiredLabels := defaults .AddStandardLabelsForComponent (checluster , userSettingsComponentLabelValue , map [string ]string {
418- dwconstants .DevWorkspaceMountLabel : "true" ,
419- dwconstants .DevWorkspaceWatchConfigMapLabel : "true" ,
420- })
421- requiredAnnos := map [string ]string {
422- dwconstants .DevWorkspaceMountAsAnnotation : "env" ,
363+ // editor download urls
364+ if len (deployContext .CheCluster .Spec .DevEnvironments .EditorsDownloadUrls ) > 0 {
365+ for _ , editorDownloadUrl := range deployContext .CheCluster .Spec .DevEnvironments .EditorsDownloadUrls {
366+ editor := strings .ToUpper (editorDownloadUrl .Editor )
367+ editor = strings .ReplaceAll (editor , "-" , "_" )
368+ editor = strings .ReplaceAll (editor , "/" , "_" )
369+ data [fmt .Sprintf ("EDITOR_DOWNLOAD_URL_%s" , editor )] = editorDownloadUrl .Url
370+ }
423371 }
424372
425- data := map [string ]string {}
426-
373+ // idling configuration
427374 if checluster .Spec .DevEnvironments .SecondsOfInactivityBeforeIdling != nil {
428375 data ["SECONDS_OF_DW_INACTIVITY_BEFORE_IDLING" ] = strconv .FormatInt (int64 (* checluster .Spec .DevEnvironments .SecondsOfInactivityBeforeIdling ), 10 )
429376 }
430-
431377 if checluster .Spec .DevEnvironments .SecondsOfRunBeforeIdling != nil {
432378 data ["SECONDS_OF_DW_RUN_BEFORE_IDLING" ] = strconv .FormatInt (int64 (* checluster .Spec .DevEnvironments .SecondsOfRunBeforeIdling ), 10 )
433379 }
434380
435- cfg = & corev1.ConfigMap {
436- TypeMeta : metav1.TypeMeta {
437- Kind : "ConfigMap" ,
438- APIVersion : "v1" ,
439- },
440- ObjectMeta : metav1.ObjectMeta {
441- Name : configMapName ,
442- Namespace : targetNs ,
443- Labels : requiredLabels ,
444- Annotations : requiredAnnos ,
445- },
446- Data : data ,
447- }
448- _ , err := deploy .Sync (deployContext , cfg , deploy .ConfigMapDiffOpts )
449- return err
450- }
451-
452- func (r * CheUserNamespaceReconciler ) reconcileEditorSettings (
453- deployContext * chetypes.DeployContext ,
454- targetNs string ,
455- checluster * chev2.CheCluster ,
456- ) error {
457- name := prefixedName ("editor-settings" )
458-
459- annotations := map [string ]string {
460- dwconstants .DevWorkspaceMountAsAnnotation : "env" ,
461- }
462- labels := defaults .AddStandardLabelsForComponent (checluster , userSettingsComponentLabelValue , map [string ]string {
463- dwconstants .DevWorkspaceMountLabel : "true" ,
464- dwconstants .DevWorkspaceWatchConfigMapLabel : "true" ,
465- })
466-
467- delConfigMap := func () error {
468- _ , err := deploy .Delete (deployContext , client.ObjectKey {Name : name , Namespace : targetNs }, & corev1.ConfigMap {})
381+ // proxy settings
382+ if proxyConfig , err := che .GetProxyConfiguration (deployContext ); err != nil {
469383 return err
470- }
471-
472- data := map [string ]string {}
473- if len (deployContext .CheCluster .Spec .DevEnvironments .EditorsDownloadUrls ) > 0 {
474- for _ , editorDownloadUrl := range deployContext .CheCluster .Spec .DevEnvironments .EditorsDownloadUrls {
475- editor := strings .ToUpper (editorDownloadUrl .Editor )
476- editor = strings .ReplaceAll (editor , "-" , "_" )
477- editor = strings .ReplaceAll (editor , "/" , "_" )
478- data [fmt .Sprintf ("EDITOR_DOWNLOAD_URL_%s" , editor )] = editorDownloadUrl .Url
384+ } else if proxyConfig != nil {
385+ if proxyConfig .HttpProxy != "" {
386+ data ["HTTP_PROXY" ] = proxyConfig .HttpProxy
387+ data ["http_proxy" ] = proxyConfig .HttpProxy
388+ }
389+ if proxyConfig .HttpsProxy != "" {
390+ data ["HTTPS_PROXY" ] = proxyConfig .HttpsProxy
391+ data ["https_proxy" ] = proxyConfig .HttpsProxy
392+ }
393+ if proxyConfig .NoProxy != "" {
394+ data ["NO_PROXY" ] = proxyConfig .NoProxy
395+ data ["no_proxy" ] = proxyConfig .NoProxy
479396 }
480- } else {
481- return delConfigMap ()
482397 }
483398
484399 cm := & corev1.ConfigMap {
0 commit comments