mirror of
https://github.com/zalando/postgres-operator.git
synced 2026-09-30 07:41:36 +02:00
annotation to bypass globally configured instance limits (#1943)
This commit is contained in:
@@ -1343,6 +1343,7 @@ func (c *Cluster) generateStatefulSet(spec *acidv1.PostgresSpec) (*appsv1.Statef
|
||||
return nil, fmt.Errorf("could not generate volume claim template: %v", err)
|
||||
}
|
||||
|
||||
// global minInstances and maxInstances settings can overwrite manifest
|
||||
numberOfInstances := c.getNumberOfInstances(spec)
|
||||
|
||||
// the operator has domain-specific logic on how to do rolling updates of PG clusters
|
||||
@@ -1443,9 +1444,16 @@ func (c *Cluster) generateScalyrSidecarSpec(clusterName, APIKey, serverURL, dock
|
||||
func (c *Cluster) getNumberOfInstances(spec *acidv1.PostgresSpec) int32 {
|
||||
min := c.OpConfig.MinInstances
|
||||
max := c.OpConfig.MaxInstances
|
||||
instanceLimitAnnotationKey := c.OpConfig.IgnoreInstanceLimitsAnnotationKey
|
||||
cur := spec.NumberOfInstances
|
||||
newcur := cur
|
||||
|
||||
if instanceLimitAnnotationKey != "" {
|
||||
if value, exists := c.ObjectMeta.Annotations[instanceLimitAnnotationKey]; exists && value == "true" {
|
||||
return cur
|
||||
}
|
||||
}
|
||||
|
||||
if spec.StandbyCluster != nil {
|
||||
if newcur == 1 {
|
||||
min = newcur
|
||||
|
||||
@@ -864,6 +864,136 @@ func TestGenerateSpiloPodEnvVars(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetNumberOfInstances(t *testing.T) {
|
||||
testName := "TestGetNumberOfInstances"
|
||||
tests := []struct {
|
||||
subTest string
|
||||
config config.Config
|
||||
annotationKey string
|
||||
annotationValue string
|
||||
desired int32
|
||||
provided int32
|
||||
}{
|
||||
{
|
||||
subTest: "no constraints",
|
||||
config: config.Config{
|
||||
Resources: config.Resources{
|
||||
MinInstances: -1,
|
||||
MaxInstances: -1,
|
||||
IgnoreInstanceLimitsAnnotationKey: "",
|
||||
},
|
||||
},
|
||||
annotationKey: "",
|
||||
annotationValue: "",
|
||||
desired: 2,
|
||||
provided: 2,
|
||||
},
|
||||
{
|
||||
subTest: "minInstances defined",
|
||||
config: config.Config{
|
||||
Resources: config.Resources{
|
||||
MinInstances: 2,
|
||||
MaxInstances: -1,
|
||||
IgnoreInstanceLimitsAnnotationKey: "",
|
||||
},
|
||||
},
|
||||
annotationKey: "",
|
||||
annotationValue: "",
|
||||
desired: 1,
|
||||
provided: 2,
|
||||
},
|
||||
{
|
||||
subTest: "maxInstances defined",
|
||||
config: config.Config{
|
||||
Resources: config.Resources{
|
||||
MinInstances: -1,
|
||||
MaxInstances: 5,
|
||||
IgnoreInstanceLimitsAnnotationKey: "",
|
||||
},
|
||||
},
|
||||
annotationKey: "",
|
||||
annotationValue: "",
|
||||
desired: 10,
|
||||
provided: 5,
|
||||
},
|
||||
{
|
||||
subTest: "ignore minInstances",
|
||||
config: config.Config{
|
||||
Resources: config.Resources{
|
||||
MinInstances: 2,
|
||||
MaxInstances: -1,
|
||||
IgnoreInstanceLimitsAnnotationKey: "ignore-instance-limits",
|
||||
},
|
||||
},
|
||||
annotationKey: "ignore-instance-limits",
|
||||
annotationValue: "true",
|
||||
desired: 1,
|
||||
provided: 1,
|
||||
},
|
||||
{
|
||||
subTest: "want to ignore minInstances but wrong key",
|
||||
config: config.Config{
|
||||
Resources: config.Resources{
|
||||
MinInstances: 2,
|
||||
MaxInstances: -1,
|
||||
IgnoreInstanceLimitsAnnotationKey: "ignore-instance-limits",
|
||||
},
|
||||
},
|
||||
annotationKey: "ignoring-instance-limits",
|
||||
annotationValue: "true",
|
||||
desired: 1,
|
||||
provided: 2,
|
||||
},
|
||||
{
|
||||
subTest: "want to ignore minInstances but wrong value",
|
||||
config: config.Config{
|
||||
Resources: config.Resources{
|
||||
MinInstances: 2,
|
||||
MaxInstances: -1,
|
||||
IgnoreInstanceLimitsAnnotationKey: "ignore-instance-limits",
|
||||
},
|
||||
},
|
||||
annotationKey: "ignore-instance-limits",
|
||||
annotationValue: "active",
|
||||
desired: 1,
|
||||
provided: 2,
|
||||
},
|
||||
{
|
||||
subTest: "annotation set but no constraints to ignore",
|
||||
config: config.Config{
|
||||
Resources: config.Resources{
|
||||
MinInstances: -1,
|
||||
MaxInstances: -1,
|
||||
IgnoreInstanceLimitsAnnotationKey: "ignore-instance-limits",
|
||||
},
|
||||
},
|
||||
annotationKey: "ignore-instance-limits",
|
||||
annotationValue: "true",
|
||||
desired: 1,
|
||||
provided: 1,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
var cluster = New(
|
||||
Config{
|
||||
OpConfig: tt.config,
|
||||
}, k8sutil.KubernetesClient{}, acidv1.Postgresql{}, logger, eventRecorder)
|
||||
|
||||
cluster.Spec.NumberOfInstances = tt.desired
|
||||
if tt.annotationKey != "" {
|
||||
cluster.ObjectMeta.Annotations = make(map[string]string)
|
||||
cluster.ObjectMeta.Annotations[tt.annotationKey] = tt.annotationValue
|
||||
}
|
||||
numInstances := cluster.getNumberOfInstances(&cluster.Spec)
|
||||
|
||||
if numInstances != tt.provided {
|
||||
t.Errorf("%s %s: Expected to get %d instances, have %d instead",
|
||||
testName, tt.subTest, tt.provided, numInstances)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCloneEnv(t *testing.T) {
|
||||
testName := "TestCloneEnv"
|
||||
tests := []struct {
|
||||
|
||||
Reference in New Issue
Block a user