Skip to content

Commit

Permalink
upgrade: cleanup CreateWithRetry usage
Browse files Browse the repository at this point in the history
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 <ykaliuta@redhat.com>
  • Loading branch information
ykaliuta committed Jul 30, 2024
1 parent 69b6cb9 commit 4de8683
Showing 1 changed file with 3 additions and 29 deletions.
32 changes: 3 additions & 29 deletions pkg/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"errors"
"fmt"
"reflect"
"time"

"github.com/hashicorp/go-multierror"
operatorv1 "github.com/openshift/api/operator/v1"
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 4de8683

Please sign in to comment.