From 4de8683108b3e23ed16fcada20ae60ce5c4cb764 Mon Sep 17 00:00:00 2001 From: Yauheni Kaliuta Date: Tue, 30 Jul 2024 15:08:40 +0300 Subject: [PATCH] upgrade: cleanup CreateWithRetry usage CreateWithRetry() now checks AlreadyExists condition inside, so skip it handling. sleep() is not needed for DSCI with proper working CreateWithRetry since it is the actual point of existance of the function. Checking of number of DSCI instances is redundant as well since it is checked by the webhook. For non-webhook configuration it relies on the Create() failure for the same name. Basically, using CreateWithRetry for DSC is also redundant from webhook point of view since it is created after DSCI which garantees working webhook. But it handles already existed object. Signed-off-by: Yauheni Kaliuta --- pkg/upgrade/upgrade.go | 32 +++----------------------------- 1 file changed, 3 insertions(+), 29 deletions(-) diff --git a/pkg/upgrade/upgrade.go b/pkg/upgrade/upgrade.go index 72a6d6d5cc8..8f85bb4bbe1 100644 --- a/pkg/upgrade/upgrade.go +++ b/pkg/upgrade/upgrade.go @@ -7,7 +7,6 @@ import ( "errors" "fmt" "reflect" - "time" "github.com/hashicorp/go-multierror" operatorv1 "github.com/openshift/api/operator/v1" @@ -104,17 +103,9 @@ func CreateDefaultDSC(ctx context.Context, cli client.Client) error { }, } err := cluster.CreateWithRetry(ctx, cli, releaseDataScienceCluster, 1) // 1 min timeout - switch { - case err == nil: - fmt.Printf("created DataScienceCluster resource\n") - case k8serr.IsAlreadyExists(err): - // Do not update the DSC if it already exists - fmt.Printf("DataScienceCluster resource already exists. It will not be updated with default DSC.\n") - return nil - default: + if err != nil { return fmt.Errorf("failed to create DataScienceCluster custom resource: %w", err) } - return nil } @@ -152,27 +143,10 @@ func CreateDefaultDSCI(ctx context.Context, cli client.Client, _ cluster.Platfor Spec: *defaultDsciSpec, } - instances := &dsciv1.DSCInitializationList{} - if err := cli.List(ctx, instances); err != nil { + err := cluster.CreateWithRetry(ctx, cli, defaultDsci, 1) // 1 min timeout + if err != nil { return err } - - switch { - case len(instances.Items) > 1: - fmt.Println("only one instance of DSCInitialization object is allowed. Please delete other instances.") - return nil - case len(instances.Items) == 1: - // Do not patch/update if DSCI already exists. - fmt.Println("DSCInitialization resource already exists. It will not be updated with default DSCI.") - return nil - case len(instances.Items) == 0: - fmt.Println("create default DSCI CR.") - time.Sleep(10 * time.Second) // put 10 seconds sleep for webhook to fully functional before request first creation - err := cluster.CreateWithRetry(ctx, cli, defaultDsci, 1) // 1 min timeout - if err != nil && !k8serr.IsAlreadyExists(err) { - return err - } - } return nil }