Skip to content

Commit

Permalink
*: try leader by label
Browse files Browse the repository at this point in the history
  • Loading branch information
acekingke committed Sep 8, 2023
1 parent d170120 commit 700465f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
12 changes: 12 additions & 0 deletions internal/pod_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,15 @@ func (p *PodExecutor) CloseXenonSemiCheck(namespace, podName string) error {
}
return nil
}

func (p *PodExecutor) XenonTryLeader(namespace, podName string) error {
cmd := []string{"xenoncli", "raft", "trytoleader"}
_, stderr, err := p.Exec(namespace, podName, "xenon", cmd...)
if err != nil {
return err
}
if len(stderr) != 0 {
return fmt.Errorf("run command %s in xenon failed: %s", cmd, stderr)
}
return nil
}
25 changes: 25 additions & 0 deletions mysqlcluster/syncer/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ func (s *StatusSyncer) Sync(ctx context.Context) (syncer.SyncResult, error) {
}
continue
}
if err := s.TryLeader(ctx, &pod); err != nil {
s.log.Error(err, "failed to Try leader", "pod", pod.Name, "namespace", pod.Namespace)
}
for _, cond := range pod.Status.Conditions {
switch cond.Type {
case corev1.ContainersReady:
Expand Down Expand Up @@ -789,3 +792,25 @@ func (s *StatusSyncer) DoRoRebuild(ctx context.Context, pod *corev1.Pod, items [
}
return nil
}

func (s *StatusSyncer) TryLeader(ctx context.Context, pod *corev1.Pod) error {
if pod.ObjectMeta.Labels == nil || len(pod.ObjectMeta.Labels[utils.LabelTryLeader]) == 0 {
return nil
}
// 1. close the xenon's SemiCheck.
executor, err := internal.NewPodExecutor()
if err != nil {
return err
}

err = executor.XenonTryLeader(s.Namespace, pod.Name)
s.log.Info("the xenon's tryleader", "pod", pod.Name)
if err != nil {
return err
}
delete(pod.ObjectMeta.Labels, utils.LabelTryLeader)
if err := s.cli.Update(ctx, pod); err != nil {
return err
}
return nil
}
1 change: 1 addition & 0 deletions utils/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ const (
const LableRebuild = "rebuild"
const LabelRebuildFrom = "rebuild-from"
const LabelMaintain = "maintain"
const LabelTryLeader = "tryleader"

// XenonHttpUrl is a http url corresponding to the xenon instruction.
type XenonHttpUrl string
Expand Down

0 comments on commit 700465f

Please sign in to comment.