Skip to content

Commit b529180

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. 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. All 7 containers are configurable: llamaStack, lightspeedService, dataverseExporter, vectorDatabaseInit, postgres, okp, and consolePlugin. Implementation details: - 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 - Add 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 b529180

22 files changed

Lines changed: 1323 additions & 125 deletions

api/v1beta1/openstacklightspeed_types.go

Lines changed: 55 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 resource requirements for each container
96+
// managed by the operator. Defaults are applied by the API server via
97+
// kubebuilder markers. Users may override any container's resources in
98+
// the CR; the provided value replaces the default entirely.
99+
type ContainerResourcesSpec struct {
100+
// +kubebuilder:validation:Optional
101+
// +kubebuilder:default:={requests: {cpu: "500m", memory: "2Gi"}, limits: {cpu: "2", memory: "8Gi"}}
102+
// LlamaStack sets compute resources for the llama-stack (OGX) container
103+
// in the lightspeed-stack deployment.
104+
LlamaStack corev1.ResourceRequirements `json:"llamaStack,omitempty"`
105+
106+
// +kubebuilder:validation:Optional
107+
// +kubebuilder:default:={requests: {cpu: "250m", memory: "512Mi"}, limits: {cpu: "1", memory: "2Gi"}}
108+
// LightspeedService sets compute resources for the lightspeed-service-api
109+
// container in the lightspeed-stack deployment.
110+
LightspeedService corev1.ResourceRequirements `json:"lightspeedService,omitempty"`
111+
112+
// +kubebuilder:validation:Optional
113+
// +kubebuilder:default:={requests: {cpu: "50m", memory: "64Mi"}, limits: {memory: "200Mi"}}
114+
// DataverseExporter sets compute resources for the dataverse exporter
115+
// sidecar container (only created when data collection is enabled).
116+
DataverseExporter corev1.ResourceRequirements `json:"dataverseExporter,omitempty"`
117+
118+
// +kubebuilder:validation:Optional
119+
// +kubebuilder:default:={requests: {cpu: "100m", memory: "256Mi"}, limits: {cpu: "500m", memory: "1Gi"}}
120+
// VectorDatabaseInit sets compute resources for both vector-database
121+
// init containers (vector-database-collect and vector-database-config-build).
122+
VectorDatabaseInit corev1.ResourceRequirements `json:"vectorDatabaseInit,omitempty"`
123+
124+
// +kubebuilder:validation:Optional
125+
// +kubebuilder:default:={requests: {cpu: "30m", memory: "300Mi"}, limits: {cpu: "500m", memory: "2Gi"}}
126+
// Postgres sets compute resources for the PostgreSQL container.
127+
Postgres corev1.ResourceRequirements `json:"postgres,omitempty"`
128+
129+
// +kubebuilder:validation:Optional
130+
// +kubebuilder:default:={requests: {cpu: "500m", memory: "2Gi"}, limits: {cpu: "2", memory: "4Gi"}}
131+
// OKP sets compute resources for the Offline Knowledge Portal container.
132+
OKP corev1.ResourceRequirements `json:"okp,omitempty"`
133+
134+
// +kubebuilder:validation:Optional
135+
// +kubebuilder:default:={requests: {cpu: "50m", memory: "64Mi"}, limits: {cpu: "200m", memory: "256Mi"}}
136+
// ConsolePlugin sets compute resources for the lightspeed-console-plugin
137+
// container and its init container.
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,14 @@ 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+
// +kubebuilder:default:={}
157+
// Resources configures compute resource requirements for individual
158+
// containers managed by the operator. Each field has sensible defaults
159+
// applied by the API server. Override any container's resources to
160+
// replace its defaults entirely.
161+
Resources ContainerResourcesSpec `json:"resources,omitempty"`
162+
108163
// +kubebuilder:validation:Optional
109164
// +kubebuilder:pruning:PreserveUnknownFields
110165
// Dev contains developer/experimental configuration.

api/v1beta1/zz_generated.deepcopy.go

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