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.Error = err.Error() | ||||||
| 		tmp.Status = ClusterStatusInvalid | 		tmp.PostgresClusterStatus = ClusterStatusInvalid | ||||||
| 
 | 
 | ||||||
| 		*p = Postgresql(tmp) | 		*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 { | 	if clusterName, err := extractClusterName(tmp2.ObjectMeta.Name, tmp2.Spec.TeamID); err != nil { | ||||||
| 		tmp2.Error = err.Error() | 		tmp2.Error = err.Error() | ||||||
| 		tmp2.Status = ClusterStatusInvalid | 		tmp2.PostgresClusterStatus = ClusterStatusInvalid | ||||||
| 	} else if err := validateCloneClusterDescription(&tmp2.Spec.Clone); err != nil { | 	} else if err := validateCloneClusterDescription(&tmp2.Spec.Clone); err != nil { | ||||||
| 		tmp2.Error = err.Error() | 		tmp2.Error = err.Error() | ||||||
| 		tmp2.Status = ClusterStatusInvalid | 		tmp2.PostgresClusterStatus = ClusterStatusInvalid | ||||||
| 	} else { | 	} else { | ||||||
| 		tmp2.Spec.ClusterName = clusterName | 		tmp2.Spec.ClusterName = clusterName | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | @ -15,9 +15,9 @@ type Postgresql struct { | ||||||
| 	metav1.TypeMeta   `json:",inline"` | 	metav1.TypeMeta   `json:",inline"` | ||||||
| 	metav1.ObjectMeta `json:"metadata,omitempty"` | 	metav1.ObjectMeta `json:"metadata,omitempty"` | ||||||
| 
 | 
 | ||||||
| 	Spec   PostgresSpec   `json:"spec"` | 	Spec                  PostgresSpec   `json:"spec"` | ||||||
| 	Status PostgresStatus `json:"status,omitempty"` | 	PostgresClusterStatus PostgresStatus `json:"status,omitempty"` | ||||||
| 	Error  string         `json:"-"` | 	Error                 string         `json:"-"` | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // PostgresSpec defines the specification for the PostgreSQL TPR.
 | // PostgresSpec defines the specification for the PostgreSQL TPR.
 | ||||||
|  |  | ||||||
|  | @ -85,12 +85,12 @@ func validateCloneClusterDescription(clone *CloneDescription) error { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // Success of the current Status
 | // Success of the current Status
 | ||||||
| func (status PostgresStatus) Success() bool { | func (postgresClusterStatus PostgresStatus) Success() bool { | ||||||
| 	return status != ClusterStatusAddFailed && | 	return postgresClusterStatus != ClusterStatusAddFailed && | ||||||
| 		status != ClusterStatusUpdateFailed && | 		postgresClusterStatus != ClusterStatusUpdateFailed && | ||||||
| 		status != ClusterStatusSyncFailed | 		postgresClusterStatus != ClusterStatusSyncFailed | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (status PostgresStatus) String() string { | func (postgresClusterStatus PostgresStatus) String() string { | ||||||
| 	return string(status) | 	return string(postgresClusterStatus) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -128,7 +128,7 @@ var unmarshalCluster = []struct { | ||||||
| 		ObjectMeta: metav1.ObjectMeta{ | 		ObjectMeta: metav1.ObjectMeta{ | ||||||
| 			Name: "acid-testcluster1", | 			Name: "acid-testcluster1", | ||||||
| 		}, | 		}, | ||||||
| 		Status: ClusterStatusInvalid, | 		PostgresClusterStatus: ClusterStatusInvalid, | ||||||
| 		// This error message can vary between Go versions, so compute it for the current version.
 | 		// This error message can vary between Go versions, so compute it for the current version.
 | ||||||
| 		Error: json.Unmarshal([]byte(`{"teamId": 0}`), &PostgresSpec{}).Error(), | 		Error: json.Unmarshal([]byte(`{"teamId": 0}`), &PostgresSpec{}).Error(), | ||||||
| 	}, | 	}, | ||||||
|  | @ -284,9 +284,9 @@ var unmarshalCluster = []struct { | ||||||
| 			ObjectMeta: metav1.ObjectMeta{ | 			ObjectMeta: metav1.ObjectMeta{ | ||||||
| 				Name: "teapot-testcluster1", | 				Name: "teapot-testcluster1", | ||||||
| 			}, | 			}, | ||||||
| 			Spec:   PostgresSpec{TeamID: "acid"}, | 			Spec:                  PostgresSpec{TeamID: "acid"}, | ||||||
| 			Status: ClusterStatusInvalid, | 			PostgresClusterStatus: ClusterStatusInvalid, | ||||||
| 			Error:  errors.New("name must match {TEAM}-{NAME} format").Error(), | 			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}, | 		[]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"}, | 					AllowedSourceRanges: []string{"185.85.220.0/22"}, | ||||||
| 					NumberOfInstances:   1, | 					NumberOfInstances:   1, | ||||||
| 				}, | 				}, | ||||||
| 				Status: ClusterStatusRunning, | 				PostgresClusterStatus: ClusterStatusRunning, | ||||||
| 				Error:  "", | 				Error:                 "", | ||||||
| 			}}, | 			}}, | ||||||
| 		}, | 		}, | ||||||
| 		nil}, | 		nil}, | ||||||
|  |  | ||||||
|  | @ -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
 | 	// TODO: eventually switch to updateStatus() for kubernetes 1.11 and above
 | ||||||
