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
59 changes: 59 additions & 0 deletions pkg/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
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 +288,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, dscApplicationsNamespace))

return multiErr.ErrorOrNil()
}

Expand Down Expand Up @@ -603,3 +607,58 @@ 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, applicationNS string) error {
var errs *multierror.Error

if oldRelease.Version.Minor >= 14 && oldRelease.Version.Minor <= 15 {
logger := logf.FromContext(ctx)
zdtsw marked this conversation as resolved.
Show resolved Hide resolved
nimCronjob := "nvidia-nim-periodic-validator"
nimConfigMap := "nvidia-nim-validation-result"
nimAPISec := "nvidia-nim-access"

job := &batchv1.CronJob{}
if err := cli.Get(ctx, types.NamespacedName{Name: nimCronjob, Namespace: applicationNS}, job); err != nil {
if !k8serr.IsNotFound(err) {
logger.V(1).Error(err, "failed to get NIM cronjob "+nimCronjob)
}
} else {
zdtsw marked this conversation as resolved.
Show resolved Hide resolved
if dErr := cli.Delete(ctx, job); dErr != nil {
logger.Error(dErr, "failed to remove NIM cronjob "+nimCronjob)
errs = multierror.Append(errs, dErr)
} else {
logger.Info("removed NIM cronjob successfully")
}
}

cm := &corev1.ConfigMap{}
if err := cli.Get(ctx, types.NamespacedName{Name: nimConfigMap, Namespace: applicationNS}, cm); err != nil {
if !k8serr.IsNotFound(err) {
logger.V(1).Error(err, "failed to get NIM configmap "+nimConfigMap)
}
} else {
if dErr := cli.Delete(ctx, cm); dErr != nil {
logger.Error(dErr, "failed to remove NIM configmap "+nimConfigMap)
errs = multierror.Append(errs, dErr)
} else {
logger.V(1).Info("removed NIM configmap successfully")
zdtsw marked this conversation as resolved.
Show resolved Hide resolved
}
}

sec := &corev1.Secret{}
if err := cli.Get(ctx, types.NamespacedName{Name: nimAPISec, Namespace: applicationNS}, sec); err != nil {
if !k8serr.IsNotFound(err) {
logger.V(1).Error(err, "failed to get NIM API key secret "+nimAPISec)
}
} else {
if dErr := cli.Delete(ctx, sec); dErr != nil {
logger.Error(dErr, "failed to remove NIM API key secret "+nimAPISec)
errs = multierror.Append(errs, dErr)
} else {
logger.V(1).Info("removed NIM API key secret successfully")
}
}
}

return errs.ErrorOrNil()
}