-
Notifications
You must be signed in to change notification settings - Fork 499
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
Make evict leader scheduler compatitable #1831
Changes from 5 commits
5a548ef
2ddb902
2493ca8
ac84b01
c60a2fc
98a23e9
d205605
88a935c
dcbfd90
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,6 +89,7 @@ func (tku *tikvUpgrader) Upgrade(tc *v1alpha1.TidbCluster, oldSet *apps.Stateful | |
|
||
if controller.PodWebhookEnabled { | ||
setUpgradePartition(newSet, 0) | ||
return nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto. |
||
} | ||
|
||
setUpgradePartition(newSet, *oldSet.Spec.UpdateStrategy.RollingUpdate.Partition) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,23 +14,29 @@ | |
package pod | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"strings" | ||
|
||
"k8s.io/apimachinery/pkg/util/sets" | ||
|
||
"github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1" | ||
"github.com/pingcap/tidb-operator/pkg/pdapi" | ||
"github.com/pingcap/tidb-operator/pkg/webhook/util" | ||
admission "k8s.io/api/admission/v1beta1" | ||
core "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/util/sets" | ||
"k8s.io/klog" | ||
) | ||
|
||
const ( | ||
tikvNotBootstrapped = `TiKV cluster not bootstrapped, please start TiKV first"` | ||
tikvNotBootstrapped = `TiKV cluster not bootstrapped, please start TiKV first"` | ||
evictSchedulerLeader = "evict-leader-scheduler" | ||
) | ||
|
||
// Payload only used to unmarshal the data from pdapi | ||
type Payload struct { | ||
StoreIdRanges map[string]interface{} `json:"store-id-ranges"` | ||
} | ||
|
||
func (pc *PodAdmissionControl) admitCreateTiKVPod(pod *core.Pod, tc *v1alpha1.TidbCluster, pdClient pdapi.PDClient) *admission.AdmissionResponse { | ||
|
||
name := pod.Name | ||
|
@@ -61,10 +67,9 @@ func (pc *PodAdmissionControl) admitCreateTiKVPod(pod *core.Pod, tc *v1alpha1.Ti | |
return util.ARSuccess() | ||
} | ||
|
||
schedulerIds := sets.String{} | ||
for _, s := range evictLeaderSchedulers { | ||
id := strings.Split(s, "-")[3] | ||
schedulerIds.Insert(id) | ||
schedulerIds, err := filterLeaderEvictScheduler(evictLeaderSchedulers, pdClient) | ||
if err != nil { | ||
return util.ARFail(err) | ||
} | ||
|
||
// if the pod which is going to be created already have a store and was in evictLeaderSchedulers, | ||
|
@@ -84,3 +89,37 @@ func (pc *PodAdmissionControl) admitCreateTiKVPod(pod *core.Pod, tc *v1alpha1.Ti | |
|
||
return util.ARSuccess() | ||
} | ||
|
||
// This is method is to make compatible between old pdapi version and 4.0 pdapi version. | ||
Yisaer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// To get more detail, see: https://github.com/pingcap/tidb-operator/pull/1831 | ||
func filterLeaderEvictScheduler(evictLeaderSchedulers []string, pdClient pdapi.PDClient) (sets.String, error) { | ||
schedulerIds := sets.String{} | ||
if len(evictLeaderSchedulers) == 1 && evictLeaderSchedulers[0] == evictSchedulerLeader { | ||
c, err := pdClient.GetConfig() | ||
if err != nil { | ||
return schedulerIds, err | ||
} | ||
if c.Schedule != nil { | ||
if c.Schedule.SchedulersPayload == nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it's nil, why still need to continue to the following codes? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not necessary, just solve the nil or empty payload with the same logic. |
||
c.Schedule.SchedulersPayload = map[string]string{} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can just change to:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updatd, PTAL |
||
v, ok := c.Schedule.SchedulersPayload[evictSchedulerLeader] | ||
DanielZhangQD marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if ok { | ||
payload := &Payload{} | ||
err := json.Unmarshal([]byte(v), payload) | ||
if err != nil { | ||
return schedulerIds, err | ||
} | ||
for k := range payload.StoreIdRanges { | ||
schedulerIds.Insert(k) | ||
} | ||
} | ||
} | ||
} else { | ||
for _, s := range evictLeaderSchedulers { | ||
id := strings.Split(s, "-")[3] | ||
schedulerIds.Insert(id) | ||
} | ||
} | ||
return schedulerIds, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
During my test, I found the bug in upgrading and I fixed it.