Skip to content

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

Open
omkarjoshi0304 wants to merge 2 commits 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 2 commits 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
@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
@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

@omkarjoshi0304
omkarjoshi0304 requested a review from umago July 27, 2026 08:51
Comment thread go.mod
Comment thread api/v1beta1/openstacklightspeed_types.go Outdated
Comment thread api/v1beta1/openstacklightspeed_types.go
@umago

umago commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

Change overall looks fine. I think the version bumps and the Init containers at least we should think a bit more before exposing it.

The version bumps looks unrelated to the change (and should at least be on it's own commit). And the Init containers seems like a leak from internal implementation to CR.

Addresses a security vulnerability in the x/text package. The
transitive dependency bumps (x/mod, x/net, x/sync, x/sys, x/term,
x/tools) are required by the new x/text version.
@omkarjoshi0304
omkarjoshi0304 force-pushed the feature/configurable-container-resources branch from bd3a911 to ae02a43 Compare July 27, 2026 11:50
@omkarjoshi0304

Copy link
Copy Markdown
Collaborator Author

/retest

Allow users to override CPU/memory requests and limits for user-facing
containers (llamaStack, lightspeedService, postgres, okp, consolePlugin)
through the OpenStackLightspeed CR spec. Internal containers
(dataverse exporter, vector-database init) keep hardcoded defaults
since they are implementation details not exposed to users.

Defaults are applied by the API server via kubebuilder markers.
@omkarjoshi0304
omkarjoshi0304 force-pushed the feature/configurable-container-resources branch from ae02a43 to 07d805f Compare July 27, 2026 12:47

@umago umago 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.

Thanks Omkar! It /lgtm

@openshift-ci

openshift-ci Bot commented Jul 28, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: omkarjoshi0304, umago

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

The pull request process is described 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

@umago

umago commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

/lgtm

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants