Skip to content

Commit 66f5db6

Browse files
Add configurable container resource requests and limits via CR spec
Container resource requirements (CPU/memory requests and limits) were previously hardcoded inline across controller files, making it impossible for users to tune resources for their workloads. This is particularly important for llama-stack, where memory usage can grow unpredictably with bring-your-own-key (BYOK) deployments. 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. cinder-operator). When the field is omitted, sensible defaults matching the previous hardcoded values are used. When set, the user's values replace the defaults entirely. All 7 containers are configurable: llamaStack, lightspeedService, dataverseExporter, vectorDatabaseInit, postgres, okp, and consolePlugin. Implementation details: - Add ContainerResourcesSpec struct with optional per-container overrides to the API types - Centralize default resource values as functions (not package-level vars) to prevent shared-map mutation bugs via Go's shallow copy semantics - Add resolveResources helper that returns the user override when present, falling back to the default - Update all 4 controller files (lcore, postgres, okp, console) to resolve resources from the CR spec - Add unit tests for resolveResources and kuttl e2e tests for custom resource application across all deployments - Update sample CR with commented-out resource override examples - Regenerate CRD manifests and deepcopy methods
1 parent e770335 commit 66f5db6

22 files changed

Lines changed: 1504 additions & 104 deletions

api/v1beta1/openstacklightspeed_types.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package v1beta1
1919
import (
2020
"github.com/openstack-k8s-operators/lib-common/modules/common/condition"
2121
"github.com/openstack-k8s-operators/lib-common/modules/common/util"
22+
corev1 "k8s.io/api/core/v1"
2223
"k8s.io/apimachinery/pkg/api/resource"
2324
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2425
"k8s.io/apimachinery/pkg/runtime"
@@ -91,6 +92,52 @@ type DatabaseSpec struct {
9192
Class string `json:"class,omitempty"`
9293
}
9394

95+
// ContainerResourcesSpec defines optional resource requirements overrides
96+
// for each container managed by the operator. When a field is nil, the
97+
// operator uses built-in defaults. When set, the provided value replaces
98+
// the default entirely (both requests and limits).
99+
type ContainerResourcesSpec struct {
100+
// +kubebuilder:validation:Optional
101+
// LlamaStack overrides compute resources for the llama-stack (OGX) container
102+
// in the lightspeed-stack deployment.
103+
// Default requests: CPU 500m, Memory 2Gi. Default limits: CPU 2, Memory 8Gi.
104+
LlamaStack *corev1.ResourceRequirements `json:"llamaStack,omitempty"`
105+
106+
// +kubebuilder:validation:Optional
107+
// LightspeedService overrides compute resources for the lightspeed-service-api
108+
// container in the lightspeed-stack deployment.
109+
// Default requests: CPU 250m, Memory 512Mi. Default limits: CPU 1, Memory 2Gi.
110+
LightspeedService *corev1.ResourceRequirements `json:"lightspeedService,omitempty"`
111+
112+
// +kubebuilder:validation:Optional
113+
// DataverseExporter overrides compute resources for the dataverse exporter
114+
// sidecar container (only created when data collection is enabled).
115+
// Default requests: CPU 50m, Memory 64Mi. Default limits: Memory 200Mi.
116+
DataverseExporter *corev1.ResourceRequirements `json:"dataverseExporter,omitempty"`
117+
118+
// +kubebuilder:validation:Optional
119+
// VectorDatabaseInit overrides compute resources for both vector-database
120+
// init containers (vector-database-collect and vector-database-config-build).
121+
// Default requests: CPU 100m, Memory 256Mi. Default limits: CPU 500m, Memory 1Gi.
122+
VectorDatabaseInit *corev1.ResourceRequirements `json:"vectorDatabaseInit,omitempty"`
123+
124+
// +kubebuilder:validation:Optional
125+
// Postgres overrides compute resources for the PostgreSQL container.
126+
// Default requests: CPU 30m, Memory 300Mi. Default limits: CPU 500m, Memory 2Gi.
127+
Postgres *corev1.ResourceRequirements `json:"postgres,omitempty"`
128+
129+
// +kubebuilder:validation:Optional
130+
// OKP overrides compute resources for the Offline Knowledge Portal container.
131+
// Default requests: CPU 500m, Memory 2Gi. Default limits: CPU 2, Memory 4Gi.
132+
OKP *corev1.ResourceRequirements `json:"okp,omitempty"`
133+
134+
// +kubebuilder:validation:Optional
135+
// ConsolePlugin overrides compute resources for the lightspeed-console-plugin
136+
// container and its init container.
137+
// Default requests: CPU 50m, Memory 64Mi. Default limits: CPU 200m, Memory 256Mi.
138+
ConsolePlugin *corev1.ResourceRequirements `json:"consolePlugin,omitempty"`
139+
}
140+
94141
// OpenStackLightspeedSpec defines the desired state of OpenStackLightspeed
95142
type OpenStackLightspeedSpec struct {
96143
OpenStackLightspeedCore `json:",inline"`
@@ -105,6 +152,13 @@ type OpenStackLightspeedSpec struct {
105152
// OKP configures the Offline Knowledge Portal (OKP) RAG source.
106153
OKP *OKPSpec `json:"okp,omitempty"`
107154

155+
// +kubebuilder:validation:Optional
156+
// Resources overrides the default compute resource requirements for
157+
// individual containers managed by the operator. When omitted, sensible
158+
// defaults are used. When a container's field is set, it replaces the
159+
// default entirely (both requests and limits).
160+
Resources *ContainerResourcesSpec `json:"resources,omitempty"`
161+
108162
// +kubebuilder:validation:Optional
109163
// +kubebuilder:pruning:PreserveUnknownFields
110164
// Dev contains developer/experimental configuration.

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 56 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)