@@ -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
6756type 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
186169func (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
0 commit comments