Skip to content

Commit 8faeaf1

Browse files
Merge pull request #111 from omkarjoshi0304/lcore
Add memory and CPU resource limits to containers
2 parents fcdd71a + 83bbcc4 commit 8faeaf1

6 files changed

Lines changed: 125 additions & 19 deletions

File tree

internal/controller/common.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,6 @@ func generatePostgresSelectorLabels() map[string]string {
9999
}
100100
}
101101

102-
// getResourcesOrDefault returns the provided resource requirements if non-nil,
103-
// otherwise returns the given default resource requirements.
104-
func getResourcesOrDefault(custom *corev1.ResourceRequirements, defaults corev1.ResourceRequirements) corev1.ResourceRequirements {
105-
if custom != nil {
106-
return *custom
107-
}
108-
return defaults
109-
}
110-
111102
// isDeploymentReady checks whether the provided deployment is ready by verifying
112103
// that the deployment's observed generation matches the current generation and
113104
// all replicas (updated, available, and total) match the desired count.

internal/controller/console_deployment.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
appsv1 "k8s.io/api/apps/v1"
2424
corev1 "k8s.io/api/core/v1"
2525
networkingv1 "k8s.io/api/networking/v1"
26+
"k8s.io/apimachinery/pkg/api/resource"
2627
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2728
"k8s.io/apimachinery/pkg/util/intstr"
2829
)
@@ -85,6 +86,16 @@ func buildConsoleDeploymentSpec(consoleImage string) appsv1.DeploymentSpec {
8586
"awk '" + consoleLocalesRewriteAwk + "' " +
8687
consoleLocalesPath + " > /locales-rewrite/" + consoleLocalesFilename,
8788
},
89+
Resources: corev1.ResourceRequirements{
90+
Requests: corev1.ResourceList{
91+
corev1.ResourceCPU: resource.MustParse("50m"),
92+
corev1.ResourceMemory: resource.MustParse("64Mi"),
93+
},
94+
Limits: corev1.ResourceList{
95+
corev1.ResourceCPU: resource.MustParse("200m"),
96+
corev1.ResourceMemory: resource.MustParse("256Mi"),
97+
},
98+
},
8899
VolumeMounts: []corev1.VolumeMount{
89100
{
90101
Name: "locales-rewrite",
@@ -108,6 +119,16 @@ func buildConsoleDeploymentSpec(consoleImage string) appsv1.DeploymentSpec {
108119
SecurityContext: &corev1.SecurityContext{
109120
AllowPrivilegeEscalation: toPtr(false),
110121
},
122+
Resources: corev1.ResourceRequirements{
123+
Requests: corev1.ResourceList{
124+
corev1.ResourceCPU: resource.MustParse("50m"),
125+
corev1.ResourceMemory: resource.MustParse("64Mi"),
126+
},
127+
Limits: corev1.ResourceList{
128+
corev1.ResourceCPU: resource.MustParse("200m"),
129+
corev1.ResourceMemory: resource.MustParse("256Mi"),
130+
},
131+
},
111132
VolumeMounts: []corev1.VolumeMount{
112133
{
113134
Name: "lightspeed-console-plugin-cert",

internal/controller/lcore_deployment.go

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,16 @@ func buildLCorePodTemplateSpec(h *common_helper.Helper, ctx context.Context, ins
8181
InitialDelaySeconds: 5,
8282
PeriodSeconds: 10,
8383
},
84-
Resources: getResourcesOrDefault(nil, corev1.ResourceRequirements{}),
84+
Resources: corev1.ResourceRequirements{
85+
Requests: corev1.ResourceList{
86+
corev1.ResourceCPU: resource.MustParse("500m"),
87+
corev1.ResourceMemory: resource.MustParse("2Gi"),
88+
},
89+
Limits: corev1.ResourceList{
90+
corev1.ResourceCPU: resource.MustParse("2"),
91+
corev1.ResourceMemory: resource.MustParse("8Gi"),
92+
},
93+
},
8594
ImagePullPolicy: corev1.PullIfNotPresent,
8695
}
8796

@@ -108,15 +117,24 @@ func buildLCorePodTemplateSpec(h *common_helper.Helper, ctx context.Context, ins
108117
}
109118

110119
lightspeedStackContainer := corev1.Container{
111-
Name: "lightspeed-service-api",
112-
Image: apiv1beta1.OpenStackLightspeedDefaultValues.LCoreImageURL,
113-
Args: []string{"-c", VectorDBVolumeLightspeedStackConfigPath},
114-
Ports: []corev1.ContainerPort{{Name: "https", ContainerPort: OpenStackLightspeedAppServerContainerPort}},
115-
VolumeMounts: lightspeedStackMounts,
116-
Env: lsEnvVars,
117-
LivenessProbe: buildLightspeedStackLivenessProbe(),
118-
ReadinessProbe: buildLightspeedStackReadinessProbe(),
119-
Resources: getResourcesOrDefault(nil, corev1.ResourceRequirements{}),
120+
Name: "lightspeed-service-api",
121+
Image: apiv1beta1.OpenStackLightspeedDefaultValues.LCoreImageURL,
122+
Args: []string{"-c", VectorDBVolumeLightspeedStackConfigPath},
123+
Ports: []corev1.ContainerPort{{Name: "https", ContainerPort: OpenStackLightspeedAppServerContainerPort}},
124+
VolumeMounts: lightspeedStackMounts,
125+
Env: lsEnvVars,
126+
LivenessProbe: buildLightspeedStackLivenessProbe(),
127+
ReadinessProbe: buildLightspeedStackReadinessProbe(),
128+
Resources: corev1.ResourceRequirements{
129+
Requests: corev1.ResourceList{
130+
corev1.ResourceCPU: resource.MustParse("250m"),
131+
corev1.ResourceMemory: resource.MustParse("512Mi"),
132+
},
133+
Limits: corev1.ResourceList{
134+
corev1.ResourceCPU: resource.MustParse("1"),
135+
corev1.ResourceMemory: resource.MustParse("2Gi"),
136+
},
137+
},
120138
ImagePullPolicy: corev1.PullIfNotPresent,
121139
}
122140
containers := []corev1.Container{llamaStackContainer, lightspeedStackContainer}

internal/controller/postgres_deployment.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ func buildPostgresPodTemplateSpec() corev1.PodTemplateSpec {
149149
corev1.ResourceMemory: resource.MustParse("300Mi"),
150150
},
151151
Limits: corev1.ResourceList{
152+
corev1.ResourceCPU: resource.MustParse("500m"),
152153
corev1.ResourceMemory: resource.MustParse("2Gi"),
153154
},
154155
},

test/kuttl/common/openstack-lightspeed-instance/assert-openstack-lightspeed-instance.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ kind: Deployment
4141
metadata:
4242
name: lightspeed-postgres-server
4343
namespace: openstack-lightspeed
44+
spec:
45+
template:
46+
spec:
47+
containers:
48+
- name: lightspeed-postgres-server
49+
resources:
50+
requests:
51+
cpu: 30m
52+
memory: 300Mi
53+
limits:
54+
cpu: 500m
55+
memory: 2Gi
4456
status:
4557
replicas: 1
4658
readyReplicas: 1
@@ -159,6 +171,13 @@ spec:
159171
- name: vector-database-config-build
160172
containers:
161173
- name: llama-stack
174+
resources:
175+
requests:
176+
cpu: 500m
177+
memory: 2Gi
178+
limits:
179+
cpu: "2"
180+
memory: 8Gi
162181
env:
163182
- name: OPENSTACK_LIGHTSPEED_PROVIDER_API_KEY
164183
valueFrom:
@@ -186,6 +205,13 @@ spec:
186205
- name: llama-cache
187206
mountPath: /tmp/llama-stack
188207
- name: lightspeed-service-api
208+
resources:
209+
requests:
210+
cpu: 250m
211+
memory: 512Mi
212+
limits:
213+
cpu: "1"
214+
memory: 2Gi
189215
env:
190216
- name: LIGHTSPEED_STACK_LOG_LEVEL
191217
value: WARNING
@@ -309,9 +335,25 @@ spec:
309335
readOnlyRootFilesystem: true
310336
capabilities:
311337
drop: ["ALL"]
338+
resources:
339+
requests:
340+
cpu: 50m
341+
memory: 64Mi
342+
limits:
343+
cpu: 200m
344+
memory: 256Mi
312345
volumeMounts:
313346
- name: locales-rewrite
314347
mountPath: /locales-rewrite
348+
containers:
349+
- name: lightspeed-console-plugin
350+
resources:
351+
requests:
352+
cpu: 50m
353+
memory: 64Mi
354+
limits:
355+
cpu: 200m
356+
memory: 256Mi
315357
---
316358
apiVersion: v1
317359
kind: Service

test/kuttl/tests/update-openstacklightspeed/08-assert-openstacklightspeed-update.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ kind: Deployment
2323
metadata:
2424
name: lightspeed-postgres-server
2525
namespace: openstack-lightspeed
26+
spec:
27+
template:
28+
spec:
29+
containers:
30+
- name: lightspeed-postgres-server
31+
resources:
32+
requests:
33+
cpu: 30m
34+
memory: 300Mi
35+
limits:
36+
cpu: 500m
37+
memory: 2Gi
2638
status:
2739
replicas: 1
2840
readyReplicas: 1
@@ -74,6 +86,13 @@ spec:
7486
- name: vector-database-config-build
7587
containers:
7688
- name: llama-stack
89+
resources:
90+
requests:
91+
cpu: 500m
92+
memory: 2Gi
93+
limits:
94+
cpu: "2"
95+
memory: 8Gi
7796
env:
7897
- name: OPENSTACK_LIGHTSPEED_PROVIDER_API_KEY
7998
valueFrom:
@@ -103,6 +122,13 @@ spec:
103122
- name: llama-cache
104123
mountPath: /tmp/llama-stack
105124
- name: lightspeed-service-api
125+
resources:
126+
requests:
127+
cpu: 250m
128+
memory: 512Mi
129+
limits:
130+
cpu: "1"
131+
memory: 2Gi
106132
env:
107133
- name: LIGHTSPEED_STACK_LOG_LEVEL
108134
value: ERROR
@@ -199,6 +225,13 @@ spec:
199225
spec:
200226
initContainers:
201227
- name: rewrite-locales
228+
resources:
229+
requests:
230+
cpu: 50m
231+
memory: 64Mi
232+
limits:
233+
cpu: 200m
234+
memory: 256Mi
202235
volumeMounts:
203236
- name: locales-rewrite
204237
mountPath: /locales-rewrite

0 commit comments

Comments
 (0)