Skip to content

Commit c48ddd1

Browse files
committed
remove volume size requirement and relax changes on update
1 parent a0b0da3 commit c48ddd1

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

docs/user.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ you can find this example also in the manifests folder:
4040
kubectl create -f manifests/minimal-postgres-manifest.yaml
4141
```
4242

43-
Note, that the minimum volume size to properly run the `postgresql` resource is
44-
`1Gi`. If a lower value is set in the manifest the operator will cancel ADD or
45-
UPDATE events on this resource with an error.
43+
Note, that the minimum volume size to run the `postgresql` resource on Elastic
44+
Block Storage (EBS) is `1Gi`.
4645

4746
## Watch pods being created
4847

pkg/cluster/cluster.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,6 @@ func (c *Cluster) validateResources(spec *acidv1.PostgresSpec) error {
500500
const (
501501
cpuMinLimit = "256m"
502502
memoryMinLimit = "256Mi"
503-
volumeMinSize = "1Gi"
504503
)
505504

506505
var (
@@ -530,15 +529,6 @@ func (c *Cluster) validateResources(spec *acidv1.PostgresSpec) error {
530529
}
531530
}
532531

533-
volumeSize := spec.Volume.Size
534-
isSmaller, err = util.IsSmallerQuantity(volumeSize, volumeMinSize)
535-
if err != nil {
536-
return fmt.Errorf("error validating volume size: %v", err)
537-
}
538-
if isSmaller {
539-
return fmt.Errorf("defined volume size %s is below required minimum %s to properly run postgresql resource", volumeSize, volumeMinSize)
540-
}
541-
542532
return nil
543533
}
544534

@@ -552,6 +542,7 @@ func (c *Cluster) Update(oldSpec, newSpec *acidv1.Postgresql) error {
552542
c.mu.Lock()
553543
defer c.mu.Unlock()
554544

545+
oldStatus := c.Status
555546
c.setStatus(acidv1.ClusterStatusUpdating)
556547
c.setSpec(newSpec)
557548

@@ -563,6 +554,21 @@ func (c *Cluster) Update(oldSpec, newSpec *acidv1.Postgresql) error {
563554
}
564555
}()
565556

557+
// check if pod resources were edited below the enforced minimum limits
558+
if err := c.validateResources(&newSpec.Spec); err != nil {
559+
err = fmt.Errorf("insufficient resource limits specified: %v", err)
560+
561+
isCPULimitSmaller, err2 := util.IsSmallerQuantity(newSpec.Spec.Resources.ResourceLimits.CPU, oldSpec.Spec.Resources.ResourceLimits.CPU)
562+
isMemoryLimitSmaller, err3 := util.IsSmallerQuantity(newSpec.Spec.Resources.ResourceLimits.Memory, oldSpec.Spec.Resources.ResourceLimits.Memory)
563+
564+
if oldStatus.Running() && !isCPULimitSmaller && !isMemoryLimitSmaller && err2 == nil && err3 == nil {
565+
c.logger.Warning(err)
566+
} else {
567+
updateFailed = true
568+
return err
569+
}
570+
}
571+
566572
if oldSpec.Spec.PgVersion != newSpec.Spec.PgVersion { // PG versions comparison
567573
c.logger.Warningf("postgresql version change(%q -> %q) has no effect", oldSpec.Spec.PgVersion, newSpec.Spec.PgVersion)
568574
//we need that hack to generate statefulset with the old version
@@ -595,12 +601,6 @@ func (c *Cluster) Update(oldSpec, newSpec *acidv1.Postgresql) error {
595601
}
596602
}
597603

598-
// check pod resources and volume size and cancel update if they are too low
599-
if err := c.validateResources(&c.Spec); err != nil {
600-
updateFailed = true
601-
return fmt.Errorf("insufficient resource limits specified: %v", err)
602-
}
603-
604604
// Volume
605605
if oldSpec.Spec.Size != newSpec.Spec.Size {
606606
c.logger.Debugf("syncing persistent volumes")

0 commit comments

Comments
 (0)