Skip to content

Commit 2a351f6

Browse files
k8s-infra-cherrypick-robotcahillsfchrischdi
authored
[release-1.7] 🌱 Add retry to clusterctl UpgradeWithBinary (#11542)
* seedling: Add retry to clusterctl `UpgradeWithBinary` * fix for go 1.21 --------- Co-authored-by: Stephen Cahill <[email protected]> Co-authored-by: Christian Schlotter <[email protected]>
1 parent 94e7810 commit 2a351f6

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
@@ -196,12 +196,27 @@ func UpgradeManagementClusterAndWait(ctx context.Context, input UpgradeManagemen
196196
client := input.ClusterProxy.GetClient()
197197

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

0 commit comments

Comments
 (0)