Skip to content

Commit c74b50b

Browse files
authored
refactor: use providerName to retry when the upgrade is not completed (#3148)
1 parent 62e1a9a commit c74b50b

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

internal/service/advancedclustertpf/common.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,15 @@ func GenerateFCVPinningWarningForRead(fcvPresentInState bool, apiRespFCVExpirati
7676
}
7777

7878
func IsFlex(replicationSpecs *[]admin.ReplicationSpec20240805) bool {
79+
return getProviderName(replicationSpecs) == flexcluster.FlexClusterType
80+
}
81+
82+
func getProviderName(replicationSpecs *[]admin.ReplicationSpec20240805) string {
7983
regionConfig := getRegionConfig(replicationSpecs)
8084
if regionConfig == nil {
81-
return false
85+
return ""
8286
}
83-
return regionConfig.GetProviderName() == flexcluster.FlexClusterType
87+
return regionConfig.GetProviderName()
8488
}
8589

8690
func getRegionConfig(replicationSpecs *[]admin.ReplicationSpec20240805) *admin.CloudRegionConfig20240805 {

internal/service/advancedclustertpf/common_admin_sdk.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func UpgradeTenant(ctx context.Context, diags *diag.Diagnostics, client *config.
128128
addErrorDiag(diags, operationTenantUpgrade, defaultAPIErrorDetails(waitParams.ClusterName, err))
129129
return nil
130130
}
131-
return AwaitChanges(ctx, client, waitParams, operationTenantUpgrade, diags)
131+
return AwaitChangesUpgrade(ctx, client, waitParams, operationTenantUpgrade, diags)
132132
}
133133

134134
func UpgradeFlexToDedicated(ctx context.Context, diags *diag.Diagnostics, client *config.MongoDBClient, waitParams *ClusterWaitParams, req *admin.AtlasTenantClusterUpgradeRequest20240805) *admin.ClusterDescription20240805 {
@@ -137,7 +137,7 @@ func UpgradeFlexToDedicated(ctx context.Context, diags *diag.Diagnostics, client
137137
addErrorDiag(diags, operationFlexUpgrade, defaultAPIErrorDetails(waitParams.ClusterName, err))
138138
return nil
139139
}
140-
return AwaitChanges(ctx, client, waitParams, operationFlexUpgrade, diags)
140+
return AwaitChangesUpgrade(ctx, client, waitParams, operationFlexUpgrade, diags)
141141
}
142142

143143
func PinFCV(ctx context.Context, api admin.ClustersApi, projectID, clusterName, expirationDateStr string) error {

internal/service/advancedclustertpf/common_await_changes.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@ import (
1010
"go.mongodb.org/atlas-sdk/v20250219001/admin"
1111

1212
"github.com/hashicorp/terraform-plugin-framework/diag"
13+
"github.com/hashicorp/terraform-plugin-log/tflog"
1314
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
1415

16+
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/constant"
1517
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/retrystrategy"
1618
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate"
1719
"github.com/mongodb/terraform-provider-mongodbatlas/internal/config"
20+
"github.com/mongodb/terraform-provider-mongodbatlas/internal/service/flexcluster"
1821
)
1922

2023
var (
@@ -30,6 +33,19 @@ type ClusterWaitParams struct {
3033
IsDelete bool
3134
}
3235

36+
func AwaitChangesUpgrade(ctx context.Context, client *config.MongoDBClient, waitParams *ClusterWaitParams, errorLocator string, diags *diag.Diagnostics) *admin.ClusterDescription20240805 {
37+
upgraded := AwaitChanges(ctx, client, waitParams, errorLocator, diags)
38+
if diags.HasError() || upgraded == nil {
39+
return nil
40+
}
41+
providerName := getProviderName(upgraded.ReplicationSpecs)
42+
if slices.Contains([]string{flexcluster.FlexClusterType, constant.TENANT}, providerName) {
43+
tflog.Warn(ctx, fmt.Sprintf("cluster upgrade unexpected provider %s, retrying", providerName))
44+
return AwaitChanges(ctx, client, waitParams, errorLocator, diags)
45+
}
46+
return upgraded
47+
}
48+
3349
func AwaitChanges(ctx context.Context, client *config.MongoDBClient, waitParams *ClusterWaitParams, errorLocator string, diags *diag.Diagnostics) *admin.ClusterDescription20240805 {
3450
api := client.AtlasV2.ClustersApi
3551
targetState := retrystrategy.RetryStrategyIdleState

0 commit comments

Comments
 (0)