only operate on statefulset level

This commit is contained in:
Felix Kunde 2021-04-13 10:52:26 +02:00
parent 680d67aab7
commit 11a7ff721b
1 changed files with 19 additions and 34 deletions

View File

@ -7,6 +7,7 @@ import (
"context"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"github.com/stretchr/testify/assert"
acidv1 "github.com/zalando/postgres-operator/pkg/apis/acid.zalan.do/v1"
@ -35,9 +36,8 @@ func TestSyncStatefulSetsAnnotations(t *testing.T) {
pg := acidv1.Postgresql{
ObjectMeta: metav1.ObjectMeta{
Name: clusterName,
Namespace: namespace,
Annotations: map[string]string{"test-anno": "true"},
Name: clusterName,
Namespace: namespace,
},
Spec: acidv1.PostgresSpec{
Volume: acidv1.Volume{
@ -68,35 +68,24 @@ func TestSyncStatefulSetsAnnotations(t *testing.T) {
cluster.Name = clusterName
cluster.Namespace = namespace
// create a new Postgresql resource
_, err := cluster.KubeClient.Postgresqls(namespace).Create(
context.TODO(), &pg, metav1.CreateOptions{})
assert.NoError(t, err)
// create a statefulset
sts, err := cluster.createStatefulSet()
assert.NoError(t, err)
cluster.Statefulset = sts
// update postgresql and remove annotation to force sync
newPg := acidv1.Postgresql{
ObjectMeta: metav1.ObjectMeta{
Name: clusterName,
Namespace: namespace,
},
Spec: acidv1.PostgresSpec{
Volume: acidv1.Volume{
Size: "1Gi",
},
},
}
_, err = cluster.KubeClient.Postgresqls(namespace).Update(
context.TODO(), &newPg, metav1.UpdateOptions{})
_, err := cluster.createStatefulSet()
assert.NoError(t, err)
// empty annotations on cluster ObjectMeta object as well
cluster.ObjectMeta.Annotations = map[string]string{}
// patch statefulset and add annotation
patchData, err := metaAnnotationsPatch(map[string]string{"test-anno": "true"})
assert.NoError(t, err)
newSts, err := cluster.KubeClient.StatefulSets(namespace).Patch(
context.TODO(),
clusterName,
types.MergePatchType,
[]byte(patchData),
metav1.PatchOptions{},
"")
assert.NoError(t, err)
cluster.Statefulset = newSts
// first compare running with desired statefulset - they should not match
desiredSts, err := cluster.generateStatefulSet(&cluster.Postgresql.Spec)
@ -107,13 +96,9 @@ func TestSyncStatefulSetsAnnotations(t *testing.T) {
t.Errorf("%s: match between current and desired statefulsets albeit differences: %#v", testName, cmp)
}
// now sync statefulset - the diff should trigger a replacement
// now sync statefulset - the diff should trigger a update
cluster.syncStatefulSet()
// compare them again
_, err = cluster.KubeClient.StatefulSets(namespace).Get(context.TODO(), clusterName, metav1.GetOptions{})
assert.NoError(t, err)
cmp = cluster.compareStatefulSetWith(desiredSts)
if !cmp.match {
t.Errorf("%s: current and desired statefulsets are not matching %#v", testName, cmp)