Skip to content

Add configurable container resource requests and limits via CR spec#27

Open
omkarjoshi0304 wants to merge 1 commit into
openstack-k8s-operators:mainfrom
omkarjoshi0304:feature/configurable-container-resources
Open

Add configurable container resource requests and limits via CR spec#27
omkarjoshi0304 wants to merge 1 commit into
openstack-k8s-operators:mainfrom
omkarjoshi0304:feature/configurable-container-resources

Conversation

@omkarjoshi0304

@omkarjoshi0304 omkarjoshi0304 commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

Summary

This adds a spec.resources field to the OpenStackLightspeed CR that accepts per-container corev1.ResourceRequirements overrides following the same pattern used by other openstack-k8s-operators (e.g. test-operator). Defaults are declared via kubebuilder:default markers on the API types, so the API server sets them automatically — no fallback logic needed in the controllers.

How it works

  • Add ContainerResourcesSpec struct with kubebuilder:default markers encoding the previous hardcoded values for each container
  • Controllers read instance.Spec.Resources directly — no nil checks or resolve helpers needed since the API server guarantees defaults
  • Update sample CR with commented-out resource override examples
  • Regenerate CRD manifests and deepcopy methods

Example CR

spec:
  resources:
    llamaStack:
      requests:
        cpu: "2"
        memory: "8Gi"
      limits:
        cpu: "8"
        memory: "32Gi"
    postgres:
      requests:
        cpu: "100m"
        memory: "512Mi"
      limits:
        cpu: "1"
        memory: "4Gi"

Test Proof

[cloud-user@ojoshi-rhoso-lightspeed ~]$ oc patch openstacklightspeed openstack-lightspeed -n openstack-lightspeed --type=merge -p '{"spec": {"resources": {"llamaStack": {"requests": {"cpu": "1", "memory": "4Gi"}, "limits": {"cpu": "4", "memory": "16Gi"}}, "lightspeedService": {"requests": {"cpu": "500m", "memory": "1Gi"}, "limits": {"cpu": "2", "memory": "4Gi"}}, "postgres": {"requests": {"cpu": "100m", "memory": "512Mi"}, "limits": {"cpu": "1", "memory": "4Gi"}}}}}'
openstacklightspeed.lightspeed.openstack.org/openstack-lightspeed patched
[cloud-user@ojoshi-rhoso-lightspeed ~]$ echo "=== llama-stack ==="
oc get deployment lightspeed-stack-deployment -n openstack-lightspeed \
  -o jsonpath='{.spec.template.spec.containers[?(@.name=="llama-stack")].resources}' | \
  python3 -m json.tool
=== llama-stack ===
{
    "limits": {
        "cpu": "4",
        "memory": "16Gi"
    },
    "requests": {
        "cpu": "1",
        "memory": "4Gi"
    }
}
[cloud-user@ojoshi-rhoso-lightspeed ~]$ echo "=== lightspeed-service-api ==="
oc get deployment lightspeed-stack-deployment -n openstack-lightspeed \
  -o jsonpath='{.spec.template.spec.containers[?(@.name=="lightspeed-service-api")].resources}' | \
  python3 -m json.tool
=== lightspeed-service-api ===
{
    "limits": {
        "cpu": "2",
        "memory": "4Gi"
    },
    "requests": {
        "cpu": "500m",
        "memory": "1Gi"
    }
}
[cloud-user@ojoshi-rhoso-lightspeed ~]$ echo "=== postgres ==="
oc get deployment lightspeed-postgres-server -n openstack-lightspeed \
  -o jsonpath='{.spec.template.spec.containers[0].resources}' | \
  python3 -m json.tool
=== postgres ===
{
    "limits": {
        "cpu": "1",
        "memory": "4Gi"
    },
    "requests": {
        "cpu": "100m",
        "memory": "512Mi"
    }
}
[cloud-user@ojoshi-rhoso-lightspeed ~]$ 

@openshift-ci
openshift-ci Bot requested review from Akrog and lpiwowar July 21, 2026 15:02
@openshift-ci

openshift-ci Bot commented Jul 21, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: omkarjoshi0304
Once this PR has been reviewed and has the lgtm label, please assign akrog for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@omkarjoshi0304
omkarjoshi0304 force-pushed the feature/configurable-container-resources branch from 689bf70 to afd7706 Compare July 21, 2026 15:08
@omkarjoshi0304
omkarjoshi0304 force-pushed the feature/configurable-container-resources branch from afd7706 to 66f5db6 Compare July 21, 2026 15:16
@omkarjoshi0304

Copy link
Copy Markdown
Collaborator Author

/retest

1 similar comment
@omkarjoshi0304

Copy link
Copy Markdown
Collaborator Author

/retest

@lpiwowar lpiwowar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just very quickly skimmed through it and there is one thing that crossed my mind we should try IMO but overall I like the PR 👍.

Comment thread api/v1beta1/openstacklightspeed_types.go Outdated
@omkarjoshi0304
omkarjoshi0304 force-pushed the feature/configurable-container-resources branch 3 times, most recently from 479d7e8 to 652455c Compare July 22, 2026 13:43
@omkarjoshi0304

Copy link
Copy Markdown
Collaborator Author

/retest

@omkarjoshi0304
omkarjoshi0304 force-pushed the feature/configurable-container-resources branch 2 times, most recently from 228d137 to b529180 Compare July 22, 2026 17:11
@omkarjoshi0304
omkarjoshi0304 force-pushed the feature/configurable-container-resources branch 3 times, most recently from 328b200 to df8997a Compare July 23, 2026 14:38
lightspeedStackLogLevel: ERROR
dataverseExporterLogLevel: ERROR
resources:
consolePlugin:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Why aren't we testing the resources setting also for other pods / containers (e.g., lightspeed)? Also, I think we could validate in the 03-assert-openstack-lightspeed-instance.yaml that the default resource requests and limits were set on the pods / containers.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh I'll add resource overrides for llamaStack and lightspeedService as well

Add a Resources field to OpenStackLightspeedSpec that lets users override
CPU/memory requests and limits for each container managed by the operator.
Defaults are applied by the API server via kubebuilder:default markers on
ContainerResourcesSpec fields; any user-supplied value replaces the default
entirely.

Extend the update-openstacklightspeed kuttl test to exercise resource
overrides for consolePlugin and postgres (separate reconciler paths) and
assert custom values propagate to deployment specs.
@omkarjoshi0304
omkarjoshi0304 force-pushed the feature/configurable-container-resources branch from df8997a to bd3a911 Compare July 24, 2026 12:00
@omkarjoshi0304

Copy link
Copy Markdown
Collaborator Author

/retest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants