only operate on statefulset level
This commit is contained in:
parent
680d67aab7
commit
11a7ff721b
|
|
@ -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"
|
||||
|
|
@ -37,7 +38,6 @@ func TestSyncStatefulSetsAnnotations(t *testing.T) {
|
|||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: clusterName,
|
||||
Namespace: namespace,
|
||||
Annotations: map[string]string{"test-anno": "true"},
|
||||
},
|
||||
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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue