Skip to content

Commit 77aaf86

Browse files
committed
Fix pod labeling with node role.
1 parent e0ef8bb commit 77aaf86

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

pkg/mysqlcluster/pods.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func (f *cFactory) updatePodLabels() error {
3333
pod, err := getPodForHostname(f.client, f.namespace, f.getLabels(map[string]string{}), ns.Name)
3434
if err != nil {
3535
glog.Errorf("Failed to update pod labels: %s", err)
36-
return err
36+
continue
3737
}
3838

3939
labels := pod.GetLabels()
@@ -48,7 +48,6 @@ func (f *cFactory) updatePodLabels() error {
4848
glog.V(2).Infof("Inspecting pod: %s, label: %s, desired: %s", pod.Name, val, desiredVal)
4949

5050
if !exists || val != desiredVal {
51-
labels["role"] = desiredVal
5251
glog.Infof("Updating labels for Pod: %s", pod.Name)
5352

5453
meta := metav1.ObjectMeta{
@@ -57,13 +56,19 @@ func (f *cFactory) updatePodLabels() error {
5756
OwnerReferences: pod.GetOwnerReferences(),
5857
Namespace: pod.GetNamespace(),
5958
}
59+
6060
_, act, err := kcore.CreateOrPatchPod(f.client, meta,
6161
func(in *core.Pod) *core.Pod {
62-
in.Labels = labels
62+
in.Labels["role"] = desiredVal
6363
return in
6464
})
65+
66+
if err != nil {
67+
glog.Errorf("Error while updating pod label: %s", err)
68+
}
69+
6570
glog.Infof("Pod %s was %s", pod.Name, getStatusFromKVerb(act))
66-
return err
71+
6772
}
6873
}
6974

pkg/mysqlcluster/statefullset.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"fmt"
2121

2222
kapps "github.com/appscode/kutil/apps/v1"
23-
"github.com/golang/glog"
2423
apps "k8s.io/api/apps/v1"
2524
core "k8s.io/api/core/v1"
2625
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -82,7 +81,6 @@ func (f *cFactory) syncStatefulSet() (state string, err error) {
8281
}
8382

8483
state = getStatusFromKVerb(act)
85-
glog.V(3).Infof("SFS synced state: %s", state)
8684
return
8785
}
8886

pkg/mysqlcluster/utils.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ func (f *cFactory) addNodesToService(serviceName string, hosts ...string) error
118118
pods = append(pods, pod)
119119
}
120120

121+
if len(pods) == 0 {
122+
// no need to create endpoints, because will fail without addresses
123+
glog.V(3).Infof("Nothing to do for hosts: %v, pods not found!", hosts)
124+
return nil
125+
}
126+
121127
meta := metav1.ObjectMeta{
122128
Name: serviceName,
123129
Labels: f.getLabels(map[string]string{}),

0 commit comments

Comments
 (0)