Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 1984047: Do not use klog.Fatal #477

Merged
merged 2 commits into from
Jul 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions pkg/cmd/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,36 +69,36 @@ func NewGather() *cobra.Command {
func runGather(operator *controller.GatherJob, cfg *controllercmd.ControllerCommandConfig) func(cmd *cobra.Command, args []string) {
return func(cmd *cobra.Command, args []string) {
if configArg := cmd.Flags().Lookup("config").Value.String(); len(configArg) == 0 {
klog.Fatalf("error: --config is required")
klog.Exit("error: --config is required")
}
unstructured, _, _, err := cfg.Config()
if err != nil {
klog.Fatal(err)
klog.Exit(err)
}
cont, err := config.LoadConfig(operator.Controller, unstructured.Object, config.ToDisconnectedController)
if err != nil {
klog.Fatal(err)
klog.Exit(err)
}
operator.Controller = cont

var clientConfig *rest.Config
if kubeConfigPath := cmd.Flags().Lookup("kubeconfig").Value.String(); len(kubeConfigPath) > 0 {
kubeConfigBytes, err := ioutil.ReadFile(kubeConfigPath) //nolint: govet
if err != nil {
klog.Fatal(err)
klog.Exit(err)
}
kubeConfig, err := clientcmd.NewClientConfigFromBytes(kubeConfigBytes)
if err != nil {
klog.Fatal(err)
klog.Exit(err)
}
clientConfig, err = kubeConfig.ClientConfig()
if err != nil {
klog.Fatal(err)
klog.Exit(err)
}
} else {
clientConfig, err = rest.InClusterConfig()
if err != nil {
klog.Fatal(err)
klog.Exit(err)
}
}
protoConfig := rest.CopyConfig(clientConfig)
Expand All @@ -108,7 +108,7 @@ func runGather(operator *controller.GatherJob, cfg *controllercmd.ControllerComm
ctx, cancel := context.WithTimeout(context.Background(), operator.Interval)
err = operator.Gather(ctx, clientConfig, protoConfig)
if err != nil {
klog.Fatal(err)
klog.Error(err)
}
cancel()
os.Exit(0)
Expand All @@ -125,17 +125,17 @@ func runOperator(operator *controller.Operator, cfg *controllercmd.ControllerCom
serviceability.StartProfiler()

if configArg := cmd.Flags().Lookup("config").Value.String(); len(configArg) == 0 {
klog.Fatalf("error: --config is required")
klog.Exit("error: --config is required")
}

unstructured, operatorConfig, configBytes, err := cfg.Config()
if err != nil {
klog.Fatal(err)
klog.Exit(err)
}

startingFileContent, observedFiles, err := cfg.AddDefaultRotationToConfig(operatorConfig, configBytes)
if err != nil {
klog.Fatal(err)
klog.Exit(err)
}

// if the service CA is rotated, we want to restart
Expand Down Expand Up @@ -164,7 +164,7 @@ func runOperator(operator *controller.Operator, cfg *controllercmd.ControllerCom
WithServer(operatorConfig.ServingInfo, operatorConfig.Authentication, operatorConfig.Authorization).
WithRestartOnChange(exitOnChangeReactorCh, startingFileContent, observedFiles...)
if err := builder.Run(ctx2, unstructured); err != nil {
klog.Fatal(err)
klog.Error(err)
}
}
}