Skip to content

Commit

Permalink
fix conversion/comparison of shared clusters (#1867)
Browse files Browse the repository at this point in the history
  • Loading branch information
helderjs authored Oct 16, 2024
1 parent 6fedb28 commit 756aba9
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
3 changes: 2 additions & 1 deletion internal/translation/deployment/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ func regionConfigAreEqual(desired, current *akov2.AdvancedRegionConfig, autoscal
}

if desired.ProviderName == string(provider.ProviderTenant) {
return desired.BackingProviderName == current.BackingProviderName
return (desired.BackingProviderName == current.BackingProviderName) &&
(desired.ElectableSpecs.InstanceSize == current.ElectableSpecs.InstanceSize)
}

if desired.RegionName != current.RegionName {
Expand Down
44 changes: 44 additions & 0 deletions internal/translation/deployment/compare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,50 @@ func TestSpecAreEqual(t *testing.T) {
},
},
},
"should return false when instance size of shared cluster changed": {
ako: &akov2.AtlasDeployment{
Spec: akov2.AtlasDeploymentSpec{
DeploymentSpec: &akov2.AdvancedDeploymentSpec{
Name: "cluster0",
ClusterType: "REPLICASET",
ReplicationSpecs: []*akov2.AdvancedReplicationSpec{
{
RegionConfigs: []*akov2.AdvancedRegionConfig{
{
ProviderName: "TENANT",
BackingProviderName: "AWS",
RegionName: "US_EAST_1",
ElectableSpecs: &akov2.Specs{
InstanceSize: "M2",
},
},
},
},
},
},
},
},
atlas: &admin.AdvancedClusterDescription{
Name: pointer.MakePtr("cluster0"),
ClusterType: pointer.MakePtr("REPLICASET"),
ReplicationSpecs: &[]admin.ReplicationSpec{
{
NumShards: pointer.MakePtr(1),
RegionConfigs: &[]admin.CloudRegionConfig{
{
ProviderName: pointer.MakePtr("TENANT"),
BackingProviderName: pointer.MakePtr("AWS"),
RegionName: pointer.MakePtr("US_EAST_1"),
ElectableSpecs: &admin.HardwareSpec{
InstanceSize: pointer.MakePtr("M0"),
},
},
},
},
},
},
expected: false,
},
"should return true when cluster are the same": {
ako: &akov2.AtlasDeployment{
Spec: akov2.AtlasDeploymentSpec{
Expand Down
6 changes: 3 additions & 3 deletions internal/translation/deployment/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,8 @@ func labelsFromAtlas(cLabels []admin.ComponentLabel) []common.LabelSpec {
}

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

Expand Down Expand Up @@ -545,7 +545,7 @@ func replicationSpecFromAtlas(replicationSpecs []admin.ReplicationSpec) []*akov2
BackingProviderName: regionConfig.GetBackingProviderName(),
RegionName: regionConfig.GetRegionName(),
Priority: regionConfig.Priority,
ElectableSpecs: hSpecOrDefault(regionConfig.GetElectableSpecs()),
ElectableSpecs: hSpecOrDefault(regionConfig.GetElectableSpecs(), regionConfig.GetProviderName()),
ReadOnlySpecs: dHSpecOrDefault(regionConfig.GetReadOnlySpecs()),
AnalyticsSpecs: dHSpecOrDefault(regionConfig.GetAnalyticsSpecs()),
AutoScaling: autoScalingOrDefault(regionConfig.GetAutoScaling()),
Expand Down

0 comments on commit 756aba9

Please sign in to comment.