Skip to content

Commit 85b9dcf

Browse files
CLOUDP-130483: Fixed diskSizeGB decreasing (#634)
Fixed diskSizeGB decreasing functionality
1 parent a1c133d commit 85b9dcf

File tree

3 files changed

+63
-1
lines changed

3 files changed

+63
-1
lines changed

pkg/api/v1/atlasdeployment_types.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,26 @@ func (c *AtlasDeployment) WithBackupScheduleRef(ref common.ResourceRefNamespaced
605605
return c
606606
}
607607

608+
func (c *AtlasDeployment) WithDiskSizeGB(size int) *AtlasDeployment {
609+
c.Spec.DeploymentSpec.DiskSizeGB = &size
610+
return c
611+
}
612+
613+
func (c *AtlasDeployment) WithAutoscalingDisabled() *AtlasDeployment {
614+
f := false
615+
c.Spec.DeploymentSpec.AutoScaling = &AutoScalingSpec{
616+
AutoIndexingEnabled: &f,
617+
DiskGBEnabled: &f,
618+
Compute: &ComputeSpec{
619+
Enabled: &f,
620+
ScaleDownEnabled: &f,
621+
MinInstanceSize: "",
622+
MaxInstanceSize: "",
623+
},
624+
}
625+
return c
626+
}
627+
608628
func (c *AtlasDeployment) WithInstanceSize(name string) *AtlasDeployment {
609629
c.Spec.DeploymentSpec.ProviderSettings.InstanceSizeName = name
610630
return c

pkg/controller/atlasdeployment/deployment.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,17 @@ func removeOutdatedFields(removeFrom *mongodbatlas.Cluster, lookAt *mongodbatlas
131131
if *lookAt.AutoScaling.Compute.Enabled {
132132
result.ProviderSettings.InstanceSizeName = ""
133133
} else {
134+
if result.ProviderSettings == nil {
135+
result.ProviderSettings = &mongodbatlas.ProviderSettings{}
136+
}
137+
if result.ProviderSettings.AutoScaling == nil {
138+
result.ProviderSettings.AutoScaling = &mongodbatlas.AutoScaling{}
139+
}
134140
result.ProviderSettings.AutoScaling.Compute = &mongodbatlas.Compute{}
135141
}
142+
}
136143

144+
if lookAt.AutoScaling != nil {
137145
if lookAt.AutoScaling.DiskGBEnabled != nil && *lookAt.AutoScaling.DiskGBEnabled {
138146
result.DiskSizeGB = nil
139147
}

test/int/deployment_test.go

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,8 +460,42 @@ var _ = Describe("AtlasDeployment", Label("int", "AtlasDeployment"), func() {
460460
})
461461
})
462462

463+
It("Should Success (AWS) with enabled autoscaling", func() {
464+
createdDeployment = mdbv1.DefaultAWSDeployment(namespace.Name, createdProject.Name)
465+
createdDeployment.Spec.DeploymentSpec.DiskSizeGB = intptr(20)
466+
createdDeployment.Spec.DeploymentSpec.AutoScaling = &mdbv1.AutoScalingSpec{
467+
AutoIndexingEnabled: boolptr(true),
468+
DiskGBEnabled: boolptr(true),
469+
}
470+
471+
By(fmt.Sprintf("Creating the Deployment %s with autoscaling", kube.ObjectKeyFromObject(createdDeployment)), func() {
472+
Expect(k8sClient.Create(context.Background(), createdDeployment)).ToNot(HaveOccurred())
473+
474+
Eventually(testutil.WaitFor(k8sClient, createdDeployment, status.TrueCondition(status.ReadyType), validateDeploymentCreatingFunc()),
475+
DeploymentUpdateTimeout, interval).Should(BeTrue())
476+
477+
doRegularDeploymentStatusChecks()
478+
checkAtlasState()
479+
})
480+
481+
By("Decreasing the Deployment disk size should not take effect", func() {
482+
prevDiskSize := *createdDeployment.Spec.DeploymentSpec.DiskSizeGB
483+
createdDeployment.Spec.DeploymentSpec.DiskSizeGB = intptr(14)
484+
performUpdate(30 * time.Minute)
485+
doRegularDeploymentStatusChecks()
486+
checkAtlasState(func(c *mongodbatlas.Cluster) {
487+
Expect(*c.DiskSizeGB).To(BeEquivalentTo(prevDiskSize))
488+
489+
// check whether https://github.com/mongodb/go-client-mongodb-atlas/issues/140 is fixed
490+
Expect(c.DiskSizeGB).To(BeAssignableToTypeOf(float64ptr(0)), "DiskSizeGB is no longer a *float64, please check the spec!")
491+
})
492+
})
493+
})
494+
463495
It("Should Succeed (AWS)", func() {
464496
createdDeployment = mdbv1.DefaultAWSDeployment(namespace.Name, createdProject.Name)
497+
createdDeployment.Spec.DeploymentSpec.DiskSizeGB = intptr(20)
498+
createdDeployment = createdDeployment.WithAutoscalingDisabled()
465499

466500
By(fmt.Sprintf("Creating the Deployment %s", kube.ObjectKeyFromObject(createdDeployment)), func() {
467501
Expect(k8sClient.Create(context.Background(), createdDeployment)).ToNot(HaveOccurred())
@@ -490,7 +524,7 @@ var _ = Describe("AtlasDeployment", Label("int", "AtlasDeployment"), func() {
490524
})
491525

492526
By("Decreasing the Deployment disk size", func() {
493-
createdDeployment.Spec.DeploymentSpec.DiskSizeGB = intptr(10)
527+
createdDeployment.Spec.DeploymentSpec.DiskSizeGB = intptr(15)
494528
performUpdate(20 * time.Minute)
495529
doRegularDeploymentStatusChecks()
496530
checkAtlasState(func(c *mongodbatlas.Cluster) {

0 commit comments

Comments
 (0)