Fix: return error instead of os.Exit when something goes wrong

This commit is contained in:
sanposhiho 2021-09-03 21:25:00 +09:00
parent e4c795168b
commit f80ddac1bc

View File

@ -475,33 +475,34 @@ 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") klog.ErrorS(err, "Failed OS init")
// ACTION REQUIRED: Exit code changed from 255 to 1 return err
os.Exit(1)
} }
if err := opts.Complete(); err != nil { if err := opts.Complete(); err != nil {
klog.ErrorS(err, "Failed complete") klog.ErrorS(err, "Failed complete")
// ACTION REQUIRED: Exit code changed from 255 to 1 return err
os.Exit(1)
} }
if err := opts.Validate(); err != nil { if err := opts.Validate(); err != nil {
klog.ErrorS(err, "Failed validate") klog.ErrorS(err, "Failed validate")
// ACTION REQUIRED: Exit code changed from 255 to 1 return err
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
}, },
SilenceUsage: true,
SilenceErrors: true,
Args: func(cmd *cobra.Command, args []string) error { Args: func(cmd *cobra.Command, args []string) error {
for _, arg := range args { for _, arg := range args {
if len(arg) > 0 { if len(arg) > 0 {