mirror of
https://github.com/zalando/postgres-operator.git
synced 2026-10-05 21:31:59 +02:00
Introduce higher and lower bounds for the number of instances (#178)
* Introduce higher and lower bounds for the number of instances Reduce the number of instances to the min_instances if it is lower and to the max_instances if it is higher. -1 for either of those means there is no lower or upper bound. In addition, terminate the operator when there is a nonsense in the configuration (i.e. max_instances < min_instances). Reviewed by Jan Mußler and Sergey Dudoladov.
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"fmt"
|
||||
"github.com/zalando-incubator/postgres-operator/pkg/spec"
|
||||
)
|
||||
|
||||
@@ -33,6 +34,8 @@ type Resources struct {
|
||||
PodEnvironmentConfigMap string `name:"pod_environment_configmap" default:""`
|
||||
NodeEOLLabel map[string]string `name:"node_eol_label" default:"lifecycle-status:pending-decommission"`
|
||||
NodeReadinessLabel map[string]string `name:"node_readiness_label" default:"lifecycle-status:ready"`
|
||||
MaxInstances int32 `name:"max_instances" default:"-1"`
|
||||
MinInstances int32 `name:"min_instances" default:"-1"`
|
||||
}
|
||||
|
||||
// Auth describes authentication specific configuration parameters
|
||||
@@ -108,6 +111,9 @@ func NewFromMap(m map[string]string) *Config {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
if err := validate(&cfg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return &cfg
|
||||
}
|
||||
@@ -123,3 +129,14 @@ func Copy(c *Config) Config {
|
||||
|
||||
return cfg
|
||||
}
|
||||
|
||||
func validate(cfg *Config) (err error) {
|
||||
if cfg.MinInstances > 0 && cfg.MaxInstances > 0 && cfg.MinInstances > cfg.MaxInstances {
|
||||
err = fmt.Errorf("minimum number of instances %d is set higher than the maximum number %d",
|
||||
cfg.MinInstances, cfg.MaxInstances)
|
||||
}
|
||||
if cfg.Workers == 0 {
|
||||
err = fmt.Errorf("number of workers should be higher than 0")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user