Skip to content

Commit

Permalink
fix: add check to remove old kube-rbac-proxy container in modelregist…
Browse files Browse the repository at this point in the history
…ry operator, fixes RHOAIENG-15328 (opendatahub-io#1341)

* fix: add check to remove old kube-rbac-proxy container in modelregistry operator, fixes RHOAIENG-15328

Signed-off-by: Dhiraj Bokde <[email protected]>

* update: remove check in ModelReg code, add it to upgrade logic

Signed-off-by: Wen Zhou <[email protected]>

---------

Signed-off-by: Dhiraj Bokde <[email protected]>
Signed-off-by: Wen Zhou <[email protected]>
Co-authored-by: Wen Zhou <[email protected]>
  • Loading branch information
dhirajsb and zdtsw authored Nov 8, 2024
1 parent 656d53e commit 92251e4
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions pkg/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -487,6 +494,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 {
Expand Down

0 comments on commit 92251e4

Please sign in to comment.