Skip to content

Commit ce7d72c

Browse files
committed
abstract out guardrails configmap into separate object
Signed-off-by: Varun Ramachandra Sekar <vsekar@nvidia.com>
1 parent 2de5fbe commit ce7d72c

6 files changed

Lines changed: 63 additions & 7 deletions

File tree

api/apps/v1alpha1/nemo_guardrails_types.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,19 @@ type NemoGuardrailSpec struct {
8181
RuntimeClass string `json:"runtimeClass,omitempty"`
8282
}
8383

84+
// GuardrailConfig defines the source where the service config is made available.
85+
//
86+
// +kubebuilder:validation:XValidation:rule="!(has(self.configMap) && has(self.pvc))", message="Cannot set both ConfigMap and PVC in ConfigStore"
8487
type GuardrailConfig struct {
85-
ConfigMap string `json:"configMap,omitempty"`
88+
ConfigMap *ConfigMap `json:"configMap,omitempty"`
8689
PVC *PersistentVolumeClaim `json:"pvc,omitempty"`
8790
}
8891

92+
type ConfigMap struct {
93+
// +kubebuilder:validation:MinLength=1
94+
Name string `json:"name"`
95+
}
96+
8997
// NemoGuardrailStatus defines the observed state of NemoGuardrail
9098
type NemoGuardrailStatus struct {
9199
Conditions []metav1.Condition `json:"conditions,omitempty"`
@@ -375,13 +383,13 @@ func (n *NemoGuardrail) GetDefaultStartupProbe() *corev1.Probe {
375383
// GetVolumes returns volumes for the NemoGuardrail container
376384
func (n *NemoGuardrail) GetVolumes() []corev1.Volume {
377385
volumes := []corev1.Volume{}
378-
if n.Spec.ConfigStore.ConfigMap != "" {
386+
if n.Spec.ConfigStore.ConfigMap != nil {
379387
volumes = append(volumes, corev1.Volume{
380388
Name: "config-store",
381389
VolumeSource: corev1.VolumeSource{
382390
ConfigMap: &corev1.ConfigMapVolumeSource{
383391
LocalObjectReference: corev1.LocalObjectReference{
384-
Name: n.Spec.ConfigStore.ConfigMap,
392+
Name: n.Spec.ConfigStore.ConfigMap.Name,
385393
},
386394
},
387395
},

api/apps/v1alpha1/zz_generated.deepcopy.go

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

bundle/manifests/apps.nvidia.com_nemoguardrails.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,13 @@ spec:
6767
description: ConfigStore stores the config of the guardrail service
6868
properties:
6969
configMap:
70-
type: string
70+
properties:
71+
name:
72+
minLength: 1
73+
type: string
74+
required:
75+
- name
76+
type: object
7177
pvc:
7278
description: PersistentVolumeClaim defines the attributes of PVC
7379
used as a source for caching NIM model
@@ -94,6 +100,9 @@ spec:
94100
type: string
95101
type: object
96102
type: object
103+
x-kubernetes-validations:
104+
- message: Cannot set both ConfigMap and PVC in ConfigStore
105+
rule: '!(has(self.configMap) && has(self.pvc))'
97106
env:
98107
items:
99108
description: EnvVar represents an environment variable present in

config/crd/bases/apps.nvidia.com_nemoguardrails.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,13 @@ spec:
6767
description: ConfigStore stores the config of the guardrail service
6868
properties:
6969
configMap:
70-
type: string
70+
properties:
71+
name:
72+
minLength: 1
73+
type: string
74+
required:
75+
- name
76+
type: object
7177
pvc:
7278
description: PersistentVolumeClaim defines the attributes of PVC
7379
used as a source for caching NIM model
@@ -94,6 +100,9 @@ spec:
94100
type: string
95101
type: object
96102
type: object
103+
x-kubernetes-validations:
104+
- message: Cannot set both ConfigMap and PVC in ConfigStore
105+
rule: '!(has(self.configMap) && has(self.pvc))'
97106
env:
98107
items:
99108
description: EnvVar represents an environment variable present in

config/samples/apps_v1alpha1_nemoguardrails.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ metadata:
88
spec:
99
authSecret: ngc-api-secret
1010
configStore:
11-
configMap: gr-config
11+
configMap:
12+
name: gr-config
1213
env:
1314
- name: NIM_ENDPOINT_URL
1415
value: "http://<NIM_SERVICE_ENDPOINT>:<NIM_SERVICE_PORT>/v1"

deployments/helm/k8s-nim-operator/crds/apps.nvidia.com_nemoguardrails.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,13 @@ spec:
6767
description: ConfigStore stores the config of the guardrail service
6868
properties:
6969
configMap:
70-
type: string
70+
properties:
71+
name:
72+
minLength: 1
73+
type: string
74+
required:
75+
- name
76+
type: object
7177
pvc:
7278
description: PersistentVolumeClaim defines the attributes of PVC
7379
used as a source for caching NIM model
@@ -94,6 +100,9 @@ spec:
94100
type: string
95101
type: object
96102
type: object
103+
x-kubernetes-validations:
104+
- message: Cannot set both ConfigMap and PVC in ConfigStore
105+
rule: '!(has(self.configMap) && has(self.pvc))'
97106
env:
98107
items:
99108
description: EnvVar represents an environment variable present in

0 commit comments

Comments
 (0)