From 3887938ab9d4e8e1bb80961804cfad20ef996cdd Mon Sep 17 00:00:00 2001
From: Felix Kunde <felix-kunde@gmx.de>
Date: Wed, 3 Apr 2019 17:33:56 +0200
Subject: [PATCH] change name of status field

---
 pkg/apis/acid.zalan.do/v1/marshal.go         |  6 ++--
 pkg/apis/acid.zalan.do/v1/postgresql_type.go |  6 ++--
 pkg/apis/acid.zalan.do/v1/util.go            | 12 +++----
 pkg/apis/acid.zalan.do/v1/util_test.go       | 12 +++----
 pkg/cluster/cluster.go                       | 36 ++++++++++----------
 pkg/cluster/sync.go                          |  6 ++--
 pkg/cluster/types.go                         | 10 +++---
 pkg/controller/logs_and_api.go               |  2 +-
 pkg/controller/postgresql.go                 |  2 +-
 9 files changed, 46 insertions(+), 46 deletions(-)

diff --git a/pkg/apis/acid.zalan.do/v1/marshal.go b/pkg/apis/acid.zalan.do/v1/marshal.go
index 823ff0ef..d53db029 100644
--- a/pkg/apis/acid.zalan.do/v1/marshal.go
+++ b/pkg/apis/acid.zalan.do/v1/marshal.go
@@ -81,7 +81,7 @@ func (p *Postgresql) UnmarshalJSON(data []byte) error {
 		}
 
 		tmp.Error = err.Error()
-		tmp.Status = ClusterStatusInvalid
+		tmp.PostgresClusterStatus = ClusterStatusInvalid
 
 		*p = Postgresql(tmp)
 
@@ -91,10 +91,10 @@ func (p *Postgresql) UnmarshalJSON(data []byte) error {
 
 	if clusterName, err := extractClusterName(tmp2.ObjectMeta.Name, tmp2.Spec.TeamID); err != nil {
 		tmp2.Error = err.Error()
-		tmp2.Status = ClusterStatusInvalid
+		tmp2.PostgresClusterStatus = ClusterStatusInvalid
 	} else if err := validateCloneClusterDescription(&tmp2.Spec.Clone); err != nil {
 		tmp2.Error = err.Error()
-		tmp2.Status = ClusterStatusInvalid
+		tmp2.PostgresClusterStatus = ClusterStatusInvalid
 	} else {
 		tmp2.Spec.ClusterName = clusterName
 	}
diff --git a/pkg/apis/acid.zalan.do/v1/postgresql_type.go b/pkg/apis/acid.zalan.do/v1/postgresql_type.go
index ccd7fe08..3f669a8d 100644
--- a/pkg/apis/acid.zalan.do/v1/postgresql_type.go
+++ b/pkg/apis/acid.zalan.do/v1/postgresql_type.go
@@ -15,9 +15,9 @@ type Postgresql struct {
 	metav1.TypeMeta   `json:",inline"`
 	metav1.ObjectMeta `json:"metadata,omitempty"`
 
-	Spec   PostgresSpec   `json:"spec"`
-	Status PostgresStatus `json:"status,omitempty"`
-	Error  string         `json:"-"`
+	Spec                  PostgresSpec   `json:"spec"`
+	PostgresClusterStatus PostgresStatus `json:"status,omitempty"`
+	Error                 string         `json:"-"`
 }
 
 // PostgresSpec defines the specification for the PostgreSQL TPR.
diff --git a/pkg/apis/acid.zalan.do/v1/util.go b/pkg/apis/acid.zalan.do/v1/util.go
index 0a326797..6e0a9d86 100644
--- a/pkg/apis/acid.zalan.do/v1/util.go
+++ b/pkg/apis/acid.zalan.do/v1/util.go
@@ -85,12 +85,12 @@ func validateCloneClusterDescription(clone *CloneDescription) error {
 }
 
 // Success of the current Status
-func (status PostgresStatus) Success() bool {
-	return status != ClusterStatusAddFailed &&
-		status != ClusterStatusUpdateFailed &&
-		status != ClusterStatusSyncFailed
+func (postgresClusterStatus PostgresStatus) Success() bool {
+	return postgresClusterStatus != ClusterStatusAddFailed &&
+		postgresClusterStatus != ClusterStatusUpdateFailed &&
+		postgresClusterStatus != ClusterStatusSyncFailed
 }
 
-func (status PostgresStatus) String() string {
-	return string(status)
+func (postgresClusterStatus PostgresStatus) String() string {
+	return string(postgresClusterStatus)
 }
diff --git a/pkg/apis/acid.zalan.do/v1/util_test.go b/pkg/apis/acid.zalan.do/v1/util_test.go
index 01be31e8..cb5e1298 100644
--- a/pkg/apis/acid.zalan.do/v1/util_test.go
+++ b/pkg/apis/acid.zalan.do/v1/util_test.go
@@ -128,7 +128,7 @@ var unmarshalCluster = []struct {
 		ObjectMeta: metav1.ObjectMeta{
 			Name: "acid-testcluster1",
 		},
-		Status: ClusterStatusInvalid,
+		PostgresClusterStatus: ClusterStatusInvalid,
 		// This error message can vary between Go versions, so compute it for the current version.
 		Error: json.Unmarshal([]byte(`{"teamId": 0}`), &PostgresSpec{}).Error(),
 	},
@@ -284,9 +284,9 @@ var unmarshalCluster = []struct {
 			ObjectMeta: metav1.ObjectMeta{
 				Name: "teapot-testcluster1",
 			},
-			Spec:   PostgresSpec{TeamID: "acid"},
-			Status: ClusterStatusInvalid,
-			Error:  errors.New("name must match {TEAM}-{NAME} format").Error(),
+			Spec:                  PostgresSpec{TeamID: "acid"},
+			PostgresClusterStatus: ClusterStatusInvalid,
+			Error:                 errors.New("name must match {TEAM}-{NAME} format").Error(),
 		},
 		[]byte(`{"kind":"Postgresql","apiVersion":"acid.zalan.do/v1","metadata":{"name":"teapot-testcluster1","creationTimestamp":null},"spec":{"postgresql":{"version":"","parameters":null},"volume":{"size":"","storageClass":""},"patroni":{"initdb":null,"pg_hba":null,"ttl":0,"loop_wait":0,"retry_timeout":0,"maximum_lag_on_failover":0,"slots":null},"resources":{"requests":{"cpu":"","memory":""},"limits":{"cpu":"","memory":""}},"teamId":"acid","allowedSourceRanges":null,"numberOfInstances":0,"users":null,"clone":{}},"status":"Invalid"}`), nil},
 	{
@@ -350,8 +350,8 @@ var postgresqlList = []struct {
 					AllowedSourceRanges: []string{"185.85.220.0/22"},
 					NumberOfInstances:   1,
 				},
-				Status: ClusterStatusRunning,
-				Error:  "",
+				PostgresClusterStatus: ClusterStatusRunning,
+				Error:                 "",
 			}},
 		},
 		nil},
