Move master/replica role names into the constants.

This commit is contained in:
Oleksii Kliukin 2017-04-10 12:04:20 +02:00 committed by Murat Kabilov
parent 176c6e8b19
commit 455f91128f
4 changed files with 9 additions and 5 deletions

View File

@ -7,6 +7,7 @@ import (
"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/constants"
)
func (c *Cluster) listPods() ([]v1.Pod, error) {
@ -179,7 +180,7 @@ func (c *Cluster) recreatePods() error {
continue
}
if role == "master" {
if role == constants.PodRoleMaster {
masterPod = pod
continue
}

View File

@ -7,6 +7,7 @@ import (
"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/constants"
)
func (c *Cluster) SyncCluster() {
@ -173,7 +174,7 @@ func (c *Cluster) syncPods() error {
c.logPodChanges(&pod, curSs, reason)
}
if util.PodSpiloRole(&pod) == "master" {
if util.PodSpiloRole(&pod) == constants.PodRoleMaster {
//TODO: do manual failover first
}
err = c.recreatePod(pod)

View File

@ -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 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.
if role == "master" || role == "replica" {
if role == constants.PodRoleMaster || role == constants.PodRoleReplica {
return nil
}
case <-time.After(c.OpConfig.PodLabelWaitTimeout):
@ -203,10 +203,10 @@ func (c *Cluster) waitPodLabelsReady() error {
LabelSelector: ls.String(),
}
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{
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)
if err != nil {

View File

@ -12,4 +12,6 @@ const (
ZalandoDnsNameAnnotation = "zalando.org/dnsname"
KubeIAmAnnotation = "iam.amazonaws.com/role"
ResourceName = TPRName + "s"
PodRoleMaster = "master"
PodRoleReplica = "replica"
)