Skip to content

Commit 8dc052e

Browse files
committed
Add observedGeneration field to status of postgresql resource
Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
1 parent fffb532 commit 8dc052e

File tree

5 files changed

+17
-0
lines changed

5 files changed

+17
-0
lines changed

manifests/postgresql.crd.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4189,6 +4189,9 @@ spec:
41894189
properties:
41904190
PostgresClusterStatus:
41914191
type: string
4192+
observedGeneration:
4193+
format: int64
4194+
type: integer
41924195
required:
41934196
- PostgresClusterStatus
41944197
type: object

pkg/apis/acid.zalan.do/v1/postgresql_type.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ type UserFlags []string
301301
// PostgresStatus contains status of the PostgreSQL cluster (running, creation failed etc.)
302302
type PostgresStatus struct {
303303
PostgresClusterStatus string `json:"PostgresClusterStatus"`
304+
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
304305
}
305306

306307
// ConnectionPooler Options for connection pooler

pkg/cluster/cluster.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ func (c *Cluster) Create() (err error) {
275275
currentStatus := c.Status.DeepCopy()
276276
pg := c.Postgresql.DeepCopy()
277277
pg.Status.PostgresClusterStatus = acidv1.ClusterStatusRunning
278+
pg.Status.ObservedGeneration = pgCreateStatus.Generation
278279

279280
if err != nil {
280281
c.logger.Warningf("cluster created failed: %v", err)
@@ -998,6 +999,7 @@ func (c *Cluster) Update(oldSpec, newSpec *acidv1.Postgresql) error {
998999
defer func() {
9991000
currentStatus := newSpec.Status.DeepCopy()
10001001
newSpec.Status.PostgresClusterStatus = acidv1.ClusterStatusRunning
1002+
newSpec.Status.ObservedGeneration = newSpec.Generation
10011003

10021004
if updateFailed {
10031005
newSpec.Status.PostgresClusterStatus = acidv1.ClusterStatusUpdateFailed

pkg/cluster/sync.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ func (c *Cluster) Sync(newSpec *acidv1.Postgresql) error {
4444
c.setSpec(newSpec)
4545

4646
defer func() {
47+
// update observedGeneration to reflect that the latest spec
48+
// was processed
49+
newSpec.Status.ObservedGeneration = newSpec.Generation
4750
if err != nil {
4851
c.logger.Warningf("error while syncing cluster state: %v", err)
4952
newSpec.Status.PostgresClusterStatus = acidv1.ClusterStatusSyncFailed

pkg/cluster/util_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
"github.com/golang/mock/gomock"
1515
"github.com/stretchr/testify/assert"
16+
"github.com/stretchr/testify/require"
1617
"github.com/zalando/postgres-operator/mocks"
1718
acidv1 "github.com/zalando/postgres-operator/pkg/apis/acid.zalan.do/v1"
1819
fakeacidv1 "github.com/zalando/postgres-operator/pkg/generated/clientset/versioned/fake"
@@ -589,9 +590,16 @@ func TestInheritedAnnotations(t *testing.T) {
589590
// + new PVC
590591
cluster.KubeClient.PersistentVolumeClaims(namespace).Create(context.TODO(), &CreatePVCs(namespace, clusterName, filterLabels, 4, "1Gi").Items[3], metav1.CreateOptions{})
591592

593+
newSpec, err = cluster.KubeClient.Postgresqls(namespace).Update(context.TODO(), newSpec, metav1.UpdateOptions{})
594+
assert.NoError(t, err)
595+
596+
generation := newSpec.Generation
597+
592598
err = cluster.Update(cluster.Postgresql.DeepCopy(), newSpec)
593599
assert.NoError(t, err)
594600

601+
require.Equal(t, generation, cluster.Postgresql.Status.ObservedGeneration)
602+
595603
err = checkResourcesInheritedAnnotations(cluster, result)
596604
assert.NoError(t, err)
597605

0 commit comments

Comments
 (0)