Skip to content

Commit 21afe33

Browse files
authored
CLOUDP-320196: fix skew detection for disabled compute autoscaling (#2347)
* fix skew detection for disabled compute autoscaling * fix skew detection for autoscaling disksizeGB as well * fix linter
1 parent 6c697a6 commit 21afe33

File tree

3 files changed

+125
-2
lines changed

3 files changed

+125
-2
lines changed

internal/controller/atlasdeployment/advanced_deployment_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,7 @@ func TestHandleAdvancedDeployment(t *testing.T) {
551551
},
552552
},
553553
},
554+
//nolint:dupl
554555
deploymentInAtlas: &deployment.Cluster{
555556
ProjectID: "project-id",
556557
State: "IDLE",
@@ -577,6 +578,14 @@ func TestHandleAdvancedDeployment(t *testing.T) {
577578
InstanceSize: "M10",
578579
NodeCount: pointer.MakePtr(3),
579580
},
581+
AutoScaling: &akov2.AdvancedAutoScalingSpec{
582+
Compute: &akov2.ComputeSpec{
583+
Enabled: pointer.MakePtr(false),
584+
},
585+
DiskGB: &akov2.DiskGB{
586+
Enabled: pointer.MakePtr(false),
587+
},
588+
},
580589
},
581590
},
582591
},
@@ -634,6 +643,7 @@ func TestHandleAdvancedDeployment(t *testing.T) {
634643
},
635644
},
636645
},
646+
//nolint:dupl
637647
deploymentInAtlas: &deployment.Cluster{
638648
ProjectID: "project-id",
639649
State: "IDLE",
@@ -660,6 +670,14 @@ func TestHandleAdvancedDeployment(t *testing.T) {
660670
InstanceSize: "M10",
661671
NodeCount: pointer.MakePtr(3),
662672
},
673+
AutoScaling: &akov2.AdvancedAutoScalingSpec{
674+
Compute: &akov2.ComputeSpec{
675+
Enabled: pointer.MakePtr(false),
676+
},
677+
DiskGB: &akov2.DiskGB{
678+
Enabled: pointer.MakePtr(false),
679+
},
680+
},
663681
},
664682
},
665683
},

internal/translation/deployment/conversion.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,21 @@ func normalizeRegionConfigs(regionConfigs []*akov2.AdvancedRegionConfig, isTenan
426426
regionConfig.AutoScaling.Compute.Enabled == nil || !*regionConfig.AutoScaling.Compute.Enabled
427427
diskUnsetOrDisabled := regionConfig.AutoScaling == nil || regionConfig.AutoScaling.DiskGB == nil ||
428428
regionConfig.AutoScaling.DiskGB.Enabled == nil || !*regionConfig.AutoScaling.DiskGB.Enabled
429-
if computeUnsetOrDisabled && diskUnsetOrDisabled {
430-
regionConfig.AutoScaling = nil
429+
430+
if regionConfig.AutoScaling == nil {
431+
regionConfig.AutoScaling = &akov2.AdvancedAutoScalingSpec{}
432+
}
433+
434+
if computeUnsetOrDisabled {
435+
regionConfig.AutoScaling.Compute = &akov2.ComputeSpec{
436+
Enabled: pointer.MakePtr(false),
437+
}
438+
}
439+
440+
if diskUnsetOrDisabled {
441+
regionConfig.AutoScaling.DiskGB = &akov2.DiskGB{
442+
Enabled: pointer.MakePtr(false),
443+
}
431444
}
432445
}
433446
}

