Skip to content

Commit 2c9caab

Browse files
committed
🌱 Add retry to clusterctl UpgradeWithBinary
1 parent 7a7ba01 commit 2c9caab

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

test/framework/clusterctl/client.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ func Upgrade(ctx context.Context, input UpgradeInput) {
203203
}
204204

205205
// UpgradeWithBinary calls clusterctl upgrade apply with the list of providers defined in the local repository.
206-
func UpgradeWithBinary(ctx context.Context, binary string, input UpgradeInput) {
206+
func UpgradeWithBinary(ctx context.Context, binary string, input UpgradeInput) error {
207207
if len(input.ClusterctlVariables) > 0 {
208208
outputPath := filepath.Join(filepath.Dir(input.ClusterctlConfigPath), fmt.Sprintf("clusterctl-upgrade-config-%s.yaml", input.ClusterName))
209209
Expect(CopyAndAmendClusterctlConfig(ctx, CopyAndAmendClusterctlConfigInput{
@@ -227,8 +227,9 @@ func UpgradeWithBinary(ctx context.Context, binary string, input UpgradeInput) {
227227
if errors.As(err, &exitErr) {
228228
stdErr = string(exitErr.Stderr)
229229
}
230+
return fmt.Errorf("failed to run clusterctl upgrade apply:\nstdout:\n%s\nstderr:\n%s", string(out), stdErr)
230231
}
231-
Expect(err).ToNot(HaveOccurred(), "failed to run clusterctl upgrade apply:\nstdout:\n%s\nstderr:\n%s", string(out), stdErr)
232+
return nil
232233
}
233234

234235
func calculateClusterCtlUpgradeArgs(input UpgradeInput) []string {

test/framework/clusterctl/clusterctl_helpers.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,27 @@ func UpgradeManagementClusterAndWait(ctx context.Context, input UpgradeManagemen
197197
client := input.ClusterProxy.GetClient()
198198

199199
if input.ClusterctlBinaryPath != "" {
200-
UpgradeWithBinary(ctx, input.ClusterctlBinaryPath, upgradeInput)
200+
clusterctlVersion, err := getClusterCtlVersion(input.ClusterctlBinaryPath)
201+
Expect(err).ToNot(HaveOccurred())
202+
upgradeRetries := 1
203+
// Older versions of clusterctl may need to retry the upgrade process to allow for
204+
// cert-manager CAs to become available before continuing. For newer versions of clusterctl
205+
// this is addressed with https://github.com/kubernetes-sigs/cluster-api/pull/10513
206+
if clusterctlVersion.LT(semver.MustParse("1.7.0")) {
207+
upgradeRetries = 2
208+
}
209+
for i := range upgradeRetries {
210+
err := UpgradeWithBinary(ctx, input.ClusterctlBinaryPath, upgradeInput)
211+
if err != nil && i < upgradeRetries-1 {
212+
log.Logf("Failed to UpgradeWithBinary, retrying: %v", err)
213+
continue
214+
}
215+
Expect(err).ToNot(HaveOccurred())
216+
break
217+
}
201218
// Old versions of clusterctl may deploy CRDs, Mutating- and/or ValidatingWebhookConfigurations
202219
// before creating the new Certificate objects. This check ensures the CA's are up to date before
203220
// continuing.
204-
clusterctlVersion, err := getClusterCtlVersion(input.ClusterctlBinaryPath)
205-
Expect(err).ToNot(HaveOccurred())
206221
if clusterctlVersion.LT(semver.MustParse("1.7.2")) {
207222
Eventually(func() error {
208223
return verifyCAInjection(ctx, client)

0 commit comments

Comments
 (0)