Skip to content
This repository was archived by the owner on Jul 13, 2026. It is now read-only.

Commit ba50b7e

Browse files
committed
Add PVC for persistent PostgreSQL storage
Introduce a "database" field on the OpenStackLightspeed CR spec that allows configuring a PersistentVolumeClaim for the PostgreSQL data directory. When omitted, the existing emptyDir behavior is preserved. A few details about the implementation: * Reuse existing PVC if one already exists with matching size * Block reconciliation with a clear error if existing PVC size does not match the requested size * If no database.class is specified uses the cluster default * Default PVC size is "1Gi" The PVC is created without an owner reference so that data survives CR deletion and is reused on re-creation. Signed-off-by: Lucas Alvares Gomes <lucasagomes@gmail.com>
1 parent a8abf60 commit ba50b7e

21 files changed

Lines changed: 382 additions & 26 deletions

api/v1beta1/openstacklightspeed_types.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,20 @@ const (
4242
MaxTokensForResponseDefault = 2048
4343
)
4444

45+
// DatabaseSpec defines configuration for persistent PostgreSQL storage.
46+
type DatabaseSpec struct {
47+
// +kubebuilder:validation:Optional
48+
// +kubebuilder:default="1Gi"
49+
// +kubebuilder:validation:Pattern=`^([+-]?[0-9.]+)([eEinumkKMGTP]*[-+]?[0-9]*)$`
50+
// Size of the PersistentVolumeClaim for PostgreSQL data.
51+
Size string `json:"size,omitempty"`
52+
53+
// +kubebuilder:validation:Optional
54+
// StorageClass name for the PersistentVolumeClaim. If omitted, the cluster's
55+
// default StorageClass is used.
56+
Class string `json:"class,omitempty"`
57+
}
58+
4559
// OpenStackLightspeedSpec defines the desired state of OpenStackLightspeed
4660
type OpenStackLightspeedSpec struct {
4761
OpenStackLightspeedCore `json:",inline"`
@@ -59,6 +73,12 @@ type OpenStackLightspeedSpec struct {
5973
// Allows forcing a specific OCP version instead of auto-detection.
6074
// Format should be like "4.15", "4.16", etc.
6175
OCPRAGVersionOverride string `json:"ocpVersionOverride,omitempty"`
76+
77+
// +kubebuilder:validation:Optional
78+
// Database configures persistent storage for PostgreSQL data.
79+
// When omitted, an emptyDir volume is used (data is lost on pod reschedule).
80+
// When set, a PersistentVolumeClaim is created and mounted.
81+
Database *DatabaseSpec `json:"database,omitempty"`
6282
}
6383

6484
// OpenStackLightspeedCore defines the desired state of OpenStackLightspeed
@@ -148,6 +168,7 @@ type OpenStackLightspeedStatus struct {
148168
// +operator-sdk:csv:customresourcedefinitions:resources={{ServiceAccount,v1,lightspeed-app-server}}
149169
// +operator-sdk:csv:customresourcedefinitions:resources={{NetworkPolicy,v1,lightspeed-app-server}}
150170
// +operator-sdk:csv:customresourcedefinitions:resources={{NetworkPolicy,v1,lightspeed-postgres-server}}
171+
// +operator-sdk:csv:customresourcedefinitions:resources={{PersistentVolumeClaim,v1,openstack-lightspeed-data}}
151172
// +operator-sdk:csv:customresourcedefinitions:resources={{ClusterRole,v1,lightspeed-app-server-sar-role}}
152173
// +operator-sdk:csv:customresourcedefinitions:resources={{ClusterRoleBinding,v1,lightspeed-app-server-sar-role-binding}}
153174
// +operator-sdk:csv:customresourcedefinitions:resources={{Subscription,v1alpha1}}

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 21 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bundle/manifests/lightspeed.openstack.org_openstacklightspeeds.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,24 @@ spec:
4949
spec:
5050
description: OpenStackLightspeedSpec defines the desired state of OpenStackLightspeed
5151
properties:
52+
database:
53+
description: |-
54+
Database configures persistent storage for PostgreSQL data.
55+
When omitted, an emptyDir volume is used (data is lost on pod reschedule).
56+
When set, a PersistentVolumeClaim is created and mounted.
57+
properties:
58+
class:
59+
description: |-
60+
StorageClass name for the PersistentVolumeClaim. If omitted, the cluster's
61+
default StorageClass is used.
62+
type: string
63+
size:
64+
default: 1Gi
65+
description: Size of the PersistentVolumeClaim for PostgreSQL
66+
data.
67+
pattern: ^([+-]?[0-9.]+)([eEinumkKMGTP]*[-+]?[0-9]*)$
68+
type: string
69+
type: object
5270
enableOCPRAG:
5371
default: false
5472
description: Enables automatic OCP documentation based on cluster

bundle/manifests/openstack-lightspeed-operator.clusterserviceversion.yaml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ metadata:
2525
]
2626
capabilities: Basic Install
2727
categories: AI/Machine Learning
28-
createdAt: "2026-05-17T15:20:36Z"
28+
createdAt: "2026-05-25T08:30:49Z"
2929
description: AI-powered virtual assistant for Red Hat OpenStack Services on OpenShift
3030
features.operators.openshift.io/cnf: "false"
3131
features.operators.openshift.io/cni: "false"
@@ -113,6 +113,9 @@ spec:
113113
- kind: Secret
114114
name: metrics-reader-token
115115
version: v1
116+
- kind: PersistentVolumeClaim
117+
name: openstack-lightspeed-data
118+
version: v1
116119
specDescriptors:
117120
- description: |-
118121
Secret name containing API token for the LLMEndpoint. The secret must contain
@@ -340,11 +343,10 @@ spec:
340343
- apiGroups:
341344
- ""
342345
resources:
343-
- secrets
346+
- persistentvolumeclaims
347+
- services
344348
verbs:
345349
- create
346-
- delete
347-
- deletecollection
348350
- get
349351
- list
350352
- patch
@@ -353,23 +355,25 @@ spec:
353355
- apiGroups:
354356
- ""
355357
resources:
356-
- serviceaccounts
358+
- secrets
357359
verbs:
358360
- create
361+
- delete
362+
- deletecollection
359363
- get
360364
- list
361365
- patch
366+
- update
362367
- watch
363368
- apiGroups:
364369
- ""
365370
resources:
366-
- services
371+
- serviceaccounts
367372
verbs:
368373
- create
369374
- get
370375
- list
371376
- patch
372-
- update
373377
- watch
374378
- apiGroups:
375379
- apps

config/crd/bases/lightspeed.openstack.org_openstacklightspeeds.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,24 @@ spec:
4949
spec:
5050
description: OpenStackLightspeedSpec defines the desired state of OpenStackLightspeed
5151
properties:
52+
database:
53+
description: |-
54+
Database configures persistent storage for PostgreSQL data.
55+
When omitted, an emptyDir volume is used (data is lost on pod reschedule).
56+
When set, a PersistentVolumeClaim is created and mounted.
57+
properties:
58+
class:
59+
description: |-
60+
StorageClass name for the PersistentVolumeClaim. If omitted, the cluster's
61+
default StorageClass is used.
62+
type: string
63+
size:
64+
default: 1Gi
65+
description: Size of the PersistentVolumeClaim for PostgreSQL
66+
data.
67+
pattern: ^([+-]?[0-9.]+)([eEinumkKMGTP]*[-+]?[0-9]*)$
68+
type: string
69+
type: object
5270
enableOCPRAG:
5371
default: false
5472
description: Enables automatic OCP documentation based on cluster

config/manifests/bases/openstack-lightspeed-operator.clusterserviceversion.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ spec:
9090
- kind: Secret
9191
name: metrics-reader-token
9292
version: v1
93+
- kind: PersistentVolumeClaim
94+
name: openstack-lightspeed-data
95+
version: v1
9396
specDescriptors:
9497
- description: |-
9598
Secret name containing API token for the LLMEndpoint. The secret must contain

config/rbac/role.yaml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,10 @@ rules:
9090
- apiGroups:
9191
- ""
9292
resources:
93-
- secrets
93+
- persistentvolumeclaims
94+
- services
9495
verbs:
9596
- create
96-
- delete
97-
- deletecollection
9897
- get
9998
- list
10099
- patch
@@ -103,23 +102,25 @@ rules:
103102
- apiGroups:
104103
- ""
105104
resources:
106-
- serviceaccounts
105+
- secrets
107106
verbs:
108107
- create
108+
- delete
109+
- deletecollection
109110
- get
110111
- list
111112
- patch
113+
- update
112114
- watch
113115
- apiGroups:
114116
- ""
115117
resources:
116-
- services
118+
- serviceaccounts
117119
verbs:
118120
- create
119121
- get
120122
- list
121123
- patch
122-
- update
123124
- watch
124125
- apiGroups:
125126
- apps

config/samples/api_v1beta1_openstacklightspeed.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ spec:
1111
llmCredentials: openstack-lightspeed-apitoken
1212
modelName: llama3.1:8b
1313
tlsCACertBundle: openstack-lightspeed-certs
14+
# Uncomment to enable persistent PostgreSQL storage:
15+
# database:
16+
# size: "5Gi"
17+
# class: "my-storage-class"

internal/controller/constants.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ const (
7272
PostgresConfigVolumeMountPath = "/usr/share/pgsql/postgresql.conf.sample"
7373
PostgresDataVolume = "postgres-data"
7474
PostgresDataVolumeMountPath = "/var/lib/pgsql"
75+
PostgresDataPVCName = "openstack-lightspeed-data"
76+
PostgresDataPVCDefaultSize = "1Gi"
7577
PostgresVarRunVolumeName = "lightspeed-postgres-var-run"
7678
PostgresVarRunVolumeMountPath = "/var/run/postgresql"
7779
TmpVolumeName = "tmp-writable-volume"

internal/controller/errors.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,7 @@ var (
4747
ErrCreatePostgresConfigMap = errors.New("failed to create Postgres configmap")
4848
ErrGetPostgresConfigMap = errors.New("failed to get Postgres configmap")
4949
ErrCreatePostgresNetworkPolicy = errors.New("failed to create Postgres network policy")
50+
ErrCreatePostgresPVC = errors.New("failed to create Postgres PVC")
51+
ErrGetPostgresPVC = errors.New("failed to get Postgres PVC")
52+
ErrPostgresPVCSizeMismatch = errors.New("existing Postgres PVC size does not match requested size")
5053
)

0 commit comments

Comments
 (0)