internal/translation/deployment/conversion_test.go

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,14 @@ func TestNewDeployment(t *testing.T) {
200200
InstanceSize: "M10",
201201
NodeCount: pointer.MakePtr(3),
202202
},
203+
AutoScaling: &akov2.AdvancedAutoScalingSpec{
204+
Compute: &akov2.ComputeSpec{
205+
Enabled: pointer.MakePtr(false),
206+
},
207+
DiskGB: &akov2.DiskGB{
208+
Enabled: pointer.MakePtr(false),
209+
},
210+
},
203211
},
204212
},
205213
},
@@ -547,6 +555,14 @@ func TestNormalizeClusterDeployment(t *testing.T) {
547555
AnalyticsSpecs: nil,
548556
ElectableSpecs: nil,
549557
ReadOnlySpecs: nil,
558+
AutoScaling: &akov2.AdvancedAutoScalingSpec{
559+
Compute: &akov2.ComputeSpec{
560+
Enabled: pointer.MakePtr(false),
561+
},
562+
DiskGB: &akov2.DiskGB{
563+
Enabled: pointer.MakePtr(false),
564+
},
565+
},
550566
},
551567
},
552568
},
@@ -591,6 +607,74 @@ func TestNormalizeClusterDeployment(t *testing.T) {
591607
AnalyticsSpecs: nil,
592608
ElectableSpecs: nil,
593609
ReadOnlySpecs: nil,
610+
AutoScaling: &akov2.AdvancedAutoScalingSpec{
611+
Compute: &akov2.ComputeSpec{
612+
Enabled: pointer.MakePtr(false),
613+
},
614+
DiskGB: &akov2.DiskGB{
615+
Enabled: pointer.MakePtr(false),
616+
},
617+
},
618+
},
619+
},
620+
},
621+
},
622+
},
623+
},
624+
},
625+
"regionconfig specs with autoscaling": {
626+
deployment: &Cluster{
627+
AdvancedDeploymentSpec: &akov2.AdvancedDeploymentSpec{
628+
ReplicationSpecs: []*akov2.AdvancedReplicationSpec{
629+
{
630+
RegionConfigs: []*akov2.AdvancedRegionConfig{
631+
{
632+
AnalyticsSpecs: &akov2.Specs{},
633+
ElectableSpecs: &akov2.Specs{},
634+
ReadOnlySpecs: &akov2.Specs{},
635+
AutoScaling: &akov2.AdvancedAutoScalingSpec{
636+
Compute: &akov2.ComputeSpec{
637+
Enabled: pointer.MakePtr(false),
638+
ScaleDownEnabled: pointer.MakePtr(false),
639+
MinInstanceSize: "M10",
640+
MaxInstanceSize: "M10",
641+
},
642+
},
643+
},
644+
},
645+
},
646+
},
647+
},
648+
},
649+
expected: &Cluster{
650+
AdvancedDeploymentSpec: &akov2.AdvancedDeploymentSpec{
651+
ClusterType: "REPLICASET",
652+
EncryptionAtRestProvider: "NONE",
653+
MongoDBMajorVersion: "7.0",
654+
VersionReleaseSystem: "LTS",
655+
Paused: pointer.MakePtr(false),
656+
PitEnabled: pointer.MakePtr(false),
657+
RootCertType: "ISRGROOTX1",
658+
BackupEnabled: pointer.MakePtr(false),
659+
Tags: []*akov2.TagSpec{},
660+
661+
ReplicationSpecs: []*akov2.AdvancedReplicationSpec{
662+
{
663+
NumShards: 1,
664+
ZoneName: "Zone 1",
665+
RegionConfigs: []*akov2.AdvancedRegionConfig{
666+
{
667+
AnalyticsSpecs: nil,
668+
ElectableSpecs: nil,
669+
ReadOnlySpecs: nil,
670+
AutoScaling: &akov2.AdvancedAutoScalingSpec{
671+
Compute: &akov2.ComputeSpec{
672+
Enabled: pointer.MakePtr(false),
673+
},
674+
DiskGB: &akov2.DiskGB{
675+
Enabled: pointer.MakePtr(false),
676+
},
677+
},
594678
},
595679
},
596680
},
@@ -690,6 +774,14 @@ func TestNormalizeClusterDeployment(t *testing.T) {
690774
InstanceSize: "M10",
691775
NodeCount: pointer.MakePtr(3),
692776
},
777+
AutoScaling: &akov2.AdvancedAutoScalingSpec{
778+
Compute: &akov2.ComputeSpec{
779+
Enabled: pointer.MakePtr(false),
780+
},
781+
DiskGB: &akov2.DiskGB{
782+
Enabled: pointer.MakePtr(false),
783+
},
784+
},
693785
},
694786
},
695787
},

0 commit comments

Comments
 (0)