Repository navigation
monitor: support affinity and topologySpreadConstraints for TidbMonitor - #7179
time-and-fate wants to merge 2 commits into
Conversation
…bDashboard/TidbNGMonitoring The label selector of a pod topology spread constraint is built from the base labels of the CR kind the component belongs to. Only TidbCluster and DMCluster were handled, so setting topologySpreadConstraints on TidbDashboard or TidbNGMonitoring assigned to a nil map and crashed tidb-controller-manager. Add the two missing kinds and the component label value of TidbDashboard, and cover the conversion of every kind that uses the accessor with unit tests.
TidbMonitor pods carry no scheduling constraints, so replicas of one monitor can be scheduled to the same node or the same zone. Add two optional fields to TidbMonitorSpec and propagate them to the monitor StatefulSet pod template: - affinity is passed through as is. - topologySpreadConstraints uses the same type as TidbCluster. Constraints are always DoNotSchedule and the labelSelector is generated for the instance of each monitor shard, so replicas are spread within a shard. Both fields have no default. When they are unset the rendered pod template is unchanged, so existing monitors are not rolled by the upgrade. The conversion loop of componentAccessorImpl.TopologySpreadConstraints() is extracted into buildPodTopologySpreadConstraints(), which is shared with the new TidbMonitor.PodTopologySpreadConstraints().
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
/retest |
1 similar comment
|
/retest |
|
@time-and-fate: The following tests failed, say
Full PR test history. Your PR dashboard. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
What problem does this PR solve?
TidbMonitorhas no way to control where monitoring replicas are scheduled. The monitor pods carry neitheraffinitynortopologySpreadConstraints, so whenreplicasis greater than 1 the replicas of one monitor can land on the same node or in the same zone and share a single failure domain.TidbClusterandDMClusteralready expose both fields. This PR adds them toTidbMonitorwith the same types and semantics.While reusing the topology spread conversion for
TidbMonitor, I found that settingtopologySpreadConstraintsonTidbDashboardorTidbNGMonitoringmakes tidb-controller-manager panic withassignment to entry in nil map: the label selector of a constraint is built from the base labels of the CR kind, and those two kinds were not handled. This PR fixes it as well.What is changed and how does it work?
TidbMonitorSpec, next tonodeSelectorandtolerations:affinity(core/v1 Affinity) is passed through to the monitor StatefulSet pod template as is.topologySpreadConstraintsuses the same type asTidbCluster.whenUnsatisfiableis alwaysDoNotScheduleand thelabelSelectoris generated by the operator, so a constraint only needstopologyKey. The selector matches the instance label of the monitor shard, i.e. replicas are spread within a shard.componentAccessorImpl.TopologySpreadConstraints()is extracted intobuildPodTopologySpreadConstraints(), which is now shared with the newTidbMonitor.PodTopologySpreadConstraints().TidbDashboardandTidbNGMonitoringget their base labels (label.NewTiDBDashboard()/label.NewTiDBNGMonitoring()) when building the selector, andTidbDashboardgets its component label value.Notes for the documentation PR:
Pending; soft requirements can be expressed withaffinity.whenUnsatisfiable,labelSelector,nodeTaintsPolicyandmatchLabelKeysare not part of the type. Unknown fields are pruned by the API server (recentkubectlreports an error in its default strict mode).persistent: true, a volume that is already bound to one zone pins its replica to that zone. Check the storage class before adding a zone constraint to an existing monitor.Code changes
Tests
Unit tests:
pkg/apis/pingcap/v1alpha1: the generated constraints of every kind that uses the accessor (TidbCluster,DMClusterincl. discovery,TidbNGMonitoring,TidbDashboard), thematchLabelsoverride, andTidbMonitor.PodTopologySpreadConstraints()for shard 0 and shard N.pkg/monitor/monitor: the monitor StatefulSet getsaffinityand the constraints (selector equals the pod labels), and each shard gets its own selector.pkg/manager/tidbdashboard,pkg/manager/tidbngmonitoring: the StatefulSet carries the constraints.E2E test:
TidbMonitor topology spread constraintintests/e2e/tidbcluster/tidbcluster.go— two replicas with a zone constraint must end up in different zones. Verified locally viahack/e2e.sh -- --ginkgo.focus='TidbMonitor topology spread constraint'(1 Passed | 0 Failed | 0 Flaked).Manual test on kind (operator built from this branch, 3 workers in 2 zones):
affinity/topologySpreadConstraints.shards: 2withreplicas: 2: each shard gets its own selector and spreads over both zones.affinity.nodeAffinityshows up in the template and limits the nodes as expected.AdvancedStatefulSet=true: thestatefulsets.apps.pingcap.comobject and the pods carry the constraints.Side effects
Related changes
Release Notes
Please refer to Release Notes Language Style Guide before writing the release note.
Summary by CodeRabbit