Skip to content

Commit

Permalink
fix: static route might lost during leader election
Browse files Browse the repository at this point in the history
  • Loading branch information
oilbeater committed Oct 31, 2019
1 parent 5d5ac30 commit a2e24de
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
7 changes: 3 additions & 4 deletions pkg/controller/election.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,12 @@ func setupLeaderElection(config *leaderElectionConfig) *leaderelection.LeaderEle
}

var err error
ttl := 8 * time.Second

elector, err = leaderelection.NewLeaderElector(leaderelection.LeaderElectionConfig{
Lock: &lock,
LeaseDuration: ttl,
RenewDeadline: ttl / 2,
RetryPeriod: ttl / 4,
LeaseDuration: 15 * time.Second,
RenewDeadline: 10 * time.Second,
RetryPeriod: 2 * time.Second,

Callbacks: callbacks,
})
Expand Down
11 changes: 8 additions & 3 deletions pkg/controller/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,11 +457,16 @@ func (c *Controller) handleAddPod(key string) error {

raw, _ := json.Marshal(pod.Annotations)
patchPayload := fmt.Sprintf(patchPayloadTemplate, op, raw)
_, err = c.config.KubeClient.CoreV1().Pods(namespace).Patch(name, types.JSONPatchType, []byte(patchPayload))
if err != nil {
if _, err = c.config.KubeClient.CoreV1().Pods(namespace).Patch(name, types.JSONPatchType, []byte(patchPayload)); err != nil {
klog.Errorf("patch pod %s/%s failed %v", name, namespace, err)
return err
}
return err

// In case update event might lost during leader election
if pod.Spec.NodeName != "" {
return c.handleUpdatePod(key)
}
return nil
}

func (c *Controller) handleAddIpPoolPod(key string) error {
Expand Down

0 comments on commit a2e24de

Please sign in to comment.