Skip to content

Commit 549bab6

Browse files
authored
refactor entitystore CRD (#298)
Signed-off-by: Varun Ramachandra Sekar <[email protected]> Co-authored-by: Varun Ramachandra Sekar <[email protected]>
1 parent 850b403 commit 549bab6

File tree

6 files changed

+254
-144
lines changed

6 files changed

+254
-144
lines changed

api/apps/v1alpha1/nemo_entitystore_types.go

Lines changed: 61 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"fmt"
2121
"maps"
2222
"os"
23+
"strconv"
2324

2425
rendertypes "github.com/NVIDIA/k8s-nim-operator/internal/render/types"
2526
utils "github.com/NVIDIA/k8s-nim-operator/internal/utils"
@@ -51,18 +52,6 @@ const (
5152
NemoEntitystoreStatusFailed = "Failed"
5253
)
5354

54-
// Default values for NEMO entitystore.
55-
const (
56-
defaultDBSecretPasswordKey = "password"
57-
defaultDatabasePort = "5432"
58-
)
59-
60-
// Various error messages for NEMO entitystore.
61-
var (
62-
nilErrorFmtStr = "`%s` cannot be nil"
63-
emptyErrorFmtStr = "`%s` cannot be empty"
64-
)
65-
6655
// NemoEntitystoreSpec defines the desired state of NemoEntitystore
6756
type NemoEntitystoreSpec struct {
6857
Image Image `json:"image,omitempty"`
@@ -89,19 +78,59 @@ type NemoEntitystoreSpec struct {
8978
UserID *int64 `json:"userID,omitempty"`
9079
GroupID *int64 `json:"groupID,omitempty"`
9180
RuntimeClass string `json:"runtimeClass,omitempty"`
92-
// Database stores the database config for the entity-store service
93-
EntityStoreParams *EntityStoreParams `json:"entityStoreParams,omitempty"`
94-
}
95-
96-
type EntityStoreParams struct {
97-
AppVersion string `json:"appVersion,omitempty"`
98-
DatabaseHost string `json:"databaseHost,omitempty"`
99-
DatabasePort string `json:"databasePort,omitempty"`
100-
DatabaseUser string `json:"databaseUser,omitempty"`
101-
DatabaseName string `json:"databaseName,omitempty"`
102-
DBSecret string `json:"dbSecret,omitempty"`
103-
DBSecretPasswordKey string `json:"dbSecretPasswordKey,omitempty"`
104-
EnvConfigMap string `json:"envConfigMap,omitempty"`
81+
// DatabaseConfig stores the database configuration for NEMO entitystore.
82+
// Required, must not be nil.
83+
//
84+
// +kubebuilder:validation:Required
85+
DatabaseConfig *DatabaseConfig `json:"databaseConfig,omitempty"`
86+
}
87+
88+
type DatabaseConfig struct {
89+
// Host is the hostname of the database.
90+
// Required, must not be empty.
91+
//
92+
// +kubebuilder:validation:Required
93+
// +kubebuilder:validation:MinLength=1
94+
Host string `json:"host,omitempty"`
95+
// Port is the port where the database is reachable at.
96+
// If specified, this must be a valid port number, 0 < databasePort < 65536.
97+
// Defaults to 5432.
98+
//
99+
// +kubebuilder:validation:Minimum=1
100+
// +kubebuilder:validation:Maximum=65535
101+
// +kubebuilder:default:=5432
102+
Port int32 `json:"port,omitempty"`
103+
// DatabaseName is the database name for NEMO EntityStore.
104+
// Required, must not be empty.
105+
//
106+
// +kubebuilder:validation:Required
107+
// +kubebuilder:validation:MinLength=1
108+
DatabaseName string `json:"databaseName,omitempty"`
109+
// DatabaseCredentials stores the configuration to retrieve the database credentials.
110+
// Required, must not be nil.
111+
//
112+
// +kubebuilder:validation:Required
113+
Credentials *DatabaseCredentials `json:"credentials,omitempty"`
114+
}
115+
116+
type DatabaseCredentials struct {
117+
// User is the non-root username for NEMO EntityStore in the database.
118+
// Required, must not be empty.
119+
//
120+
// +kubebuilder:validation:Required
121+
// +kubebuilder:validation:MinLength=1
122+
User string `json:"user,omitempty"`
123+
// SecretName is the name of the secret which has the database credentials for the NEMO entitystore user.
124+
// Required, must not be empty.
125+
//
126+
// +kubebuilder:validation:Required
127+
// +kubebuilder:validation:MinLength=1
128+
SecretName string `json:"secretName,omitempty"`
129+
// PasswordKey is the name of the key in the `CredentialsSecret` secret for the database credentials.
130+
// Defaults to "password".
131+
//
132+
// +kubebuilder:default:="password"
133+
PasswordKey string `json:"passwordKey,omitempty"`
105134
}
106135

107136
// NemoEntitystoreStatus defines the observed state of NemoEntitystore
@@ -135,52 +164,6 @@ type NemoEntitystoreList struct {
135164
Items []NemoEntitystore `json:"items"`
136165
}
137166

138-
func (n *EntityStoreParams) Normalize() {
139-
if n.DatabasePort == "" {
140-
n.DatabasePort = defaultDatabasePort
141-
}
142-
143-
if n.DBSecretPasswordKey == "" {
144-
n.DBSecretPasswordKey = defaultDBSecretPasswordKey
145-
}
146-
}
147-
148-
func (n *EntityStoreParams) Validate() error {
149-
if n.DatabaseHost == "" {
150-
return fmt.Errorf(emptyErrorFmtStr, "spec.entityStoreParams.databaseHost")
151-
}
152-
153-
if n.DatabaseUser == "" {
154-
return fmt.Errorf(emptyErrorFmtStr, "spec.entityStoreParams.databaseUser")
155-
}
156-
157-
if n.DatabaseName == "" {
158-
return fmt.Errorf(emptyErrorFmtStr, "spec.entityStoreParams.databaseName")
159-
}
160-
161-
if n.DBSecret == "" {
162-
return fmt.Errorf(emptyErrorFmtStr, "spec.entityStoreParams.dbSecret")
163-
}
164-
165-
return nil
166-
}
167-
168-
func (n *NemoEntitystore) Normalize() {
169-
if n.Spec.EntityStoreParams == nil {
170-
return
171-
}
172-
173-
n.Spec.EntityStoreParams.Normalize()
174-
}
175-
176-
func (n *NemoEntitystore) Validate() error {
177-
if n.Spec.EntityStoreParams == nil {
178-
return fmt.Errorf(nilErrorFmtStr, "spec.entityStoreParams")
179-
}
180-
181-
return n.Spec.EntityStoreParams.Validate()
182-
}
183-
184167
// GetPVCName returns the name to be used for the PVC based on the custom spec
185168
// Prefers pvc.Name if explicitly set by the user in the NemoEntitystore instance
186169
func (n *NemoEntitystore) GetPVCName(pvc PersistentVolumeClaim) string {
@@ -217,34 +200,34 @@ func (n *NemoEntitystore) GetStandardEnv() []corev1.EnvVar {
217200
envVars := []corev1.EnvVar{
218201
{
219202
Name: "APP_VERSION",
220-
Value: n.Spec.EntityStoreParams.AppVersion,
203+
Value: n.Spec.Image.Tag,
221204
},
222205
{
223206
Name: "POSTGRES_PASSWORD",
224207
ValueFrom: &corev1.EnvVarSource{
225208
SecretKeyRef: &corev1.SecretKeySelector{
226-
Key: n.Spec.EntityStoreParams.DBSecretPasswordKey,
209+
Key: n.Spec.DatabaseConfig.Credentials.PasswordKey,
227210
LocalObjectReference: corev1.LocalObjectReference{
228-
Name: n.Spec.EntityStoreParams.DBSecret,
211+
Name: n.Spec.DatabaseConfig.Credentials.SecretName,
229212
},
230213
},
231214
},
232215
},
233216
{
234217
Name: "POSTGRES_USER",
235-
Value: n.Spec.EntityStoreParams.DatabaseUser,
218+
Value: n.Spec.DatabaseConfig.Credentials.User,
236219
},
237220
{
238221
Name: "POSTGRES_HOST",
239-
Value: n.Spec.EntityStoreParams.DatabaseHost,
222+
Value: n.Spec.DatabaseConfig.Host,
240223
},
241224
{
242225
Name: "POSTGRES_PORT",
243-
Value: n.Spec.EntityStoreParams.DatabasePort,
226+
Value: strconv.FormatInt(int64(n.Spec.DatabaseConfig.Port), 10),
244227
},
245228
{
246229
Name: "POSTGRES_DB",
247-
Value: n.Spec.EntityStoreParams.DatabaseName,
230+
Value: n.Spec.DatabaseConfig.DatabaseName,
248231
},
249232
}
250233

api/apps/v1alpha1/zz_generated.deepcopy.go

Lines changed: 28 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bundle/manifests/apps.nvidia.com_nemoentitystores.yaml

Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,26 +63,64 @@ spec:
6363
items:
6464
type: string
6565
type: array
66-
entityStoreParams:
67-
description: Database stores the database config for the entity-store
68-
service
66+
databaseConfig:
67+
description: |-
68+
DatabaseConfig stores the database configuration for NEMO entitystore.
69+
Required, must not be nil.
6970
properties:
70-
appVersion:
71-
type: string
72-
databaseHost:
73-
type: string
71+
credentials:
72+
description: |-
73+
DatabaseCredentials stores the configuration to retrieve the database credentials.
74+
Required, must not be nil.
75+
properties:
76+
passwordKey:
77+
default: password
78+
description: |-
79+
PasswordKey is the name of the key in the `CredentialsSecret` secret for the database credentials.
80+
Defaults to "password".
81+
type: string
82+
secretName:
83+
description: |-
84+
SecretName is the name of the secret which has the database credentials for the NEMO entitystore user.
85+
Required, must not be empty.
86+
minLength: 1
87+
type: string
88+
user:
89+
description: |-
90+
User is the non-root username for NEMO EntityStore in the database.
91+
Required, must not be empty.
92+
minLength: 1
93+
type: string
94+
required:
95+
- secretName
96+
- user
97+
type: object
7498
databaseName:
99+
description: |-
100+
DatabaseName is the database name for NEMO EntityStore.
101+
Required, must not be empty.
102+
minLength: 1
75103
type: string
76-
databasePort:
77-
type: string
78-
databaseUser:
79-
type: string
80-
dbSecret:
81-
type: string
82-
dbSecretPasswordKey:
83-
type: string
84-
envConfigMap:
104+
host:
105+
description: |-
106+
Host is the hostname of the database.
107+
Required, must not be empty.
108+
minLength: 1
85109
type: string
110+
port:
111+
default: 5432
112+
description: |-
113+
Port is the port where the database is reachable at.
114+
If specified, this must be a valid port number, 0 < databasePort < 65536.
115+
Defaults to 5432.
116+
format: int32
117+
maximum: 65535
118+
minimum: 1
119+
type: integer
120+
required:
121+
- credentials
122+
- databaseName
123+
- host
86124
type: object
87125
env:
88126
items:
@@ -2120,6 +2158,7 @@ spec:
21202158
type: integer
21212159
required:
21222160
- authSecret
2161+
- databaseConfig
21232162
type: object
21242163
status:
21252164
description: NemoEntitystoreStatus defines the observed state of NemoEntitystore

0 commit comments

Comments
 (0)