From a5771c8a1573be183db307b5f5abc149489e58d7 Mon Sep 17 00:00:00 2001 From: Dhiraj Bokde Date: Thu, 7 Nov 2024 22:26:30 -0800 Subject: [PATCH] fix: add check to remove old kube-rbac-proxy container in modelregistry operator, fixes RHOAIENG-15328 (#1341) * fix: add check to remove old kube-rbac-proxy container in modelregistry operator, fixes RHOAIENG-15328 Signed-off-by: Dhiraj Bokde * update: remove check in ModelReg code, add it to upgrade logic Signed-off-by: Wen Zhou --------- Signed-off-by: Dhiraj Bokde Signed-off-by: Wen Zhou Co-authored-by: Wen Zhou (cherry picked from commit 92251e4568eb567c4654b7a2a64fbdc6b5ae42f3) --- pkg/upgrade/upgrade.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/pkg/upgrade/upgrade.go b/pkg/upgrade/upgrade.go index df16b42ab0e..78cfe7710a3 100644 --- a/pkg/upgrade/upgrade.go +++ b/pkg/upgrade/upgrade.go @@ -43,6 +43,7 @@ import ( "github.com/opendatahub-io/opendatahub-operator/v2/components/workbenches" "github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster" "github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster/gvk" + "github.com/opendatahub-io/opendatahub-operator/v2/pkg/metadata/labels" ) type ResourceSpec struct { @@ -275,6 +276,12 @@ func CleanupExistingResource(ctx context.Context, return err } } + // remove modelreg proxy container from deployment in ODH + if platform == cluster.OpenDataHub { + if err := removeRBACProxyModelRegistry(ctx, cli, "model-registry-operator", "kube-rbac-proxy", dscApplicationsNamespace); err != nil { + return err + } + } // to take a reference toDelete := getDashboardWatsonResources(dscApplicationsNamespace) @@ -482,6 +489,38 @@ func updateODCModelRegistry(ctx context.Context, cli client.Client, instanceName return nil } +// workaround for RHOAIENG-15328 +// TODO: this can be removed from ODH 2.22. +func removeRBACProxyModelRegistry(ctx context.Context, cli client.Client, componentName string, containerName string, applicationNS string) error { + log := logf.FromContext(ctx) + deploymentList := &appsv1.DeploymentList{} + if err := cli.List(ctx, deploymentList, client.InNamespace(applicationNS), client.HasLabels{labels.ODH.Component(componentName)}); err != nil { + return fmt.Errorf("error fetching list of deployments: %w", err) + } + + if len(deploymentList.Items) != 1 { // ModelRegistry operator is not deployed + return nil + } + mrDeployment := deploymentList.Items[0] + mrContainerList := mrDeployment.Spec.Template.Spec.Containers + // if only one container in deployment, we are already on newer deployment, no need more action + if len(mrContainerList) == 1 { + return nil + } + + log.Info("Upgrade force ModelRegistry to remove container from deployment") + for i, container := range mrContainerList { + if container.Name == containerName { + removeUnusedKubeRbacProxy := []byte(fmt.Sprintf("[{\"op\": \"remove\", \"path\": \"/spec/template/spec/containers/%d\"}]", i)) + if err := cli.Patch(ctx, &mrDeployment, client.RawPatch(types.JSONPatchType, removeUnusedKubeRbacProxy)); err != nil { + return fmt.Errorf("error removing ModelRegistry %s container from deployment: %w", containerName, err) + } + break + } + } + return nil +} + func RemoveLabel(ctx context.Context, cli client.Client, objectName string, labelKey string) error { foundNamespace := &corev1.Namespace{} if err := cli.Get(ctx, client.ObjectKey{Name: objectName}, foundNamespace); err != nil {