Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Nov 8, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
dhirajsb marked this conversation as resolved.
Show resolved Hide resolved
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.
dhirajsb marked this conversation as resolved.
Show resolved Hide resolved
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