only operate on statefulset level
This commit is contained in:
parent
680d67aab7
commit
11a7ff721b
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/types"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
acidv1 "github.com/zalando/postgres-operator/pkg/apis/acid.zalan.do/v1"
|
acidv1 "github.com/zalando/postgres-operator/pkg/apis/acid.zalan.do/v1"
|
||||||
|
|
@ -35,9 +36,8 @@ func TestSyncStatefulSetsAnnotations(t *testing.T) {
|
||||||
|
|
||||||
pg := acidv1.Postgresql{
|
pg := acidv1.Postgresql{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: clusterName,
|
Name: clusterName,
|
||||||
Namespace: namespace,
|
Namespace: namespace,
|
||||||
Annotations: map[string]string{"test-anno": "true"},
|
|
||||||
},
|
},
|
||||||
Spec: acidv1.PostgresSpec{
|
Spec: acidv1.PostgresSpec{
|
||||||
Volume: acidv1.Volume{
|
Volume: acidv1.Volume{
|
||||||
|
|
@ -68,35 +68,24 @@ func TestSyncStatefulSetsAnnotations(t *testing.T) {
|
||||||
cluster.Name = clusterName
|
cluster.Name = clusterName
|
||||||
cluster.Namespace = namespace
|
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
|
// create a statefulset
|
||||||
sts, err := cluster.createStatefulSet()
|
_, 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{})
|
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// empty annotations on cluster ObjectMeta object as well
|
// patch statefulset and add annotation
|
||||||
cluster.ObjectMeta.Annotations = map[string]string{}
|
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
|
// first compare running with desired statefulset - they should not match
|
||||||
desiredSts, err := cluster.generateStatefulSet(&cluster.Postgresql.Spec)
|
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)
|
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()
|
cluster.syncStatefulSet()
|
||||||
|
|
||||||
// compare them again
|
|
||||||
_, err = cluster.KubeClient.StatefulSets(namespace).Get(context.TODO(), clusterName, metav1.GetOptions{})
|
|
||||||
assert.NoError(t, err)
|
|
||||||
|
|
||||||
cmp = cluster.compareStatefulSetWith(desiredSts)
|
cmp = cluster.compareStatefulSetWith(desiredSts)
|
||||||
if !cmp.match {
|
if !cmp.match {
|
||||||
t.Errorf("%s: current and desired statefulsets are not matching %#v", testName, cmp)
|
t.Errorf("%s: current and desired statefulsets are not matching %#v", testName, cmp)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue