Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-1.7] 🌱 Add retry to clusterctl UpgradeWithBinary #11542

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -196,12 +196,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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for i := range upgradeRetries {
for i := 0; i < upgradeRetries; i++ {

Wow, took me some time to remember the old syntax again 😂

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll push this fix

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good thank you!

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
Loading