mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-06 16:06:51 +00:00
kubelet: Add --exit-on-lock-contention flag
This patch adds the --exit-on-lock-contention flag, which must be used in conjunction with the --lock-file flag. When provided, it causes the kubelet to wait for inotify events for that lock file. When an 'open' event is received, the kubelet will exit.
This commit is contained in:
@@ -19,6 +19,7 @@ package app
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"net"
|
||||
@@ -289,11 +290,22 @@ func Run(s *options.KubeletServer, kcfg *KubeletConfig) error {
|
||||
}
|
||||
|
||||
func run(s *options.KubeletServer, kcfg *KubeletConfig) (err error) {
|
||||
if s.ExitOnLockContention && s.LockFilePath == "" {
|
||||
return errors.New("cannot exit on lock file contention: no lock file specified")
|
||||
}
|
||||
|
||||
done := make(chan struct{})
|
||||
if s.LockFilePath != "" {
|
||||
glog.Infof("aquiring lock on %q", s.LockFilePath)
|
||||
if err := flock.Acquire(s.LockFilePath); err != nil {
|
||||
return fmt.Errorf("unable to aquire file lock on %q: %v", s.LockFilePath, err)
|
||||
}
|
||||
if s.ExitOnLockContention {
|
||||
glog.Infof("watching for inotify events for: %v", s.LockFilePath)
|
||||
if err := watchForLockfileContention(s.LockFilePath, done); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
if c, err := configz.New("componentconfig"); err == nil {
|
||||
c.Set(s.KubeletConfiguration)
|
||||
@@ -383,8 +395,8 @@ func run(s *options.KubeletServer, kcfg *KubeletConfig) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
// run forever
|
||||
select {}
|
||||
<-done
|
||||
return nil
|
||||
}
|
||||
|
||||
// InitializeTLS checks for a configured TLSCertFile and TLSPrivateKeyFile: if unspecified a new self-signed
|
||||
|
||||
Reference in New Issue
Block a user