| 	var ( | 	var ( | ||||||
| 		err error | 		err error | ||||||
| 		b   []byte | 		b   []byte | ||||||
| 	) | 	) | ||||||
| 	if b, err = json.Marshal(status); err != nil { | 	if b, err = json.Marshal(postgresClusterStatus); err != nil { | ||||||
| 		c.logger.Errorf("could not marshal status: %v", err) | 		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),
 | 	// 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)
 | 	// 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.
 | 	// 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, patch) | ||||||
| 	if err != nil { | 	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.
 | 	// update the spec, maintaining the new resourceVersion.
 | ||||||
| 	c.setSpec(newspec) | 	c.setSpec(newspec) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (c *Cluster) isNewCluster() bool { | func (c *Cluster) isNewCluster() bool { | ||||||
| 	return c.Status == acidv1.ClusterStatusCreating | 	return c.PostgresClusterStatus == acidv1.ClusterStatusCreating | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // initUsers populates c.systemUsers and c.pgUsers maps.
 | // initUsers populates c.systemUsers and c.pgUsers maps.
 | ||||||
|  | @ -214,13 +214,13 @@ func (c *Cluster) Create() error { | ||||||
| 
 | 
 | ||||||
| 	defer func() { | 	defer func() { | ||||||
| 		if err == nil { | 		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 { | 		} else { | ||||||
| 			c.setStatus(acidv1.ClusterStatusAddFailed) | 			c.setPostgresClusterStatus(acidv1.ClusterStatusAddFailed) | ||||||
| 		} | 		} | ||||||
| 	}() | 	}() | ||||||
| 
 | 
 | ||||||
| 	c.setStatus(acidv1.ClusterStatusCreating) | 	c.setPostgresClusterStatus(acidv1.ClusterStatusCreating) | ||||||
| 
 | 
 | ||||||
| 	for _, role := range []PostgresRole{Master, Replica} { | 	for _, role := range []PostgresRole{Master, Replica} { | ||||||
| 
 | 
 | ||||||
|  | @ -487,14 +487,14 @@ func (c *Cluster) Update(oldSpec, newSpec *acidv1.Postgresql) error { | ||||||
| 	c.mu.Lock() | 	c.mu.Lock() | ||||||
| 	defer c.mu.Unlock() | 	defer c.mu.Unlock() | ||||||
| 
 | 
 | ||||||
| 	c.setStatus(acidv1.ClusterStatusUpdating) | 	c.setPostgresClusterStatus(acidv1.ClusterStatusUpdating) | ||||||
| 	c.setSpec(newSpec) | 	c.setSpec(newSpec) | ||||||
| 
 | 
 | ||||||
| 	defer func() { | 	defer func() { | ||||||
| 		if updateFailed { | 		if updateFailed { | ||||||
| 			c.setStatus(acidv1.ClusterStatusUpdateFailed) | 			c.setPostgresClusterStatus(acidv1.ClusterStatusUpdateFailed) | ||||||
| 		} else { | 		} else { | ||||||
| 			c.setStatus(acidv1.ClusterStatusRunning) | 			c.setPostgresClusterStatus(acidv1.ClusterStatusRunning) | ||||||
| 		} | 		} | ||||||
| 	}() | 	}() | ||||||
| 
 | 
 | ||||||
|  | @ -633,7 +633,7 @@ func (c *Cluster) Delete() { | ||||||
| func (c *Cluster) NeedsRepair() (bool, acidv1.PostgresStatus) { | func (c *Cluster) NeedsRepair() (bool, acidv1.PostgresStatus) { | ||||||
| 	c.specMu.RLock() | 	c.specMu.RLock() | ||||||
| 	defer c.specMu.RUnlock() | 	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
 | // GetStatus provides status of the cluster
 | ||||||
| func (c *Cluster) GetStatus() *ClusterStatus { | func (c *Cluster) GetPostgresClusterStatus() *ClusterStatus { | ||||||
| 	return &ClusterStatus{ | 	return &ClusterStatus{ | ||||||
| 		Cluster: c.Spec.ClusterName, | 		Cluster:               c.Spec.ClusterName, | ||||||
| 		Team:    c.Spec.TeamID, | 		Team:                  c.Spec.TeamID, | ||||||
| 		Status:  c.Status, | 		PostgresClusterStatus: c.PostgresClusterStatus, | ||||||
| 		Spec:    c.Spec, | 		Spec:                  c.Spec, | ||||||
| 
 | 
 | ||||||
| 		MasterService:       c.GetServiceMaster(), | 		MasterService:       c.GetServiceMaster(), | ||||||
| 		ReplicaService:      c.GetServiceReplica(), | 		ReplicaService:      c.GetServiceReplica(), | ||||||
|  |  | ||||||
|  | @ -27,9 +27,9 @@ func (c *Cluster) Sync(newSpec *acidv1.Postgresql) error { | ||||||
| 	defer func() { | 	defer func() { | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			c.logger.Warningf("error while syncing cluster state: %v", err) | 			c.logger.Warningf("error while syncing cluster state: %v", err) | ||||||
| 			c.setStatus(acidv1.ClusterStatusSyncFailed) | 			c.setPostgresClusterStatus(acidv1.ClusterStatusSyncFailed) | ||||||
| 		} else if c.Status != acidv1.ClusterStatusRunning { | 		} else if c.PostgresClusterStatus != acidv1.ClusterStatusRunning { | ||||||
| 			c.setStatus(acidv1.ClusterStatusRunning) | 			c.setPostgresClusterStatus(acidv1.ClusterStatusRunning) | ||||||
| 		} | 		} | ||||||
| 	}() | 	}() | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -63,9 +63,9 @@ type ClusterStatus struct { | ||||||
| 	StatefulSet         *v1beta1.StatefulSet | 	StatefulSet         *v1beta1.StatefulSet | ||||||
| 	PodDisruptionBudget *policybeta1.PodDisruptionBudget | 	PodDisruptionBudget *policybeta1.PodDisruptionBudget | ||||||
| 
 | 
 | ||||||
| 	CurrentProcess Process | 	CurrentProcess        Process | ||||||
| 	Worker         uint32 | 	Worker                uint32 | ||||||
| 	Status         acidv1.PostgresStatus | 	PostgresClusterStatus acidv1.PostgresStatus | ||||||
| 	Spec           acidv1.PostgresSpec | 	Spec                  acidv1.PostgresSpec | ||||||
| 	Error          error | 	Error                 error | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -29,7 +29,7 @@ func (c *Controller) ClusterStatus(team, namespace, cluster string) (*cluster.Cl | ||||||
| 		return nil, fmt.Errorf("could not find cluster") | 		return nil, fmt.Errorf("could not find cluster") | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	status := cl.GetStatus() | 	status := cl.GetPostgresClusterStatus() | ||||||
| 	status.Worker = c.clusterWorkerID(clusterName) | 	status.Worker = c.clusterWorkerID(clusterName) | ||||||
| 
 | 
 | ||||||
| 	return status, nil | 	return status, nil | ||||||
|  |  | ||||||
|  | @ -89,7 +89,7 @@ func (c *Controller) queueEvents(list *acidv1.PostgresqlList, event EventType) { | ||||||
| 		activeClustersCnt++ | 		activeClustersCnt++ | ||||||
| 		// check if that cluster needs repair
 | 		// check if that cluster needs repair
 | ||||||
| 		if event == EventRepair { | 		if event == EventRepair { | ||||||
| 			if pg.Status.Success() { | 			if pg.PostgresClusterStatus.Success() { | ||||||
| 				continue | 				continue | ||||||
| 			} else { | 			} else { | ||||||
| 				clustersToRepair++ | 				clustersToRepair++ | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue