mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-11-02 11:18:16 +00:00
os exit when option is true
This commit is contained in:
@@ -91,6 +91,7 @@ const (
|
||||
// proxyRun defines the interface to run a specified ProxyServer
|
||||
type proxyRun interface {
|
||||
Run() error
|
||||
CleanupAndExit() error
|
||||
}
|
||||
|
||||
// Options contains everything necessary to create and run a proxy server.
|
||||
@@ -307,6 +308,11 @@ func (o *Options) Run() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if o.CleanupAndExit {
|
||||
return proxyServer.CleanupAndExit()
|
||||
}
|
||||
|
||||
o.proxyServer = proxyServer
|
||||
return o.runLoop()
|
||||
}
|
||||
@@ -497,7 +503,6 @@ type ProxyServer struct {
|
||||
Conntracker Conntracker // if nil, ignored
|
||||
ProxyMode string
|
||||
NodeRef *v1.ObjectReference
|
||||
CleanupAndExit bool
|
||||
CleanupIPVS bool
|
||||
MetricsBindAddress string
|
||||
EnableProfiling bool
|
||||
@@ -546,19 +551,10 @@ func createClients(config componentbaseconfig.ClientConnectionConfiguration, mas
|
||||
}
|
||||
|
||||
// Run runs the specified ProxyServer. This should never exit (unless CleanupAndExit is set).
|
||||
// TODO: At the moment, Run() cannot return a nil error, otherwise it's caller will never exit. Update callers of Run to handle nil errors.
|
||||
func (s *ProxyServer) Run() error {
|
||||
// To help debugging, immediately log version
|
||||
klog.Infof("Version: %+v", version.Get())
|
||||
// remove iptables rules and exit
|
||||
if s.CleanupAndExit {
|
||||
encounteredError := userspace.CleanupLeftovers(s.IptInterface)
|
||||
encounteredError = iptables.CleanupLeftovers(s.IptInterface) || encounteredError
|
||||
encounteredError = ipvs.CleanupLeftovers(s.IpvsInterface, s.IptInterface, s.IpsetInterface, s.CleanupIPVS) || encounteredError
|
||||
if encounteredError {
|
||||
return errors.New("encountered an error while tearing down rules")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// TODO(vmarmol): Use container config for this.
|
||||
var oomAdjuster *oom.OOMAdjuster
|
||||
@@ -704,3 +700,15 @@ func getConntrackMax(config kubeproxyconfig.KubeProxyConntrackConfiguration) (in
|
||||
}
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
// CleanupAndExit remove iptables rules and exit if success return nil
|
||||
func (s *ProxyServer) CleanupAndExit() error {
|
||||
encounteredError := userspace.CleanupLeftovers(s.IptInterface)
|
||||
encounteredError = iptables.CleanupLeftovers(s.IptInterface) || encounteredError
|
||||
encounteredError = ipvs.CleanupLeftovers(s.IpvsInterface, s.IptInterface, s.IpsetInterface, s.CleanupIPVS) || encounteredError
|
||||
if encounteredError {
|
||||
return errors.New("encountered an error while tearing down rules")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user