Skip to content

Commit 2667040

Browse files
authored
Revert "Unify warnings about unmovable pods (zalando#389)" (zalando#430)
This reverts commit 4fa09e0. Reason: the reverted commit bloats the logs
1 parent 4fa09e0 commit 2667040

File tree

2 files changed

+27
-41
lines changed

2 files changed

+27
-41
lines changed

pkg/controller/node.go

Lines changed: 26 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ import (
77
"k8s.io/apimachinery/pkg/runtime"
88
"k8s.io/apimachinery/pkg/watch"
99

10-
"fmt"
11-
1210
"github.com/zalando-incubator/postgres-operator/pkg/cluster"
13-
"github.com/zalando-incubator/postgres-operator/pkg/spec"
1411
"github.com/zalando-incubator/postgres-operator/pkg/util"
1512
)
1613

@@ -58,16 +55,15 @@ func (c *Controller) nodeUpdate(prev, cur interface{}) {
5855
return
5956
}
6057

61-
if !c.nodeIsReady(nodePrev) {
62-
c.logger.Debugf("The decommissioned node %v should have already triggered master pod migration. Previous k8s-reported state of the node: %v", util.NameFromMeta(nodePrev.ObjectMeta), nodePrev)
58+
if util.MapContains(nodeCur.Labels, map[string]string{"master": "true"}) {
6359
return
6460
}
6561

66-
if c.nodeIsReady(nodeCur) {
67-
c.logger.Debugf("The decommissioned node %v become schedulable again. Current k8s-reported state of the node: %v", util.NameFromMeta(nodeCur.ObjectMeta), nodeCur)
62+
// do nothing if the node should have already triggered an update or
63+
// if only one of the label and the unschedulability criteria are met.
64+
if !c.nodeIsReady(nodePrev) || c.nodeIsReady(nodeCur) {
6865
return
6966
}
70-
7167
c.moveMasterPodsOffNode(nodeCur)
7268
}
7369

@@ -77,17 +73,16 @@ func (c *Controller) nodeIsReady(node *v1.Node) bool {
7773
}
7874

7975
func (c *Controller) moveMasterPodsOffNode(node *v1.Node) {
80-
8176
nodeName := util.NameFromMeta(node.ObjectMeta)
82-
c.logger.Infof("moving pods: node %q became unschedulable and does not have a ready label %q",
77+
c.logger.Infof("moving pods: node %q became unschedulable and does not have a ready label: %q",
8378
nodeName, c.opConfig.NodeReadinessLabel)
8479

8580
opts := metav1.ListOptions{
8681
LabelSelector: labels.Set(c.opConfig.ClusterLabels).String(),
8782
}
8883
podList, err := c.KubeClient.Pods(c.opConfig.WatchedNamespace).List(opts)
8984
if err != nil {
90-
c.logger.Errorf("could not fetch the list of Spilo pods: %v", err)
85+
c.logger.Errorf("could not fetch list of the pods: %v", err)
9186
return
9287
}
9388

@@ -98,25 +93,17 @@ func (c *Controller) moveMasterPodsOffNode(node *v1.Node) {
9893
}
9994
}
10095

101-
movedMasterPods := 0
102-
movableMasterPods := make(map[*v1.Pod]*cluster.Cluster)
103-
unmovablePods := make(map[spec.NamespacedName]string)
104-
10596
clusters := make(map[*cluster.Cluster]bool)
106-
97+
masterPods := make(map[*v1.Pod]*cluster.Cluster)
98+
movedPods := 0
10799
for _, pod := range nodePods {
108-
109100
podName := util.NameFromMeta(pod.ObjectMeta)
110101

111102
role, ok := pod.Labels[c.opConfig.PodRoleLabel]
112-
if !ok {
113-
// pods with an unknown role cannot be safely moved to another node
114-
unmovablePods[podName] = fmt.Sprintf("could not move pod %q from node %q: pod has no role label %q", podName, nodeName, c.opConfig.PodRoleLabel)
115-
continue
116-
}
117-
118-
// deployments can transparently re-create replicas so we do not move away such pods
119-
if cluster.PostgresRole(role) == cluster.Replica {
103+
if !ok || cluster.PostgresRole(role) != cluster.Master {
104+
if !ok {
105+
c.logger.Warningf("could not move pod %q: pod has no role", podName)
106+
}
120107
continue
121108
}
122109

@@ -126,45 +113,44 @@ func (c *Controller) moveMasterPodsOffNode(node *v1.Node) {
126113
cl, ok := c.clusters[clusterName]
127114
c.clustersMu.RUnlock()
128115
if !ok {
129-
unmovablePods[podName] = fmt.Sprintf("could not move master pod %q from node %q: pod belongs to an unknown Postgres cluster %q", podName, nodeName, clusterName)
116+
c.logger.Warningf("could not move pod %q: pod does not belong to a known cluster", podName)
130117
continue
131118
}
132119

133120
if !clusters[cl] {
134121
clusters[cl] = true
135122
}
136123

137-
movableMasterPods[pod] = cl
124+
masterPods[pod] = cl
138125
}
139126

140127
for cl := range clusters {
141128
cl.Lock()
142129
}
143130

144-
for pod, cl := range movableMasterPods {
145-
131+
for pod, cl := range masterPods {
146132
podName := util.NameFromMeta(pod.ObjectMeta)
147-
if err := cl.MigrateMasterPod(podName); err == nil {
148-
movedMasterPods++
133+
134+
if err := cl.MigrateMasterPod(podName); err != nil {
135+
c.logger.Errorf("could not move master pod %q: %v", podName, err)
149136
} else {
150-
unmovablePods[podName] = fmt.Sprintf("could not move master pod %q from node %q: %v", podName, nodeName, err)
137+
movedPods++
151138
}
152139
}
153140

154141
for cl := range clusters {
155142
cl.Unlock()
156143
}
157144

158-
if leftPods := len(unmovablePods); leftPods > 0 {
159-
c.logger.Warnf("could not move %d master or unknown role pods from the node %q, you may have to delete them manually",
160-
leftPods, nodeName)
161-
for _, reason := range unmovablePods {
162-
c.logger.Warning(reason)
163-
}
164-
}
145+
totalPods := len(masterPods)
165146

166-
c.logger.Infof("%d master pods have been moved out from the node %q", movedMasterPods, nodeName)
147+
c.logger.Infof("%d/%d master pods have been moved out from the %q node",
148+
movedPods, totalPods, nodeName)
167149

150+
if leftPods := totalPods - movedPods; leftPods > 0 {
151+
c.logger.Warnf("could not move master %d/%d pods from the %q node",
152+
leftPods, totalPods, nodeName)
153+
}
168154
}
169155

170156
func (c *Controller) nodeDelete(obj interface{}) {

run_operator_locally.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ function deploy_self_built_image() {
121121
# update the tag in the postgres operator conf
122122
# since the image with this tag already exists on the machine,
123123
# docker should not attempt to fetch it from the registry due to imagePullPolicy
124-
sed --expression "s/\(image\:.*\:\).*$/\1$TAG/; s/smoke-tested-//" manifests/postgres-operator.yaml > "$PATH_TO_LOCAL_OPERATOR_MANIFEST"
124+
sed --expression "s/\(image\:.*\:\).*$/\1$TAG/" manifests/postgres-operator.yaml > "$PATH_TO_LOCAL_OPERATOR_MANIFEST"
125125

126126
retry "kubectl create -f \"$PATH_TO_LOCAL_OPERATOR_MANIFEST\"" "attempt to create $PATH_TO_LOCAL_OPERATOR_MANIFEST resource"
127127
}

0 commit comments

Comments
 (0)