change name of status field
This commit is contained in:
parent
313db7d10b
commit
3887938ab9
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ type Postgresql struct {
|
|||
metav1.ObjectMeta `json:"metadata,omitempty"`
|
||||
|
||||
Spec PostgresSpec `json:"spec"`
|
||||
Status PostgresStatus `json:"status,omitempty"`
|
||||
PostgresClusterStatus PostgresStatus `json:"status,omitempty"`
|
||||
Error string `json:"-"`
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
},
|
||||
|
|
@ -285,7 +285,7 @@ var unmarshalCluster = []struct {
|
|||
Name: "teapot-testcluster1",
|
||||
},
|
||||
Spec: PostgresSpec{TeamID: "acid"},
|
||||
Status: ClusterStatusInvalid,
|
||||
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,7 +350,7 @@ var postgresqlList = []struct {
|
|||
AllowedSourceRanges: []string{"185.85.220.0/22"},
|
||||
NumberOfInstances: 1,
|
||||
},
|
||||
Status: ClusterStatusRunning,
|
||||
PostgresClusterStatus: ClusterStatusRunning,
|
||||
Error: "",
|
||||
}},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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,11 +853,11 @@ 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,
|
||||
PostgresClusterStatus: c.PostgresClusterStatus,
|
||||
Spec: c.Spec,
|
||||
|
||||
MasterService: c.GetServiceMaster(),
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ type ClusterStatus struct {
|
|||
|
||||
CurrentProcess Process
|
||||
Worker uint32
|
||||
Status acidv1.PostgresStatus
|
||||
PostgresClusterStatus acidv1.PostgresStatus
|
||||
Spec acidv1.PostgresSpec
|
||||
Error error
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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++
|
||||
|
|
|
|||
Loading…
Reference in New Issue