Move master/replica role names into the constants.
This commit is contained in:
		
							parent
							
								
									176c6e8b19
								
							
						
					
					
						commit
						455f91128f
					
				|  | @ -7,6 +7,7 @@ import ( | ||||||
| 
 | 
 | ||||||
| 	"github.bus.zalan.do/acid/postgres-operator/pkg/spec" | 	"github.bus.zalan.do/acid/postgres-operator/pkg/spec" | ||||||
| 	"github.bus.zalan.do/acid/postgres-operator/pkg/util" | 	"github.bus.zalan.do/acid/postgres-operator/pkg/util" | ||||||
|  | 	"github.bus.zalan.do/acid/postgres-operator/pkg/util/constants" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| func (c *Cluster) listPods() ([]v1.Pod, error) { | func (c *Cluster) listPods() ([]v1.Pod, error) { | ||||||
|  | @ -179,7 +180,7 @@ func (c *Cluster) recreatePods() error { | ||||||
| 			continue | 			continue | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		if role == "master" { | 		if role == constants.PodRoleMaster { | ||||||
| 			masterPod = pod | 			masterPod = pod | ||||||
| 			continue | 			continue | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  | @ -7,6 +7,7 @@ import ( | ||||||
| 
 | 
 | ||||||
| 	"github.bus.zalan.do/acid/postgres-operator/pkg/spec" | 	"github.bus.zalan.do/acid/postgres-operator/pkg/spec" | ||||||
| 	"github.bus.zalan.do/acid/postgres-operator/pkg/util" | 	"github.bus.zalan.do/acid/postgres-operator/pkg/util" | ||||||
|  | 	"github.bus.zalan.do/acid/postgres-operator/pkg/util/constants" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| func (c *Cluster) SyncCluster() { | func (c *Cluster) SyncCluster() { | ||||||
|  | @ -173,7 +174,7 @@ func (c *Cluster) syncPods() error { | ||||||
| 			c.logPodChanges(&pod, curSs, reason) | 			c.logPodChanges(&pod, curSs, reason) | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		if util.PodSpiloRole(&pod) == "master" { | 		if util.PodSpiloRole(&pod) == constants.PodRoleMaster { | ||||||
| 			//TODO: do manual failover first
 | 			//TODO: do manual failover first
 | ||||||
| 		} | 		} | ||||||
| 		err = c.recreatePod(pod) | 		err = c.recreatePod(pod) | ||||||
|  |  | ||||||
|  | @ -154,7 +154,7 @@ func (c *Cluster) waitForPodLabel(podEvents chan spec.PodEvent) error { | ||||||
| 			// We cannot assume any role of the newly created pod. Normally, for a multi-pod cluster
 | 			// We cannot assume any role of the newly created pod. Normally, for a multi-pod cluster
 | ||||||
| 			// we should observe the 'replica' value, but it could be that some pods are not allowed
 | 			// we should observe the 'replica' value, but it could be that some pods are not allowed
 | ||||||
| 			// to promote, therefore, the new pod could be a master as well.
 | 			// to promote, therefore, the new pod could be a master as well.
 | ||||||
| 			if role == "master" || role == "replica" { | 			if role == constants.PodRoleMaster || role == constants.PodRoleReplica { | ||||||
| 				return nil | 				return nil | ||||||
| 			} | 			} | ||||||
| 		case <-time.After(c.OpConfig.PodLabelWaitTimeout): | 		case <-time.After(c.OpConfig.PodLabelWaitTimeout): | ||||||
|  | @ -203,10 +203,10 @@ func (c *Cluster) waitPodLabelsReady() error { | ||||||
| 		LabelSelector: ls.String(), | 		LabelSelector: ls.String(), | ||||||
| 	} | 	} | ||||||
| 	masterListOption := v1.ListOptions{ | 	masterListOption := v1.ListOptions{ | ||||||
| 		LabelSelector: labels.Merge(ls, labels.Set{"spilo-role": "master"}).String(), | 		LabelSelector: labels.Merge(ls, labels.Set{"spilo-role": constants.PodRoleMaster}).String(), | ||||||
| 	} | 	} | ||||||
| 	replicaListOption := v1.ListOptions{ | 	replicaListOption := v1.ListOptions{ | ||||||
| 		LabelSelector: labels.Merge(ls, labels.Set{"spilo-role": "replica"}).String(), | 		LabelSelector: labels.Merge(ls, labels.Set{"spilo-role": constants.PodRoleReplica}).String(), | ||||||
| 	} | 	} | ||||||
| 	pods, err := c.KubeClient.Pods(namespace).List(listOptions) | 	pods, err := c.KubeClient.Pods(namespace).List(listOptions) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
|  |  | ||||||
|  | @ -12,4 +12,6 @@ const ( | ||||||
| 	ZalandoDnsNameAnnotation = "zalando.org/dnsname" | 	ZalandoDnsNameAnnotation = "zalando.org/dnsname" | ||||||
| 	KubeIAmAnnotation        = "iam.amazonaws.com/role" | 	KubeIAmAnnotation        = "iam.amazonaws.com/role" | ||||||
| 	ResourceName             = TPRName + "s" | 	ResourceName             = TPRName + "s" | ||||||
|  | 	PodRoleMaster            = "master" | ||||||
|  | 	PodRoleReplica           = "replica" | ||||||
| ) | ) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue