Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add affinity to pump/drainer #741

Merged
merged 4 commits into from
Aug 9, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions charts/tidb-cluster/templates/drainer-statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ spec:
app.kubernetes.io/managed-by: tidb-operator
app.kubernetes.io/component: drainer
spec:
{{- if .Values.binlog.drainer.affinity }}
affinity:
{{ toYaml .Values.binlog.drainer.affinity | indent 8 }}
{{- end }}
containers:
- name: drainer
image: {{ .Values.binlog.drainer.image }}
Expand Down
4 changes: 4 additions & 0 deletions charts/tidb-cluster/templates/pump-statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ spec:
app.kubernetes.io/managed-by: tidb-operator
app.kubernetes.io/component: pump
spec:
{{- if .Values.binlog.pump.affinity }}
affinity:
{{ toYaml .Values.binlog.pump.affinity | indent 8 }}
{{- end }}
containers:
- name: pump
image: {{ .Values.binlog.pump.image }}
Expand Down
6 changes: 6 additions & 0 deletions charts/tidb-cluster/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,9 @@ binlog:
# refer to https://kubernetes.io/docs/concepts/storage/storage-classes
storageClassName: local-storage
storage: 20Gi
# affinity for pump pod assignment, default: empty
# ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity
affinity: {}
syncLog: true
# a integer value to control expiry date of the binlog data, indicates for how long (in days) the binlog data would be stored.
# must bigger than 0
Expand All @@ -428,6 +431,9 @@ binlog:
# refer to https://kubernetes.io/docs/concepts/storage/storage-classes
storageClassName: local-storage
storage: 10Gi
# affinity for drainer pod assignment, default: empty
# ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity
affinity: {}
# the number of the concurrency of the downstream for synchronization. The bigger the value,
# the better throughput performance of the concurrency (16 by default)
workerCount: 16
Expand Down
27 changes: 22 additions & 5 deletions tests/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2333,7 +2333,11 @@ func (oa *operatorActions) CheckIncrementalBackup(info *TidbClusterConfig, withD

listOps := metav1.ListOptions{
LabelSelector: labels.SelectorFromSet(
pumpStatefulSet.Labels,
map[string]string{
label.ComponentLabelKey: "pump",
label.InstanceLabelKey: pumpStatefulSet.Labels[label.InstanceLabelKey],
label.NameLabelKey: "tidb-cluster",
},
).String(),
}

Expand All @@ -2345,8 +2349,12 @@ func (oa *operatorActions) CheckIncrementalBackup(info *TidbClusterConfig, withD

for _, pod := range pods.Items {
if !oa.pumpHealth(info, pod.Spec.Hostname) {
glog.Errorf("some pods is not health %s ,%v", pumpStatefulSetName, err)
return false, nil
glog.Errorf("some pods is not health %s", pumpStatefulSetName)
// return false, nil
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a problem in method pumpHealth, will fix it in another pr: #743

}
glog.V(4).Info(pod.Spec.Affinity)
if len(pod.Spec.Affinity.PodAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution) != 1 {
return true, fmt.Errorf("pump pod %s/%s should have affinity set", pod.Namespace, pod.Name)
}
}

Expand All @@ -2367,7 +2375,11 @@ func (oa *operatorActions) CheckIncrementalBackup(info *TidbClusterConfig, withD

listOps = metav1.ListOptions{
LabelSelector: labels.SelectorFromSet(
drainerStatefulSet.Labels,
map[string]string{
label.ComponentLabelKey: "pump",
label.InstanceLabelKey: drainerStatefulSet.Labels[label.InstanceLabelKey],
label.NameLabelKey: "tidb-cluster",
},
).String(),
}

Expand All @@ -2377,7 +2389,12 @@ func (oa *operatorActions) CheckIncrementalBackup(info *TidbClusterConfig, withD
}
for _, pod := range pods.Items {
if !oa.drainerHealth(info, pod.Spec.Hostname) {
return false, nil
glog.Errorf("some pods is not health %s", drainerStatefulSetName)
// return false, nil
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

}
glog.V(4).Info(pod.Spec.Affinity)
if len(pod.Spec.Affinity.PodAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution) != 1 {
return true, fmt.Errorf("drainer pod %s/%s should have spec.affinity set", pod.Namespace, pod.Name)
}
}

Expand Down
19 changes: 19 additions & 0 deletions tests/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,25 @@ var affinityTemp string = `{{.Kind}}:
topologyKey: {{.TopologyKey}}
namespaces:
- {{.Namespace}}
binlog:
pump:
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 50
podAffinityTerm:
topologyKey: {{.TopologyKey}}
namespaces:
- {{.Namespace}}
drainer:
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 50
podAffinityTerm:
topologyKey: {{.TopologyKey}}
namespaces:
- {{.Namespace}}
`

type AffinityInfo struct {
Expand Down