mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
Fix: return error instead of os.Exit when something goes wrong
This commit is contained in:
parent
3a26b864f4
commit
b8ae016ee6
@ -79,15 +79,14 @@ suitable Node. Multiple different schedulers may be used within a cluster;
|
|||||||
kube-scheduler is the reference implementation.
|
kube-scheduler is the reference implementation.
|
||||||
See [scheduling](https://kubernetes.io/docs/concepts/scheduling-eviction/)
|
See [scheduling](https://kubernetes.io/docs/concepts/scheduling-eviction/)
|
||||||
for more information about scheduling and the kube-scheduler component.`,
|
for more information about scheduling and the kube-scheduler component.`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
if err := opts.Complete(&namedFlagSets); err != nil {
|
if err := opts.Complete(&namedFlagSets); err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "%v\n", err)
|
return fmt.Errorf("completes the remaining instantiation of the options: %w", err)
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
if err := runCommand(cmd, opts, registryOptions...); err != nil {
|
if err := runCommand(cmd, opts, registryOptions...); err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "%v\n", err)
|
return fmt.Errorf("run command: %w", err)
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
|
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 {
|
||||||
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
@ -32,6 +33,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
if err := runSchedulerCmd(); err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "failed to run scheduler command: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func runSchedulerCmd() error {
|
||||||
rand.Seed(time.Now().UnixNano())
|
rand.Seed(time.Now().UnixNano())
|
||||||
|
|
||||||
pflag.CommandLine.SetNormalizeFunc(cliflag.WordSepNormalizeFunc)
|
pflag.CommandLine.SetNormalizeFunc(cliflag.WordSepNormalizeFunc)
|
||||||
@ -42,6 +50,8 @@ func main() {
|
|||||||
defer logs.FlushLogs()
|
defer logs.FlushLogs()
|
||||||
|
|
||||||
if err := command.Execute(); err != nil {
|
if err := command.Execute(); err != nil {
|
||||||
os.Exit(1)
|
return fmt.Errorf("execute command: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user