mirror of
https://github.com/zalando/postgres-operator.git
synced 2026-10-19 04:30:55 +02:00
Custom annotations 329 (#657)
* Add ability for custom annotations to database pods
This commit is contained in:
committed by
Felix Kunde
parent
33e1d60703
commit
535517cd1b
@@ -11,7 +11,7 @@ import (
|
||||
"github.com/zalando/postgres-operator/pkg/util/config"
|
||||
"github.com/zalando/postgres-operator/pkg/util/k8sutil"
|
||||
"github.com/zalando/postgres-operator/pkg/util/teams"
|
||||
"k8s.io/api/core/v1"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -328,3 +328,57 @@ func TestShouldDeleteSecret(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPodAnnotations(t *testing.T) {
|
||||
testName := "TestPodAnnotations"
|
||||
tests := []struct {
|
||||
subTest string
|
||||
operator map[string]string
|
||||
database map[string]string
|
||||
merged map[string]string
|
||||
}{
|
||||
{
|
||||
subTest: "No Annotations",
|
||||
operator: make(map[string]string),
|
||||
database: make(map[string]string),
|
||||
merged: make(map[string]string),
|
||||
},
|
||||
{
|
||||
subTest: "Operator Config Annotations",
|
||||
operator: map[string]string{"foo": "bar"},
|
||||
database: make(map[string]string),
|
||||
merged: map[string]string{"foo": "bar"},
|
||||
},
|
||||
{
|
||||
subTest: "Database Config Annotations",
|
||||
operator: make(map[string]string),
|
||||
database: map[string]string{"foo": "bar"},
|
||||
merged: map[string]string{"foo": "bar"},
|
||||
},
|
||||
{
|
||||
subTest: "Database Config overrides Operator Config Annotations",
|
||||
operator: map[string]string{"foo": "bar", "global": "foo"},
|
||||
database: map[string]string{"foo": "baz", "local": "foo"},
|
||||
merged: map[string]string{"foo": "baz", "global": "foo", "local": "foo"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
cl.OpConfig.CustomPodAnnotations = tt.operator
|
||||
cl.Postgresql.Spec.PodAnnotations = tt.database
|
||||
|
||||
annotations := cl.generatePodAnnotations(&cl.Postgresql.Spec)
|
||||
for k, v := range annotations {
|
||||
if observed, expected := v, tt.merged[k]; observed != expected {
|
||||
t.Errorf("%v expects annotation value %v for key %v, but found %v",
|
||||
testName+"/"+tt.subTest, expected, observed, k)
|
||||
}
|
||||
}
|
||||
for k, v := range tt.merged {
|
||||
if observed, expected := annotations[k], v; observed != expected {
|
||||
t.Errorf("%v expects annotation value %v for key %v, but found %v",
|
||||
testName+"/"+tt.subTest, expected, observed, k)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user