Skip to content

Commit 70d7d33

Browse files
committed
Add container resource caps enforcement for workspace containers
Implements ContainerResourceCaps configuration to enforce maximum resource limits and requests for workspace containers. When configured, container resource requirements that exceed the caps will be limited to the maximum values. This feature does not apply to initContainers or projectClone containers. Changes include: - New ContainerResourceCaps field in DevWorkspaceOperatorConfig API - Updated CRDs with the new field definition - Controller integration to pass resource caps to container handlers - Resource capping logic in container, flatten, merge, and projects packages - Tests for resource cap enforcement Assisted-by: Claude. Signed-off-by: Anatolii Bazko <[email protected]>
1 parent 1a8a0e8 commit 70d7d33

18 files changed

+636
-15
lines changed

apis/controller/v1alpha1/devworkspaceoperatorconfig_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,11 @@ type WorkspaceConfig struct {
183183
// the value "0" should be used. By default, the memory limit is 128Mi and the memory request is 64Mi.
184184
// No CPU limit or request is added by default.
185185
DefaultContainerResources *corev1.ResourceRequirements `json:"defaultContainerResources,omitempty"`
186+
// ContainerResourceCaps defines the maximum resource requirements enforced for all
187+
// workspace containers. If a container specifies higher limits or requests, they
188+
// will be capped at these maximum values. This is not applied to initContainers or
189+
// the projectClone container.
190+
ContainerResourceCaps *corev1.ResourceRequirements `json:"containerResourceCaps,omitempty"`
186191
// PodAnnotations defines the metadata.annotations for DevWorkspace pods created by the DevWorkspace Operator.
187192
PodAnnotations map[string]string `json:"podAnnotations,omitempty"`
188193
// RuntimeClassName defines the spec.runtimeClassName for DevWorkspace pods created by the DevWorkspace Operator.

apis/controller/v1alpha1/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

controllers/workspace/devworkspace_controller.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ func (r *DevWorkspaceReconciler) Reconcile(ctx context.Context, req ctrl.Request
264264
K8sClient: r.Client,
265265
HttpClient: httpClient,
266266
DefaultResourceRequirements: workspace.Config.Workspace.DefaultContainerResources,
267+
ResourceCaps: workspace.Config.Workspace.ContainerResourceCaps,
267268
}
268269

269270
if wsDefaults.NeedsDefaultTemplate(workspace) {
@@ -335,6 +336,7 @@ func (r *DevWorkspaceReconciler) Reconcile(ctx context.Context, req ctrl.Request
335336
workspace.Config.Workspace.ContainerSecurityContext,
336337
workspace.Config.Workspace.ImagePullPolicy,
337338
workspace.Config.Workspace.DefaultContainerResources,
339+
workspace.Config.Workspace.ContainerResourceCaps,
338340
workspace.Config.Workspace.PostStartTimeout,
339341
postStartDebugTrapSleepDuration,
340342
)
@@ -356,6 +358,7 @@ func (r *DevWorkspaceReconciler) Reconcile(ctx context.Context, req ctrl.Request
356358
Image: workspace.Config.Workspace.ProjectCloneConfig.Image,
357359
Env: env.GetEnvironmentVariablesForProjectClone(workspace),
358360
Resources: workspace.Config.Workspace.ProjectCloneConfig.Resources,
361+
Caps: workspace.Config.Workspace.ContainerResourceCaps,
359362
}
360363
if workspace.Config.Workspace.ProjectCloneConfig.ImagePullPolicy != "" {
361364
projectCloneOptions.PullPolicy = config.Workspace.ProjectCloneConfig.ImagePullPolicy

deploy/bundle/manifests/controller.devfile.io_devworkspaceoperatorconfigs.yaml

Lines changed: 63 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deploy/deployment/kubernetes/combined.yaml

Lines changed: 63 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deploy/deployment/kubernetes/objects/devworkspaceoperatorconfigs.controller.devfile.io.CustomResourceDefinition.yaml

Lines changed: 63 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deploy/deployment/openshift/combined.yaml

Lines changed: 63 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)