Skip to content

Commit

Permalink
fix(guardrails): Get orchestrator image from operator's ConfigMap (tr…
Browse files Browse the repository at this point in the history
…ustyai-explainability#417)

* fix(guardrails): Get orchestrator image from operator's config map

* fix(guardrails): Update tests
  • Loading branch information
ruivieira authored Feb 14, 2025
1 parent 007d94a commit 7cb634d
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 108 deletions.
2 changes: 1 addition & 1 deletion controllers/gorch/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const (
orchestratorName = "guardrails-orchestrator"
finalizerName = "trustyai.opendatahub.io/gorch-finalizer"
configMapName = "gorch-config"
orchestratorImageKey = "guardrailsOrchestratorImage"
orchestratorImageKey = "guardrails-orchestrator-image"
vllmGatewayImageKey = "vllmGatewayImage"
regexDetectorImageKey = "regexDetectorImage"
ServiceName = "GORCH"
Expand Down
6 changes: 3 additions & 3 deletions controllers/gorch/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type DeploymentConfig struct {
func (r *GuardrailsOrchestratorReconciler) createDeployment(ctx context.Context, orchestrator *gorchv1alpha1.GuardrailsOrchestrator) *appsv1.Deployment {
var containerImages ContainerImages
// Get orchestrator image
orchestratorImage, err := r.getImageFromConfigMap(ctx, orchestratorImageKey, constants.ConfigMap, orchestrator.Namespace)
orchestratorImage, err := r.getImageFromConfigMap(ctx, orchestratorImageKey, constants.ConfigMap, r.Namespace)
if orchestratorImage == "" || err != nil {
log.FromContext(ctx).Error(err, "Error getting container image from ConfigMap.")
}
Expand All @@ -46,11 +46,11 @@ func (r *GuardrailsOrchestratorReconciler) createDeployment(ctx context.Context,
// Check if the vLLM gateway is enabled
if orchestrator.Spec.VLLMGatewayConfig != nil {
// Get the gateway and regex detector container images
vllmGatewayImage, err := r.getImageFromConfigMap(ctx, vllmGatewayImageKey, constants.ConfigMap, orchestrator.Namespace)
vllmGatewayImage, err := r.getImageFromConfigMap(ctx, vllmGatewayImageKey, orchestratorName+"-config", orchestrator.Namespace)
if vllmGatewayImage == "" || err != nil {
log.FromContext(ctx).Error(err, "Error getting vLLM gateway image from ConfigMap.")
}
regexDetectorImage, err := r.getImageFromConfigMap(ctx, regexDetectorImageKey, constants.ConfigMap, orchestrator.Namespace)
regexDetectorImage, err := r.getImageFromConfigMap(ctx, regexDetectorImageKey, orchestratorName+"-config", orchestrator.Namespace)
if regexDetectorImage == "" || err != nil {
log.FromContext(ctx).Error(err, "Error getting regex detectors image from ConfigMap.")
}
Expand Down
162 changes: 58 additions & 104 deletions controllers/gorch/guardrailsorchestrator_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,51 +126,22 @@ func deleteGuardrailsOrchestrator(ctx context.Context, namespace string) error {

func testCreateDeleteGuardrailsOrchestrator(namespaceName string) {
It("Should sucessfully reconcile creating a custom resource for the GuardrailsOrchestrator", func() {
By("Creating an Orchestrator configmap")
configMap := &corev1.ConfigMap{
TypeMeta: metav1.TypeMeta{
Kind: "ConfigMap",
APIVersion: "v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: orchestratorName + "-config",
Namespace: namespaceName,
},
}
err := k8sClient.Create(ctx, configMap)
Expect(err).ToNot(HaveOccurred())

By("Creating a custom resource for the GuardrailsOrchestrator")
ctx := context.Background()
typedNamespacedName := types.NamespacedName{Name: orchestratorName, Namespace: namespaceName}
err = createGuardrailsOrchestrator(ctx, configMap.Name)
err := createGuardrailsOrchestrator(ctx, orchestratorName+"-config")
Expect(err).ToNot(HaveOccurred())

By("Checking if the custom resource was successfully created")
err = k8sClient.Get(ctx, typedNamespacedName, &gorchv1alpha1.GuardrailsOrchestrator{})
Expect(err).ToNot(HaveOccurred())

By("Creating the TrustyAI configmap for testing")
configMap = &corev1.ConfigMap{
TypeMeta: metav1.TypeMeta{
Kind: "ConfigMap",
APIVersion: "v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: constants.ConfigMap,
Namespace: namespaceName,
},
Data: map[string]string{
orchestratorImageKey: "quay.io/trustyai/ta-guardrails-orchestrator:latest",
},
}
err = k8sClient.Create(ctx, configMap)
Expect(err).ToNot(HaveOccurred())

By("Reconciling the custom resource that was created")
reconciler := &GuardrailsOrchestratorReconciler{
Client: k8sClient,
Scheme: k8sClient.Scheme(),
Client: k8sClient,
Scheme: k8sClient.Scheme(),
Namespace: namespaceName,
}

_, err = reconciler.Reconcile(ctx, reconcile.Request{NamespacedName: typedNamespacedName})
Expand Down Expand Up @@ -243,22 +214,9 @@ func testCreateDeleteGuardrailsOrchestrator(namespaceName string) {

func testCreateDeleteGuardrailsOrchestratorSidecar(namespaceName string) {
It("Should sucessfully reconcile creating a custom resource for the GuardrailsOrchestrator", func() {
By("Creating an Orchestrator configmap")
configMap := &corev1.ConfigMap{
TypeMeta: metav1.TypeMeta{
Kind: "ConfigMap",
APIVersion: "v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: orchestratorName + "-config",
Namespace: namespaceName,
},
}
err := k8sClient.Create(ctx, configMap)
Expect(err).ToNot(HaveOccurred())

By("Creating an VLLM Gateway configmap")
configMap = &corev1.ConfigMap{
configMap := &corev1.ConfigMap{
TypeMeta: metav1.TypeMeta{
Kind: "ConfigMap",
APIVersion: "v1",
Expand All @@ -268,7 +226,7 @@ func testCreateDeleteGuardrailsOrchestratorSidecar(namespaceName string) {
Namespace: namespaceName,
},
}
err = k8sClient.Create(ctx, configMap)
err := k8sClient.Create(ctx, configMap)
Expect(err).ToNot(HaveOccurred())

By("Creating a custom resource for the GuardrailsOrchestrator")
Expand All @@ -281,29 +239,11 @@ func testCreateDeleteGuardrailsOrchestratorSidecar(namespaceName string) {
err = k8sClient.Get(ctx, typedNamespacedName, &gorchv1alpha1.GuardrailsOrchestrator{})
Expect(err).ToNot(HaveOccurred())

By("Creating the TrustyAI configmap with sidecar images")
configMap = &corev1.ConfigMap{
TypeMeta: metav1.TypeMeta{
Kind: "ConfigMap",
APIVersion: "v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: constants.ConfigMap,
Namespace: namespaceName,
},
Data: map[string]string{
orchestratorImageKey: "quay.io/trustyai/ta-guardrails-orchestrator:latest",
vllmGatewayImageKey: "quay.io/trustyai/ta-guardrails-gateway:latest",
regexDetectorImageKey: "quay.io/trustyai/ta-guardrails-regex:latest",
},
}
err = k8sClient.Create(ctx, configMap)
Expect(err).ToNot(HaveOccurred())

By("Reconciling the custom resource that was created")
reconciler := &GuardrailsOrchestratorReconciler{
Client: k8sClient,
Scheme: k8sClient.Scheme(),
Client: k8sClient,
Scheme: k8sClient.Scheme(),
Namespace: namespaceName,
}

_, err = reconciler.Reconcile(ctx, reconcile.Request{NamespacedName: typedNamespacedName})
Expand All @@ -312,11 +252,11 @@ func testCreateDeleteGuardrailsOrchestratorSidecar(namespaceName string) {
By("Checking if resources were successfully created in the reconcilation")
Eventually(func() error {
configMap := &corev1.ConfigMap{}
if err := k8sClient.Get(ctx, types.NamespacedName{Name: constants.ConfigMap, Namespace: namespaceName}, configMap); err != nil {
if err := k8sClient.Get(ctx, types.NamespacedName{Name: orchestratorName + "-config", Namespace: namespaceName}, configMap); err != nil {
return err
}
Expect(configMap.Namespace).Should(Equal(namespaceName))
Expect(configMap.Name).Should(Equal(constants.ConfigMap))
Expect(configMap.Name).Should(Equal(orchestratorName + "-config"))

serviceAccount := &corev1.ServiceAccount{}
if err := k8sClient.Get(ctx, types.NamespacedName{Name: orchestratorName + "-serviceaccount", Namespace: namespaceName}, serviceAccount); err != nil {
Expand Down Expand Up @@ -376,51 +316,22 @@ func testCreateDeleteGuardrailsOrchestratorSidecar(namespaceName string) {

func testCreateDeleteGuardrailsOrchestratorOtelExporter(namespaceName string) {
It("Should sucessfully reconcile creating a custom resource for the GuardrailsOrchestrator", func() {
By("Creating an Orchestrator configmap")
configMap := &corev1.ConfigMap{
TypeMeta: metav1.TypeMeta{
Kind: "ConfigMap",
APIVersion: "v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: orchestratorName + "-config",
Namespace: namespaceName,
},
}
err := k8sClient.Create(ctx, configMap)
Expect(err).ToNot(HaveOccurred())

By("Creating a custom resource for the GuardrailsOrchestrator")
ctx := context.Background()
typedNamespacedName := types.NamespacedName{Name: orchestratorName, Namespace: namespaceName}
err = createGuardrailsOrchestratorOtelExporter(ctx, configMap.Name)
err := createGuardrailsOrchestratorOtelExporter(ctx, orchestratorName+"-config")
Expect(err).ToNot(HaveOccurred())

By("Checking if the custom resource was successfully created")
err = k8sClient.Get(ctx, typedNamespacedName, &gorchv1alpha1.GuardrailsOrchestrator{})
Expect(err).ToNot(HaveOccurred())

By("Creating the TrustyAI configmap with sidecar images")
configMap = &corev1.ConfigMap{
TypeMeta: metav1.TypeMeta{
Kind: "ConfigMap",
APIVersion: "v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: constants.ConfigMap,
Namespace: namespaceName,
},
Data: map[string]string{
orchestratorImageKey: "quay.io/trustyai/ta-guardrails-orchestrator:latest",
},
}
err = k8sClient.Create(ctx, configMap)
Expect(err).ToNot(HaveOccurred())

By("Reconciling the custom resource that was created")
reconciler := &GuardrailsOrchestratorReconciler{
Client: k8sClient,
Scheme: k8sClient.Scheme(),
Client: k8sClient,
Scheme: k8sClient.Scheme(),
Namespace: namespaceName,
}

_, err = reconciler.Reconcile(ctx, reconcile.Request{NamespacedName: typedNamespacedName})
Expand Down Expand Up @@ -502,6 +413,49 @@ func testCreateDeleteGuardrailsOrchestratorOtelExporter(namespaceName string) {
}

var _ = Describe("GuardrailsOrchestrator Controller", func() {
var ctx = context.Background()
BeforeEach(func() {
By("Creating the operator's ConfigMap")
configMap := &corev1.ConfigMap{
TypeMeta: metav1.TypeMeta{
Kind: "ConfigMap",
APIVersion: "v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: constants.ConfigMap,
Namespace: namespaceName,
},
Data: map[string]string{
orchestratorImageKey: "quay.io/trustyai/ta-guardrails-orchestrator:latest",
},
}
err := k8sClient.Create(ctx, configMap)

if err != nil && !errors.IsAlreadyExists(err) {
Expect(err).ToNot(HaveOccurred())
}

orchConfig := &corev1.ConfigMap{
TypeMeta: metav1.TypeMeta{
Kind: "ConfigMap",
APIVersion: "v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: orchestratorName + "-config",
Namespace: namespaceName,
},
Data: map[string]string{
vllmGatewayImageKey: "quay.io/trustyai/ta-guardrails-gateway:latest",
regexDetectorImageKey: "quay.io/trustyai/ta-guardrails-regex:latest",
},
}
err = k8sClient.Create(ctx, orchConfig)
if err != nil && !errors.IsAlreadyExists(err) {
Expect(err).ToNot(HaveOccurred())
}

})

Context("GuardrailsOrchestrator Controller Test", func() {
testCreateDeleteGuardrailsOrchestrator(namespaceName)
testCreateDeleteGuardrailsOrchestratorSidecar(namespaceName)
Expand Down

0 comments on commit 7cb634d

Please sign in to comment.