MCPcopy Create free account
hub / github.com/devfile/devworkspace-operator / ResolveConfigForWorkspace

Function ResolveConfigForWorkspace

pkg/config/sync.go:64–89  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
64func 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
91func GetConfigForTesting(customConfig *controller.OperatorConfiguration) *controller.OperatorConfiguration {
92 configMutex.Lock()

Callers 2

TestMergeExternalConfigFunction · 0.85

Calls 5

GetGlobalConfigFunction · 0.85
getMergedConfigFunction · 0.85
ExistsMethod · 0.80
GetIntoMethod · 0.80
GetMethod · 0.65

Tested by 2

TestMergeExternalConfigFunction · 0.68