Merge pull request #104750 from sanposhiho/fix/bug/proxy/defer-with-os-exit

Fix(kube-proxy): remove os.Exit from cobra.Command
This commit is contained in:
Kubernetes Prow Robot 2021-11-16 21:13:53 -08:00 committed by GitHub
commit 9dd8aad535
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -475,32 +475,28 @@ Service cluster IPs and ports are currently found through Docker-links-compatibl
environment variables specifying ports opened by the service proxy. There is an optional
addon that provides cluster DNS for these cluster IPs. The user must create a service
with the apiserver API to configure the proxy.`,
Run: func(cmd *cobra.Command, args []string) {
RunE: func(cmd *cobra.Command, args []string) error {
verflag.PrintAndExitIfRequested()
cliflag.PrintFlags(cmd.Flags())
if err := initForOS(opts.WindowsService); err != nil {
klog.ErrorS(err, "Failed OS init")
// ACTION REQUIRED: Exit code changed from 255 to 1
os.Exit(1)
return fmt.Errorf("failed os init: %w", err)
}
if err := opts.Complete(); err != nil {
klog.ErrorS(err, "Failed complete")
// ACTION REQUIRED: Exit code changed from 255 to 1
os.Exit(1)
return fmt.Errorf("failed complete: %w", err)
}
if err := opts.Validate(); err != nil {
klog.ErrorS(err, "Failed validate")
// ACTION REQUIRED: Exit code changed from 255 to 1
os.Exit(1)
return fmt.Errorf("failed validate: %w", err)
}
if err := opts.Run(); err != nil {
klog.ErrorS(err, "Error running ProxyServer")
os.Exit(1)
return err
}
return nil
},
Args: func(cmd *cobra.Command, args []string) error {
for _, arg := range args {