Skip to content

Commit 0eea118

Browse files
varunrsekarshivamerla
authored andcommitted
abstract out guardrails configmap into separate object
Signed-off-by: Varun Ramachandra Sekar <vsekar@nvidia.com>
1 parent 66af12d commit 0eea118

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
@@ -83,11 +83,19 @@ type NemoGuardrailSpec struct {
8383
RuntimeClass string `json:"runtimeClass,omitempty"`
8484
}
8585

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

94+
type ConfigMap struct {
95+
// +kubebuilder:validation:MinLength=1
96+
Name string `json:"name"`
97+
}
98+
9199
// NemoGuardrailStatus defines the observed state of NemoGuardrail
92100
type NemoGuardrailStatus struct {
93101
Conditions []metav1.Condition `json:"conditions,omitempty"`
@@ -368,13 +376,13 @@ func (n *NemoGuardrail) GetDefaultStartupProbe() *corev1.Probe {
368376
// GetVolumes returns volumes for the NemoGuardrail container
369377
func (n *NemoGuardrail) GetVolumes() []corev1.Volume {
370378
volumes := []corev1.Volume{}
371-
if n.Spec.ConfigStore.ConfigMap != "" {
379+
if n.Spec.ConfigStore.ConfigMap != nil {
372380
volumes = append(volumes, corev1.Volume{
373381
Name: "config-store",
374382
VolumeSource: corev1.VolumeSource{
375383
ConfigMap: &corev1.ConfigMapVolumeSource{
376384
LocalObjectReference: corev1.LocalObjectReference{
377-
Name: n.Spec.ConfigStore.ConfigMap,
385+
Name: n.Spec.ConfigStore.ConfigMap.Name,
378386
},
379387
},
380388
},

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)