diff --git a/pkg/apis/acid.zalan.do/v1/marshal.go b/pkg/apis/acid.zalan.do/v1/marshal.go index 823ff0ef22cb4e6b5823a613eb99dbd654c384b1..d53db02909f5a98c7683399b98ea41f8d55a32cc 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 ccd7fe08c7d9c87dd1f34e2099e1e66356fadade..3f669a8dc595ab09374655e584bc840e6f10853d 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 0a3267972280e735f51b9de4ff38e7de5f23cc76..6e0a9d863d7738b1f51140e1f0fd808e61df66a4 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 01be31e887b684ce3e62dd31b8c6540312cc989d..cb5e1298e41e3376c7a61e6440155049b3732dd2 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 c319ab5d16d2651d47144452475cf647c167193f..66a65cf189676359eebbff6e8e099a0499c96b0b 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 d2157c8a28c340eb30e2942c31f70a7d72aedc82..7a3ea169a08240576429d9c9820cafd3018657a6 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 5fd5029dbb1feca09cc8ce01d254521007442328..43ca75dd9c47a08f01c8a04b7bc36a5dc68173d8 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 24e73fabed9cde3de83bdf5bd04d68d8442bef9e..36484d1a93606e5b5d65c20e37528981687d11b8 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 dc082ffabc2fce58275461d31257181001a11077..b3333491ff0b9f0c17a3d5636e67eb7c0f65abbd 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++