ResolveConfigForWorkspace returns the resulting config from merging the global DevWorkspaceOperatorConfig with the DevWorkspaceOperatorConfig specified by the optional workspace attribute `controller.devfile.io/devworkspace-config`. If the `controller.devfile.io/devworkspace-config` is not set, the
(workspace *dw.DevWorkspace, client crclient.Client)
| 62 | // If the `controller.devfile.io/devworkspace-config` attribute is incorrectly set, or the specified DevWorkspaceOperatorConfig |
| 63 | // does not exist on the cluster, an error is returned. |
| 64 | func ResolveConfigForWorkspace(workspace *dw.DevWorkspace, client crclient.Client) (*controller.OperatorConfiguration, error) { |
| 65 | if !workspace.Spec.Template.Attributes.Exists(constants.ExternalDevWorkspaceConfiguration) { |
| 66 | return GetGlobalConfig(), nil |
| 67 | } |
| 68 | |
| 69 | namespacedName := types.NamespacedName{} |
| 70 | err := workspace.Spec.Template.Attributes.GetInto(constants.ExternalDevWorkspaceConfiguration, &namespacedName) |
| 71 | if err != nil { |
| 72 | return nil, fmt.Errorf("failed to read attribute %s in DevWorkspace attributes: %w", constants.ExternalDevWorkspaceConfiguration, err) |
| 73 | } |
| 74 | |
| 75 | if namespacedName.Name == "" { |
| 76 | return nil, fmt.Errorf("'name' must be set for attribute %s in DevWorkspace attributes", constants.ExternalDevWorkspaceConfiguration) |
| 77 | } |
| 78 | |
| 79 | if namespacedName.Namespace == "" { |
| 80 | return nil, fmt.Errorf("'namespace' must be set for attribute %s in DevWorkspace attributes", constants.ExternalDevWorkspaceConfiguration) |
| 81 | } |
| 82 | |
| 83 | externalDWOC := &controller.DevWorkspaceOperatorConfig{} |
| 84 | err = client.Get(context.TODO(), namespacedName, externalDWOC) |
| 85 | if err != nil { |
| 86 | return nil, fmt.Errorf("could not fetch external DWOC with name %s in namespace %s: %w", namespacedName.Name, namespacedName.Namespace, err) |
| 87 | } |
| 88 | return getMergedConfig(externalDWOC.Config, internalConfig), nil |
| 89 | } |
| 90 | |
| 91 | func GetConfigForTesting(customConfig *controller.OperatorConfiguration) *controller.OperatorConfiguration { |
| 92 | configMutex.Lock() |