convertConfigMapToConfigCRD converts a earlier devworkspace configuration configmap (if present) into a DevWorkspaceOperatorConfig. Values matching the current default config settings are ignored. If the configmap is not present, or if the configmap is present but all values are default, returns nil
(client crclient.Client)
| 82 | // If the configmap is not present, or if the configmap is present but all values are default, returns |
| 83 | // nil. Returns an error if we fail to load the controller config from configmap. |
| 84 | func convertConfigMapToConfigCRD(client crclient.Client) (*dw.DevWorkspaceOperatorConfig, error) { |
| 85 | found, err := configmap.LoadControllerConfig(client) |
| 86 | if err != nil { |
| 87 | return nil, err |
| 88 | } |
| 89 | if !found { |
| 90 | return nil, nil |
| 91 | } |
| 92 | |
| 93 | migratedRoutingConfig := &dw.RoutingConfig{} |
| 94 | setRoutingConfig := false |
| 95 | routingSuffix := configmap.ControllerCfg.GetClusterRoutingSuffix() |
| 96 | if routingSuffix != nil && *routingSuffix != defaultConfig.Routing.ClusterHostSuffix { |
| 97 | migratedRoutingConfig.ClusterHostSuffix = *routingSuffix |
| 98 | setRoutingConfig = true |
| 99 | } |
| 100 | defaultRoutingClass := configmap.ControllerCfg.GetDefaultRoutingClass() |
| 101 | if defaultRoutingClass != nil && *defaultRoutingClass != defaultConfig.Routing.DefaultRoutingClass { |
| 102 | migratedRoutingConfig.DefaultRoutingClass = *defaultRoutingClass |
| 103 | setRoutingConfig = true |
| 104 | } |
| 105 | |
| 106 | migratedWorkspaceConfig := &dw.WorkspaceConfig{} |
| 107 | setWorkspaceConfig := false |
| 108 | storageClassName := configmap.ControllerCfg.GetPVCStorageClassName() |
| 109 | if storageClassName != defaultConfig.Workspace.StorageClassName { |
| 110 | migratedWorkspaceConfig.StorageClassName = storageClassName |
| 111 | setWorkspaceConfig = true |
| 112 | } |
| 113 | sidecarPullPolicy := configmap.ControllerCfg.GetSidecarPullPolicy() |
| 114 | if sidecarPullPolicy != nil && *sidecarPullPolicy != defaultConfig.Workspace.ImagePullPolicy { |
| 115 | migratedWorkspaceConfig.ImagePullPolicy = *sidecarPullPolicy |
| 116 | setWorkspaceConfig = true |
| 117 | } |
| 118 | idleTimeout := configmap.ControllerCfg.GetWorkspaceIdleTimeout() |
| 119 | if idleTimeout != nil && *idleTimeout != defaultConfig.Workspace.IdleTimeout { |
| 120 | migratedWorkspaceConfig.IdleTimeout = *idleTimeout |
| 121 | setWorkspaceConfig = true |
| 122 | } |
| 123 | pvcName := configmap.ControllerCfg.GetWorkspacePVCName() |
| 124 | if pvcName != nil && *pvcName != defaultConfig.Workspace.PVCName { |
| 125 | migratedWorkspaceConfig.PVCName = *pvcName |
| 126 | setWorkspaceConfig = true |
| 127 | } |
| 128 | |
| 129 | var experimentalFeatures *bool |
| 130 | experimentalFeaturesStr := configmap.ControllerCfg.GetExperimentalFeaturesEnabled() |
| 131 | if experimentalFeaturesStr != nil && *experimentalFeaturesStr == "true" { |
| 132 | experimentalFeatures = pointer.Bool(true) |
| 133 | } |
| 134 | |
| 135 | if !setRoutingConfig && !setWorkspaceConfig && experimentalFeatures == nil { |
| 136 | return nil, nil |
| 137 | } |
| 138 | |
| 139 | migratedConfig := &dw.DevWorkspaceOperatorConfig{ |
| 140 | ObjectMeta: metav1.ObjectMeta{ |
| 141 | Name: OperatorConfigName, |