Skip to content

Commit 78bc972

Browse files
smanpathakAMecea
authored andcommitted
Fix issues with pod labeling
1 parent 354f7b1 commit 78bc972

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

pkg/mysqlcluster/cluster.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ func (f *cFactory) Sync(ctx context.Context) error {
170170
return fmt.Errorf("cluster sync ready endpoints: %s", err)
171171
}
172172

173+
if err := f.updatePodLabels(); err != nil {
174+
return fmt.Errorf("cluster sync pod labeling: %s", err)
175+
}
173176
return nil
174177
}
175178

pkg/mysqlcluster/endpoints.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ const (
3030

3131
func (f *cFactory) updateMasterServiceEndpoints() error {
3232
masterHost := f.getMasterHost()
33-
if err := f.updatePodLabels(masterHost); err != nil {
34-
return err
35-
}
3633

3734
return f.addNodesToService(f.cluster.GetNameForResource(api.MasterService), masterHost)
3835
}

pkg/mysqlcluster/pods.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@ import (
2626
)
2727

2828
// Set K8S labels indicating role pods: Master or Replica
29-
func (f *cFactory) updatePodLabels(masterHost string) error {
29+
func (f *cFactory) updatePodLabels() error {
30+
masterHost := f.getMasterHost()
31+
3032
for _, ns := range f.cluster.Status.Nodes {
3133
pod, err := getPodForHostname(f.client, f.namespace, f.getLabels(map[string]string{}), ns.Name)
3234
if err != nil {
3335
glog.Errorf("Failed to update pod labels: %s", err)
34-
continue
36+
return err
3537
}
3638

3739
labels := pod.GetLabels()
@@ -43,6 +45,7 @@ func (f *cFactory) updatePodLabels(masterHost string) error {
4345
desiredVal = "master"
4446
}
4547

48+
glog.Infof("Inspecting pod: %s, label: %s, desired: %s", pod.Name, val, desiredVal)
4649
if !exists || val != desiredVal {
4750
labels["role"] = desiredVal
4851
glog.Infof("Updating labels for Pod: %s", pod.Name)
@@ -53,11 +56,13 @@ func (f *cFactory) updatePodLabels(masterHost string) error {
5356
OwnerReferences: pod.GetOwnerReferences(),
5457
Namespace: pod.GetNamespace(),
5558
}
56-
kcore.CreateOrPatchPod(f.client, meta,
59+
_, act, err := kcore.CreateOrPatchPod(f.client, meta,
5760
func(in *core.Pod) *core.Pod {
5861
in.Labels = labels
5962
return in
6063
})
64+
glog.Infof("Pod %s was %s", pod.Name, getStatusFromKVerb(act))
65+
return err
6166
}
6267
}
6368

pkg/mysqlcluster/utils.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,12 @@ func (f *cFactory) addNodesToService(serviceName string, hosts ...string) error
107107
for _, host := range hosts {
108108
pod, err := getPodForHostname(f.client, f.namespace, f.getLabels(map[string]string{}), host)
109109
if err != nil {
110-
glog.Errorf("Failed to set master service endpoints: %s", err)
110+
glog.Errorf("Failed to set %s service endpoints: %s", serviceName, err)
111111
continue
112112
}
113113

114114
if len(pod.Status.PodIP) == 0 {
115-
glog.Errorf("Failed to set master service endpoints, ip for pod %s not set %s", pod.Name, err)
115+
glog.Errorf("Failed to set %s service endpoints, ip for pod %s not set %s", serviceName, pod.Name, err)
116116
continue
117117
}
118118
pods = append(pods, pod)
@@ -162,8 +162,7 @@ func (f *cFactory) addNodesToService(serviceName string, hosts ...string) error
162162
return in
163163
})
164164

165-
glog.Infof("Endpoints for service '%s' were %s.",
166-
f.cluster.GetNameForResource(api.MasterService), getStatusFromKVerb(act))
165+
glog.Infof("Endpoints for service '%s' were %s.", serviceName, getStatusFromKVerb(act))
167166

168167
return err
169168
}

0 commit comments

Comments
 (0)