|
6 | 6 |
|
7 | 7 | clusterv1beta1 "github.com/replicatedhq/embedded-cluster/kinds/apis/v1beta1" |
8 | 8 | "github.com/replicatedhq/embedded-cluster/pkg/kubeutils" |
| 9 | + "k8s.io/client-go/util/retry" |
9 | 10 | controllerruntime "sigs.k8s.io/controller-runtime" |
10 | 11 | "sigs.k8s.io/controller-runtime/pkg/client" |
11 | 12 | ) |
@@ -39,16 +40,23 @@ func CreateInstallation(ctx context.Context, cli client.Client, original *cluste |
39 | 40 |
|
40 | 41 | // setInstallationState gets the installation object of the given name and sets the state to the given state. |
41 | 42 | func setInstallationState(ctx context.Context, cli client.Client, name string, state string, reason string, pendingCharts ...string) error { |
42 | | - existingInstallation := &clusterv1beta1.Installation{} |
43 | | - err := cli.Get(ctx, client.ObjectKey{Name: name}, existingInstallation) |
44 | | - if err != nil { |
45 | | - return fmt.Errorf("get installation: %w", err) |
46 | | - } |
47 | | - existingInstallation.Status.SetState(state, reason, pendingCharts) |
48 | | - err = cli.Status().Update(ctx, existingInstallation) |
| 43 | + err := retry.RetryOnConflict(retry.DefaultRetry, func() error { |
| 44 | + existingInstallation := &clusterv1beta1.Installation{} |
| 45 | + err := cli.Get(ctx, client.ObjectKey{Name: name}, existingInstallation) |
| 46 | + if err != nil { |
| 47 | + return fmt.Errorf("get installation: %w", err) |
| 48 | + } |
| 49 | + existingInstallation.Status.SetState(state, reason, pendingCharts) |
| 50 | + err = cli.Status().Update(ctx, existingInstallation) |
| 51 | + if err != nil { |
| 52 | + return err |
| 53 | + } |
| 54 | + return nil |
| 55 | + }) |
49 | 56 | if err != nil { |
50 | | - return fmt.Errorf("update installation status: %w", err) |
| 57 | + return fmt.Errorf("failed to set installation state after 5 attempts %w", err) |
51 | 58 | } |
| 59 | + |
52 | 60 | return nil |
53 | 61 | } |
54 | 62 |
|
|
0 commit comments