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 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 addon that provides cluster DNS for these cluster IPs. The user must create a service
with the apiserver API to configure the proxy.`, 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() verflag.PrintAndExitIfRequested()
cliflag.PrintFlags(cmd.Flags()) cliflag.PrintFlags(cmd.Flags())
if err := initForOS(opts.WindowsService); err != nil { if err := initForOS(opts.WindowsService); err != nil {
klog.ErrorS(err, "Failed OS init") return fmt.Errorf("failed os init: %w", err)
// ACTION REQUIRED: Exit code changed from 255 to 1
os.Exit(1)
} }
if err := opts.Complete(); err != nil { if err := opts.Complete(); err != nil {
klog.ErrorS(err, "Failed complete") return fmt.Errorf("failed complete: %w", err)
// ACTION REQUIRED: Exit code changed from 255 to 1
os.Exit(1)
} }
if err := opts.Validate(); err != nil { if err := opts.Validate(); err != nil {
klog.ErrorS(err, "Failed validate") return fmt.Errorf("failed validate: %w", err)
// ACTION REQUIRED: Exit code changed from 255 to 1
os.Exit(1)
} }
if err := opts.Run(); err != nil { if err := opts.Run(); err != nil {
klog.ErrorS(err, "Error running ProxyServer") klog.ErrorS(err, "Error running ProxyServer")
os.Exit(1) return err
} }
return nil
}, },
Args: func(cmd *cobra.Command, args []string) error { Args: func(cmd *cobra.Command, args []string) error {
for _, arg := range args { for _, arg := range args {