From 7e356a15c7a6db594bca76fce19b08de696d17a3 Mon Sep 17 00:00:00 2001 From: Felix Kunde Date: Tue, 9 Apr 2019 12:36:02 +0200 Subject: [PATCH] use subresource when patching new status --- pkg/apis/acid.zalan.do/v1/util_test.go | 2 +- pkg/cluster/cluster.go | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/apis/acid.zalan.do/v1/util_test.go b/pkg/apis/acid.zalan.do/v1/util_test.go index 953772b02..79cfe34d4 100644 --- a/pkg/apis/acid.zalan.do/v1/util_test.go +++ b/pkg/apis/acid.zalan.do/v1/util_test.go @@ -323,7 +323,7 @@ var postgresqlList = []struct { out PostgresqlList err error }{ - {[]byte(`{"apiVersion":"v1","items":[{"apiVersion":"acid.zalan.do/v1","kind":"Postgresql","metadata":{"labels":{"team":"acid"},"name":"acid-testcluster42","namespace":"default","resourceVersion":"30446957","selfLink":"/apis/acid.zalan.do/v1/namespaces/default/postgresqls/acid-testcluster42","uid":"857cd208-33dc-11e7-b20a-0699041e4b03"},"spec":{"allowedSourceRanges":["185.85.220.0/22"],"numberOfInstances":1,"postgresql":{"version":"9.6"},"teamId":"acid","volume":{"size":"10Gi"}},"status":"Running"}],"kind":"List","metadata":{},"resourceVersion":"","selfLink":""}`), + {[]byte(`{"apiVersion":"v1","items":[{"apiVersion":"acid.zalan.do/v1","kind":"Postgresql","metadata":{"labels":{"team":"acid"},"name":"acid-testcluster42","namespace":"default","resourceVersion":"30446957","selfLink":"/apis/acid.zalan.do/v1/namespaces/default/postgresqls/acid-testcluster42","uid":"857cd208-33dc-11e7-b20a-0699041e4b03"},"spec":{"allowedSourceRanges":["185.85.220.0/22"],"numberOfInstances":1,"postgresql":{"version":"9.6"},"teamId":"acid","volume":{"size":"10Gi"}},"status":{"PostgresClusterStatus":"Running"}}],"kind":"List","metadata":{},"resourceVersion":"","selfLink":""}`), PostgresqlList{ TypeMeta: metav1.TypeMeta{ Kind: "List", diff --git a/pkg/cluster/cluster.go b/pkg/cluster/cluster.go index 8b68eb071..52118b9d0 100644 --- a/pkg/cluster/cluster.go +++ b/pkg/cluster/cluster.go @@ -159,11 +159,12 @@ func (c *Cluster) setStatus(status acidv1.PostgresClusterStatus) { c.logger.Errorf("could not marshal status: %v", err) } - patch := []byte(fmt.Sprintf(`{"status":{"PostgresClusterStatus": %s}}`, string(b))) + subresource := fmt.Sprintf(`{"status":{"PostgresClusterStatus": %s}}`, string(b)) + // we cannot do a full scale update here without fetching the previous manifest (as the resourceVersion may differ), // however, we could do patch without it. In the future, once /status subresource is there (starting Kubernets 1.11) // we should take advantage of it. - newspec, err := c.KubeClient.AcidV1ClientSet.AcidV1().Postgresqls(c.clusterNamespace()).Patch(c.Name, types.MergePatchType, patch) + newspec, err := c.KubeClient.AcidV1ClientSet.AcidV1().Postgresqls(c.clusterNamespace()).Patch(c.Name, types.MergePatchType, make([]byte, 0), subresource) if err != nil { c.logger.Errorf("could not update status: %v", err) }