Skip to content
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 node selectors and pod tolerations via attribute #681

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions pkg/constants/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,22 @@ package constants

// Constants that are used in attributes on DevWorkspace elements (components, endpoints, etc.)
const (
// PodTolerationsAttribute defines tolerations that should be applied to the DevWorkspace's pod. Tolerations
// should be defined in the same format as in Kubernetes, e.g.
// - key: "example-key"
// operator: "Exists"
// effect: "NoSchedule"
PodTolerationsAttribute = "pod-tolerations"

// NodeSelectorAttribute defines the node selector that should be used for the DevWorkspace's pod. Should be
// defined as a key-value map.
NodeSelectorAttribute = "node-selector"

// PluginSourceAttribute is an attribute added to components, commands, and projects in a flattened
// DevWorkspace representation to signify where the respective component came from (i.e. which plugin
// or parent imported it)
PluginSourceAttribute = "controller.devfile.io/imported-by"

// EndpointURLAttribute is an attribute added to endpoints to denote the endpoint on the cluster that
// was created to route to this endpoint
EndpointURLAttribute = "controller.devfile.io/endpoint-url"
Expand Down
16 changes: 16 additions & 0 deletions pkg/provision/workspace/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,22 @@ func getSpecDeployment(
deployment.Spec.Template.Annotations = maputils.Append(deployment.Spec.Template.Annotations, constants.DevWorkspaceRestrictedAccessAnnotation, restrictedAccess)
}

if workspace.Spec.Template.Attributes.Exists(constants.PodTolerationsAttribute) {
var tolerations []corev1.Toleration
if err := workspace.Spec.Template.Attributes.GetInto(constants.PodTolerationsAttribute, &tolerations); err != nil {
return nil, fmt.Errorf("failed to parse %s attribute: %w", constants.PodTolerationsAttribute, err)
}
deployment.Spec.Template.Spec.Tolerations = tolerations
}

if workspace.Spec.Template.Attributes.Exists(constants.NodeSelectorAttribute) {
nodeSelector := map[string]string{}
if err := workspace.Spec.Template.Attributes.GetInto(constants.NodeSelectorAttribute, &nodeSelector); err != nil {
return nil, fmt.Errorf("failed to parse %s attribute: %w", constants.NodeSelectorAttribute, err)
}
deployment.Spec.Template.Spec.NodeSelector = nodeSelector
}

err = controllerutil.SetControllerReference(workspace, deployment, scheme)
if err != nil {
return nil, err
Expand Down