Skip to content

Commit

Permalink
chore: enable datastore controller
Browse files Browse the repository at this point in the history
Signed-off-by: shil <[email protected]>
  • Loading branch information
shil committed Nov 25, 2024
1 parent 7373a68 commit 3863ef4
Show file tree
Hide file tree
Showing 10 changed files with 4,626 additions and 49 deletions.
128 changes: 115 additions & 13 deletions api/apps/v1alpha1/nemo_datastore_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@ import (
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

const (
// NemoDatastoreConditionReady indicates that the NEMO GuardrailService is ready.
// NemoDatastoreConditionReady indicates that the NEMO datastore service is ready.
NemoDatastoreConditionReady = "Ready"
// NemoDatastoreConditionFailed indicates that the NEMO GuardrailService has failed.
// NemoDatastoreConditionFailed indicates that the NEMO datastore service has failed.
NemoDatastoreConditionFailed = "Failed"

// NemoDatastoreStatusPending indicates that NEMO GuardrailService is in pending state
// NemoDatastoreStatusPending indicates that NEMO datastore service is in pending state
NemoDatastoreStatusPending = "Pending"
// NemoDatastoreStatusNotReady indicates that NEMO GuardrailService is not ready
// NemoDatastoreStatusNotReady indicates that NEMO datastore service is not ready
NemoDatastoreStatusNotReady = "NotReady"
// NemoDatastoreStatusReady indicates that NEMO GuardrailService is ready
// NemoDatastoreStatusReady indicates that NEMO datastore service is ready
NemoDatastoreStatusReady = "Ready"
// NemoDatastoreStatusFailed indicates that NEMO GuardrailService has failed
// NemoDatastoreStatusFailed indicates that NEMO datastore service has failed
NemoDatastoreStatusFailed = "Failed"
)

Expand All @@ -58,7 +58,7 @@ type NemoDatastoreSpec struct {
Args []string `json:"args,omitempty"`
Env []corev1.EnvVar `json:"env,omitempty"`
// The name of an secret that contains authn for the NGC NIM service API
AuthSecret string `json:"authSecret"`
AuthSecret string `json:"authSecret"`
Labels map[string]string `json:"labels,omitempty"`
Annotations map[string]string `json:"annotations,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
Expand All @@ -78,6 +78,7 @@ type NemoDatastoreSpec struct {
GroupID *int64 `json:"groupID,omitempty"`
RuntimeClass string `json:"runtimeClass,omitempty"`

DataStoreParams NemoDataStoreParams `json:"dataStoreParams"`
}

// NemoDatastoreStatus defines the observed state of NemoDatastore
Expand All @@ -87,6 +88,22 @@ type NemoDatastoreStatus struct {
State string `json:"state,omitempty"`
}

type NemoDataStoreParams struct {
AppVersion string `json:"appVersion"`
GiteaEndpoint string `json:"giteaEndpoint"`
GiteaSecret string `json:"giteaSecret"`
DatabaseURL string `json:"databaseURL"`
DatabaseHost string `json:"databaseHost"`
DatabasePort string `json:"databasePort"`
DBSecret string `json:"dbSecret"`

EnvConfigMap string `json:"envConfigmap"`
EnvSecret string `json:"envSecret"`

InitContainerImage string `json:"initContainerImage,omitempty"`
InitContainerCommand []string `json:"initContainerCommand,omitempty"`
}

// +genclient
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
Expand Down Expand Up @@ -124,7 +141,8 @@ func (n *NemoDatastore) GetPVCName(pvc PersistentVolumeClaim) string {
// GetStandardSelectorLabels returns the standard selector labels for the NemoDatastore deployment
func (n *NemoDatastore) GetStandardSelectorLabels() map[string]string {
return map[string]string{
"app": n.Name,
"app.kubernetes.io/name": n.Name,
"app.kubernetes.io/instance": n.Name,
}
}

Expand All @@ -142,11 +160,98 @@ func (n *NemoDatastore) GetStandardLabels() map[string]string {
// GetStandardEnv returns the standard set of env variables for the NemoDatastore container
func (n *NemoDatastore) GetStandardEnv() []corev1.EnvVar {
// add standard env required for NIM service
envVars := []corev1.EnvVar{}

envVars := []corev1.EnvVar{
{
Name: "APP_VERSION",
Value: n.Spec.DataStoreParams.AppVersion,
},
{
Name: "GITEA_ENDPOINT",
Value: n.Spec.DataStoreParams.GiteaEndpoint,
},
{
Name: "GITEA_ORG_NAME",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
Key: "username",
LocalObjectReference: corev1.LocalObjectReference{
Name: n.Spec.DataStoreParams.GiteaSecret,
},
},
},
},
{
Name: "GITEA_PASSWORD",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
Key: "password",
LocalObjectReference: corev1.LocalObjectReference{
Name: n.Spec.DataStoreParams.GiteaSecret,
},
},
},
},
{
Name: "DATABASE_URL",
Value: n.Spec.DataStoreParams.DatabaseURL,
},
{
Name: "DB_PASSWORD",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
Key: "password",
LocalObjectReference: corev1.LocalObjectReference{
Name: n.Spec.DataStoreParams.DBSecret,
},
},
},
},
}
return envVars
}

// GetStandardAnnotations returns default annotations to apply to the NemoDatastore instance
func (n *NemoDatastore) GetEnvFrom() []corev1.EnvFromSource {
return []corev1.EnvFromSource{
{
ConfigMapRef: &corev1.ConfigMapEnvSource{
LocalObjectReference: corev1.LocalObjectReference{
Name: n.Spec.DataStoreParams.EnvConfigMap,
},
},
},
{
SecretRef: &corev1.SecretEnvSource{
LocalObjectReference: corev1.LocalObjectReference{
Name: n.Spec.DataStoreParams.EnvSecret,
},
},
},
}
}

func (n *NemoDatastore) GetInitContainers() []corev1.Container {
image := n.Spec.DataStoreParams.InitContainerImage
if image == "" {
image = "busybox"
}
cmd := n.Spec.DataStoreParams.InitContainerCommand
if len(cmd) == 0 {
cmd = []string{
"sh",
"-c",
fmt.Sprintf("until nc -z %s %s; do echo \"PostgreSQL is unavailable. Sleeping for 5 seconds\"; sleep 5; done;", n.Spec.DataStoreParams.DatabaseHost, n.Spec.DataStoreParams.DatabasePort),
}
}
return []corev1.Container{
{
Name: "wait-postgres-ready",
Image: image,
Command: cmd,
},
}
}

// GetStandardAnnotations returns default annotations to apply to the NemoDatastore instance
func (n *NemoDatastore) GetStandardAnnotations() map[string]string {
standardAnnotations := map[string]string{
Expand Down Expand Up @@ -299,9 +404,6 @@ func (n *NemoDatastore) GetDefaultReadinessProbe() *corev1.Probe {

// GetStartupProbe returns startup probe for the NemoDatastore container
func (n *NemoDatastore) GetStartupProbe() *corev1.Probe {
if n.Spec.StartupProbe.Probe == nil {
return n.GetDefaultStartupProbe()
}
return n.Spec.StartupProbe.Probe
}

Expand Down
4 changes: 3 additions & 1 deletion api/apps/v1alpha1/nemo_guardrails_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ func (n *NemoGuardrail) GetPVCName(pvc PersistentVolumeClaim) string {
// GetStandardSelectorLabels returns the standard selector labels for the NemoGuardrail deployment
func (n *NemoGuardrail) GetStandardSelectorLabels() map[string]string {
return map[string]string{
"app": n.Name,
"app": n.Name,
"app.kubernetes.io/name": n.Name,
"app.kubernetes.io/instance": n.Name,
}
}

Expand Down
21 changes: 21 additions & 0 deletions api/apps/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3863ef4

Please sign in to comment.