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

daemons: name init functions and have one init #17616

Merged
merged 1 commit into from
Oct 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 17 additions & 11 deletions daemon/cmd/daemon_main.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,6 @@ var (
bootstrapStats = bootstrapStatistics{}
)

func init() {
RootCmd.SetFlagErrorFunc(func(_ *cobra.Command, e error) error {
time.Sleep(fatalSleep)
return e
})
logrus.RegisterExitHandler(func() {
time.Sleep(fatalSleep)
},
)
}

// Execute sets up gops, installs the cleanup signal handler and invokes
// the root command. This function only returns when an interrupt
// signal has been received. This is intended to be called by main.main().
Expand All @@ -165,6 +154,23 @@ func skipInit(basePath string) bool {
}

func init() {
setupSleepBeforeFatal()
initializeFlags()
registerBootstrapMetrics()
}

func setupSleepBeforeFatal() {
RootCmd.SetFlagErrorFunc(func(_ *cobra.Command, e error) error {
time.Sleep(fatalSleep)
return e
})
logrus.RegisterExitHandler(func() {
time.Sleep(fatalSleep)
},
)
}

func initializeFlags() {
if skipInit(path.Base(os.Args[0])) {
log.Debug("Skipping preparation of cilium-agent environment")
return
Expand Down
2 changes: 1 addition & 1 deletion daemon/cmd/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ var (
metricBootstrapTimes prometheus.ObserverVec
)

func init() {
func registerBootstrapMetrics() {
metricBootstrapTimes = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: metrics.Namespace,
Subsystem: metrics.SubsystemAgent,
Expand Down