diff --git a/pkg/cluster/pod.go b/pkg/cluster/pod.go index 60106834c..9716e2a1c 100644 --- a/pkg/cluster/pod.go +++ b/pkg/cluster/pod.go @@ -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 } diff --git a/pkg/cluster/sync.go b/pkg/cluster/sync.go index e81eec8d1..9d8720a34 100644 --- a/pkg/cluster/sync.go +++ b/pkg/cluster/sync.go @@ -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) diff --git a/pkg/cluster/util.go b/pkg/cluster/util.go index 899432f91..be13a27d2 100644 --- a/pkg/cluster/util.go +++ b/pkg/cluster/util.go @@ -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 { diff --git a/pkg/util/constants/constants.go b/pkg/util/constants/constants.go index bc4b48605..c9c193b7a 100644 --- a/pkg/util/constants/constants.go +++ b/pkg/util/constants/constants.go @@ -12,4 +12,6 @@ const ( ZalandoDnsNameAnnotation = "zalando.org/dnsname" KubeIAmAnnotation = "iam.amazonaws.com/role" ResourceName = TPRName + "s" + PodRoleMaster = "master" + PodRoleReplica = "replica" )