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

Task/NVPE-32: Cleanup NIM integration tech preview resources #1369

Merged
merged 7 commits into from
Nov 14, 2024
46 changes: 46 additions & 0 deletions pkg/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ import (
"fmt"
"reflect"

batchv1 "k8s.io/api/batch/v1"

"github.com/hashicorp/go-multierror"
operatorv1 "github.com/openshift/api/operator/v1"
routev1 "github.com/openshift/api/route/v1"
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
appsv1 "k8s.io/api/apps/v1"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
apiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
Expand Down Expand Up @@ -287,6 +290,9 @@ func CleanupExistingResource(ctx context.Context,
toDelete := getDashboardWatsonResources(dscApplicationsNamespace)
multiErr = multierror.Append(multiErr, deleteResources(ctx, cli, &toDelete))

// cleanup nvidia nim integration remove tech preview
multiErr = multierror.Append(multiErr, cleanupNimIntegrationTechPreview(ctx, cli, oldReleaseVersion))
TomerFi marked this conversation as resolved.
Show resolved Hide resolved

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andrewballantyne dont we need to cleanup api key secret also? AFAIU UI will create the secret when user selects the enable button. So, if the secret is present then it will result in an error.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's a good catch. If we don't delete the secret and we don't have a NIM Account CR here... it will likely block the creation flow. @etirelli should we delete the customer's "key file" or look at some what to keep/update it on install in the new Controller way?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say update/reuse would be best as it is unlikely the API key itself changed and forcing the customer to update might create confusion.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discussed in slack. We will delete the secret if it exists and let the user recreate it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved in 0483894.


return multiErr.ErrorOrNil()
}

Expand Down Expand Up @@ -603,3 +609,43 @@ func GetDeployedRelease(ctx context.Context, cli client.Client) (cluster.Release
// could be a clean installation or both CRs are deleted already
return cluster.Release{}, nil
}

func cleanupNimIntegrationTechPreview(ctx context.Context, cli client.Client, oldRelease cluster.Release) error {
TomerFi marked this conversation as resolved.
Show resolved Hide resolved
logger := logf.FromContext(ctx)
var errs *multierror.Error

// TODO where can we get the system namespace, opendatahub | redhat-ods-applications ?
ns := "todo-get-namespace"
TomerFi marked this conversation as resolved.
Show resolved Hide resolved

if oldRelease.Version.Minor < 16 {
TomerFi marked this conversation as resolved.
Show resolved Hide resolved
cm := &corev1.ConfigMap{}
if err := cli.Get(ctx, types.NamespacedName{Name: "nvidia-nim-validation-result", Namespace: ns}, cm); err != nil {
TomerFi marked this conversation as resolved.
Show resolved Hide resolved
if !k8serr.IsNotFound(err) {
logger.V(1).Error(err, "failed to fetch tech preview validation result configmap")
zdtsw marked this conversation as resolved.
Show resolved Hide resolved
}
} else {
if dErr := cli.Delete(ctx, cm); dErr != nil {
logger.Error(dErr, "failed to remove tech preview validation result configmap")
errs = multierror.Append(errs, dErr)
} else {
logger.V(1).Info("tech preview validation result configmap successfully removed")
}
}

job := &batchv1.CronJob{}
if err := cli.Get(ctx, types.NamespacedName{Name: "nvidia-nim-periodic-validator", Namespace: ns}, job); err != nil {
TomerFi marked this conversation as resolved.
Show resolved Hide resolved
if !k8serr.IsNotFound(err) {
logger.V(1).Error(err, "failed to fetch tech preview validation result configmap")
}
} else {
if dErr := cli.Delete(ctx, job); dErr != nil {
logger.Error(dErr, "failed to remove tech preview cron job")
errs = multierror.Append(errs, dErr)
} else {
logger.Info("tech preview cron job successfully removed")
}
}
}

return errs.ErrorOrNil()
}