Skip to content

Commit

Permalink
Merge pull request #11539 from k8s-infra-cherrypick-robot/cherry-pick…
Browse files Browse the repository at this point in the history
…-11478-to-release-1.9

[release-1.9] 🌱 Add retry to clusterctl `UpgradeWithBinary`
  • Loading branch information
k8s-ci-robot authored Dec 4, 2024
2 parents 6cd5dd3 + 0438a63 commit 35ba6a0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
5 changes: 3 additions & 2 deletions test/framework/clusterctl/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func Upgrade(ctx context.Context, input UpgradeInput) {
}

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

func calculateClusterCtlUpgradeArgs(input UpgradeInput) []string {
Expand Down
21 changes: 18 additions & 3 deletions test/framework/clusterctl/clusterctl_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,27 @@ func UpgradeManagementClusterAndWait(ctx context.Context, input UpgradeManagemen
client := input.ClusterProxy.GetClient()

if input.ClusterctlBinaryPath != "" {
UpgradeWithBinary(ctx, input.ClusterctlBinaryPath, upgradeInput)
clusterctlVersion, err := getClusterCtlVersion(input.ClusterctlBinaryPath)
Expect(err).ToNot(HaveOccurred())
upgradeRetries := 1
// Older versions of clusterctl may need to retry the upgrade process to allow for
// cert-manager CAs to become available before continuing. For newer versions of clusterctl
// this is addressed with https://github.com/kubernetes-sigs/cluster-api/pull/10513
if clusterctlVersion.LT(semver.MustParse("1.7.0")) {
upgradeRetries = 2
}
for i := range upgradeRetries {
err := UpgradeWithBinary(ctx, input.ClusterctlBinaryPath, upgradeInput)
if err != nil && i < upgradeRetries-1 {
log.Logf("Failed to UpgradeWithBinary, retrying: %v", err)
continue
}
Expect(err).ToNot(HaveOccurred())
break
}
// Old versions of clusterctl may deploy CRDs, Mutating- and/or ValidatingWebhookConfigurations
// before creating the new Certificate objects. This check ensures the CA's are up to date before
// continuing.
clusterctlVersion, err := getClusterCtlVersion(input.ClusterctlBinaryPath)
Expect(err).ToNot(HaveOccurred())
if clusterctlVersion.LT(semver.MustParse("1.7.2")) {
Eventually(func() error {
return verifyCAInjection(ctx, client)
Expand Down

0 comments on commit 35ba6a0

Please sign in to comment.