-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for per-namespace configuration and add setting for workspace PVC request size #487
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// | ||
// Copyright (c) 2019-2021 Red Hat, Inc. | ||
// This program and the accompanying materials are made | ||
// available under the terms of the Eclipse Public License 2.0 | ||
// which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 | ||
// | ||
// Contributors: | ||
// Red Hat, Inc. - initial API and implementation | ||
// | ||
|
||
package config | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/labels" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
"github.com/devfile/devworkspace-operator/controllers/workspace/provision" | ||
"github.com/devfile/devworkspace-operator/pkg/constants" | ||
) | ||
|
||
const ( | ||
commonPVCSizeKey = "commonPVCSize" | ||
) | ||
|
||
type NamespacedConfig struct { | ||
CommonPVCSize string | ||
} | ||
|
||
// ReadNamespacedConfig reads the per-namespace DevWorkspace configmap and returns it as a struct. If there are | ||
// no valid configmaps in the specified namespace, returns (nil, nil). If there are multiple configmaps with the | ||
// per-namespace configmap label, returns an error. | ||
func ReadNamespacedConfig(namespace string, api provision.ClusterAPI) (*NamespacedConfig, error) { | ||
cmList := &corev1.ConfigMapList{} | ||
labelSelector, err := labels.Parse(fmt.Sprintf("%s=true", constants.NamespacedConfigLabelKey)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
selector := &client.ListOptions{ | ||
Namespace: namespace, | ||
LabelSelector: labelSelector, | ||
} | ||
err = api.Client.List(api.Ctx, cmList, selector) | ||
if err != nil { | ||
return nil, err | ||
} | ||
cms := cmList.Items | ||
if len(cms) == 0 { | ||
return nil, nil | ||
} else if len(cms) > 1 { | ||
var cmNames []string | ||
for _, cm := range cms { | ||
cmNames = append(cmNames, cm.Name) | ||
} | ||
return nil, fmt.Errorf("multiple per-namespace configs found: %s", strings.Join(cmNames, ", ")) | ||
} | ||
|
||
cm := cms[0] | ||
if cm.Data == nil { | ||
return nil, nil | ||
} | ||
|
||
return &NamespacedConfig{ | ||
CommonPVCSize: cm.Data[commonPVCSizeKey], | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, during testing I found more config we may want to configure, but I'm not sure.
Like pvc name. For CRW it's claim-che-workspace, not sure if CRW expects Che Workspace and DevWorkspaces uses different PVCs.
Also, see che.infra.kubernetes.pvc.storage_class_name.
it's out of the current PR scope for sure, but WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My idea was that the config struct could be extended to include additional information as needed (storage class makes sense).
For common PVC name, I think it's a limited use case that would be complex to support -- e.g. what happens if it is updated after
claim-che-workspace
has been created? It seems like it would be an open door for leaking storage after workspaces are deleted, etc.