Skip to content

Commit b2ee442

Browse files
authored
retry setting installation state on conflict (#1382)
1 parent 13367d8 commit b2ee442

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

operator/pkg/upgrade/installation.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
clusterv1beta1 "github.com/replicatedhq/embedded-cluster/kinds/apis/v1beta1"
88
"github.com/replicatedhq/embedded-cluster/pkg/kubeutils"
9+
"k8s.io/client-go/util/retry"
910
controllerruntime "sigs.k8s.io/controller-runtime"
1011
"sigs.k8s.io/controller-runtime/pkg/client"
1112
)
@@ -39,16 +40,23 @@ func CreateInstallation(ctx context.Context, cli client.Client, original *cluste
3940

4041
// setInstallationState gets the installation object of the given name and sets the state to the given state.
4142
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+
})
4956
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)
5158
}
59+
5260
return nil
5361
}
5462

0 commit comments

Comments
 (0)