Skip to content

Commit 756aba9

Browse files
authored
fix conversion/comparison of shared clusters (#1867)
1 parent 6fedb28 commit 756aba9

File tree

3 files changed

+49
-4
lines changed

3 files changed

+49
-4
lines changed

internal/translation/deployment/compare.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ func regionConfigAreEqual(desired, current *akov2.AdvancedRegionConfig, autoscal
202202
}
203203

204204
if desired.ProviderName == string(provider.ProviderTenant) {
205-
return desired.BackingProviderName == current.BackingProviderName
205+
return (desired.BackingProviderName == current.BackingProviderName) &&
206+
(desired.ElectableSpecs.InstanceSize == current.ElectableSpecs.InstanceSize)
206207
}
207208

208209
if desired.RegionName != current.RegionName {

internal/translation/deployment/compare_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,50 @@ func TestSpecAreEqual(t *testing.T) {
829829
},
830830
},
831831
},
832+
"should return false when instance size of shared cluster changed": {
833+
ako: &akov2.AtlasDeployment{
834+
Spec: akov2.AtlasDeploymentSpec{
835+
DeploymentSpec: &akov2.AdvancedDeploymentSpec{
836+
Name: "cluster0",
837+
ClusterType: "REPLICASET",
838+
ReplicationSpecs: []*akov2.AdvancedReplicationSpec{
839+
{
840+
RegionConfigs: []*akov2.AdvancedRegionConfig{
841+
{
842+
ProviderName: "TENANT",
843+
BackingProviderName: "AWS",
844+
RegionName: "US_EAST_1",
845+
ElectableSpecs: &akov2.Specs{
846+
InstanceSize: "M2",
847+
},
848+
},
849+
},
850+
},
851+
},
852+
},
853+
},
854+
},
855+
atlas: &admin.AdvancedClusterDescription{
856+
Name: pointer.MakePtr("cluster0"),
857+
ClusterType: pointer.MakePtr("REPLICASET"),
858+
ReplicationSpecs: &[]admin.ReplicationSpec{
859+
{
860+
NumShards: pointer.MakePtr(1),
861+
RegionConfigs: &[]admin.CloudRegionConfig{
862+
{
863+
ProviderName: pointer.MakePtr("TENANT"),
864+
BackingProviderName: pointer.MakePtr("AWS"),
865+
RegionName: pointer.MakePtr("US_EAST_1"),
866+
ElectableSpecs: &admin.HardwareSpec{
867+
InstanceSize: pointer.MakePtr("M0"),
868+
},
869+
},
870+
},
871+
},
872+
},
873+
},
874+
expected: false,
875+
},
832876
"should return true when cluster are the same": {
833877
ako: &akov2.AtlasDeployment{
834878
Spec: akov2.AtlasDeploymentSpec{

internal/translation/deployment/conversion.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,8 @@ func labelsFromAtlas(cLabels []admin.ComponentLabel) []common.LabelSpec {
483483
}
484484

485485
func replicationSpecFromAtlas(replicationSpecs []admin.ReplicationSpec) []*akov2.AdvancedReplicationSpec {
486-
hSpecOrDefault := func(spec admin.HardwareSpec) *akov2.Specs {
487-
if spec.GetNodeCount() == 0 {
486+
hSpecOrDefault := func(spec admin.HardwareSpec, providerName string) *akov2.Specs {
487+
if spec.GetNodeCount() == 0 && providerName != string(provider.ProviderTenant) {
488488
return nil
489489
}
490490

@@ -545,7 +545,7 @@ func replicationSpecFromAtlas(replicationSpecs []admin.ReplicationSpec) []*akov2
545545
BackingProviderName: regionConfig.GetBackingProviderName(),
546546
RegionName: regionConfig.GetRegionName(),
547547
Priority: regionConfig.Priority,
548-
ElectableSpecs: hSpecOrDefault(regionConfig.GetElectableSpecs()),
548+
ElectableSpecs: hSpecOrDefault(regionConfig.GetElectableSpecs(), regionConfig.GetProviderName()),
549549
ReadOnlySpecs: dHSpecOrDefault(regionConfig.GetReadOnlySpecs()),
550550
AnalyticsSpecs: dHSpecOrDefault(regionConfig.GetAnalyticsSpecs()),
551551
AutoScaling: autoScalingOrDefault(regionConfig.GetAutoScaling()),

0 commit comments

Comments
 (0)