diff --git a/pkg/cluster/cluster.go b/pkg/cluster/cluster.go
index c319ab5d..66a65cf1 100644
--- a/pkg/cluster/cluster.go
+++ b/pkg/cluster/cluster.go
@@ -149,30 +149,30 @@ func (c *Cluster) setProcessName(procName string, args ...interface{}) {
 	}
 }
 
-func (c *Cluster) setStatus(status acidv1.PostgresStatus) {
+func (c *Cluster) setPostgresClusterStatus(postgresClusterStatus acidv1.PostgresStatus) {
 	// TODO: eventually switch to updateStatus() for kubernetes 1.11 and above
 	var (
 		err error
 		b   []byte
 	)
-	if b, err = json.Marshal(status); err != nil {
-		c.logger.Errorf("could not marshal status: %v", err)
+	if b, err = json.Marshal(postgresClusterStatus); err != nil {
+		c.logger.Errorf("could not marshal Postgres cluster status: %v", err)
 	}
 
-	patch := []byte(fmt.Sprintf(`{"status": %s}`, string(b)))
+	patch := []byte(fmt.Sprintf(`{"Postgres cluster status": %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)
 	if err != nil {
-		c.logger.Errorf("could not update status: %v", err)
+		c.logger.Errorf("could not update Postgres cluster status: %v", err)
 	}
 	// update the spec, maintaining the new resourceVersion.
 	c.setSpec(newspec)
 }
 
 func (c *Cluster) isNewCluster() bool {
-	return c.Status == acidv1.ClusterStatusCreating
+	return c.PostgresClusterStatus == acidv1.ClusterStatusCreating
 }
 
 // initUsers populates c.systemUsers and c.pgUsers maps.
@@ -214,13 +214,13 @@ func (c *Cluster) Create() error {
 
 	defer func() {
 		if err == nil {
-			c.setStatus(acidv1.ClusterStatusRunning) //TODO: are you sure it's running?
+			c.setPostgresClusterStatus(acidv1.ClusterStatusRunning) //TODO: are you sure it's running?
 		} else {
-			c.setStatus(acidv1.ClusterStatusAddFailed)
+			c.setPostgresClusterStatus(acidv1.ClusterStatusAddFailed)
 		}
 	}()
 
-	c.setStatus(acidv1.ClusterStatusCreating)
+	c.setPostgresClusterStatus(acidv1.ClusterStatusCreating)
 
 	for _, role := range []PostgresRole{Master, Replica} {
 
@@ -487,14 +487,14 @@ func (c *Cluster) Update(oldSpec, newSpec *acidv1.Postgresql) error {
 	c.mu.Lock()
 	defer c.mu.Unlock()
 
-	c.setStatus(acidv1.ClusterStatusUpdating)
+	c.setPostgresClusterStatus(acidv1.ClusterStatusUpdating)
 	c.setSpec(newSpec)
 
 	defer func() {
 		if updateFailed {
-			c.setStatus(acidv1.ClusterStatusUpdateFailed)
+			c.setPostgresClusterStatus(acidv1.ClusterStatusUpdateFailed)
 		} else {
-			c.setStatus(acidv1.ClusterStatusRunning)
+			c.setPostgresClusterStatus(acidv1.ClusterStatusRunning)
 		}
 	}()
 
@@ -633,7 +633,7 @@ func (c *Cluster) Delete() {
 func (c *Cluster) NeedsRepair() (bool, acidv1.PostgresStatus) {
 	c.specMu.RLock()
 	defer c.specMu.RUnlock()
-	return !c.Status.Success(), c.Status
+	return !c.PostgresClusterStatus.Success(), c.PostgresClusterStatus
 
 }
 
@@ -853,12 +853,12 @@ func (c *Cluster) GetCurrentProcess() Process {
 }
 
 // GetStatus provides status of the cluster
-func (c *Cluster) GetStatus() *ClusterStatus {
+func (c *Cluster) GetPostgresClusterStatus() *ClusterStatus {
 	return &ClusterStatus{
-		Cluster: c.Spec.ClusterName,
-		Team:    c.Spec.TeamID,
-		Status:  c.Status,
-		Spec:    c.Spec,
+		Cluster:               c.Spec.ClusterName,
+		Team:                  c.Spec.TeamID,
+		PostgresClusterStatus: c.PostgresClusterStatus,
+		Spec:                  c.Spec,
 
 		MasterService:       c.GetServiceMaster(),
 		ReplicaService:      c.GetServiceReplica(),
diff --git a/pkg/cluster/sync.go b/pkg/cluster/sync.go
index d2157c8a..7a3ea169 100644
--- a/pkg/cluster/sync.go
+++ b/pkg/cluster/sync.go
@@ -27,9 +27,9 @@ func (c *Cluster) Sync(newSpec *acidv1.Postgresql) error {
 	defer func() {
 		if err != nil {
 			c.logger.Warningf("error while syncing cluster state: %v", err)
-			c.setStatus(acidv1.ClusterStatusSyncFailed)
-		} else if c.Status != acidv1.ClusterStatusRunning {
-			c.setStatus(acidv1.ClusterStatusRunning)
+			c.setPostgresClusterStatus(acidv1.ClusterStatusSyncFailed)
+		} else if c.PostgresClusterStatus != acidv1.ClusterStatusRunning {
+			c.setPostgresClusterStatus(acidv1.ClusterStatusRunning)
 		}
 	}()
 
diff --git a/pkg/cluster/types.go b/pkg/cluster/types.go
index 5fd5029d..43ca75dd 100644
--- a/pkg/cluster/types.go
+++ b/pkg/cluster/types.go
@@ -63,9 +63,9 @@ type ClusterStatus struct {
 	StatefulSet         *v1beta1.StatefulSet
 	PodDisruptionBudget *policybeta1.PodDisruptionBudget
 
-	CurrentProcess Process
-	Worker         uint32
-	Status         acidv1.PostgresStatus
-	Spec           acidv1.PostgresSpec
-	Error          error
+	CurrentProcess        Process
+	Worker                uint32
+	PostgresClusterStatus acidv1.PostgresStatus
+	Spec                  acidv1.PostgresSpec
+	Error                 error
 }
diff --git a/pkg/controller/logs_and_api.go b/pkg/controller/logs_and_api.go
index 24e73fab..36484d1a 100644
--- a/pkg/controller/logs_and_api.go
+++ b/pkg/controller/logs_and_api.go
@@ -29,7 +29,7 @@ func (c *Controller) ClusterStatus(team, namespace, cluster string) (*cluster.Cl
 		return nil, fmt.Errorf("could not find cluster")
 	}
 
-	status := cl.GetStatus()
+	status := cl.GetPostgresClusterStatus()
 	status.Worker = c.clusterWorkerID(clusterName)
 
 	return status, nil
diff --git a/pkg/controller/postgresql.go b/pkg/controller/postgresql.go
index dc082ffa..b3333491 100644
--- a/pkg/controller/postgresql.go
+++ b/pkg/controller/postgresql.go
@@ -89,7 +89,7 @@ func (c *Controller) queueEvents(list *acidv1.PostgresqlList, event EventType) {
 		activeClustersCnt++
 		// check if that cluster needs repair
 		if event == EventRepair {
-			if pg.Status.Success() {
+			if pg.PostgresClusterStatus.Success() {
 				continue
 			} else {
 				clustersToRepair++
-- 
GitLab