This repository has been archived by the owner on Dec 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 48
/
debug.go
71 lines (59 loc) · 1.57 KB
/
debug.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"context"
"fmt"
"os"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/manager"
)
type startupInfo struct {
cfg *rest.Config
namespace string
signalHandler context.Context
}
type subCommand func(string, *rest.Config) (manager.Manager, error)
func startWebhookAndBootstrapperIfDebugFlagSet(info startupInfo) {
if isDebugFlagSet() {
log.Info("debug mode enabled")
log.Info("starting webhook and bootstrapper")
go startBootstrapperManager(info)
go startWebhookManager(info)
}
}
func isDebugFlagSet() bool {
debugFlag := os.Getenv("DEBUG_OPERATOR")
return debugFlag == "true"
}
func startBootstrapperManager(info startupInfo) {
startComponent("webhook-bootstrapper", info)
}
func startWebhookManager(info startupInfo) {
startComponent("webhook-server", info)
}
func startComponent(name string, info startupInfo) {
subCmd, err := getSubcommand(name)
if err != nil {
return
}
startSubCommand(name, subCmd, &info)
}
func getSubcommand(name string) (subCommand, error) {
subcmdFn, hasSubCommand := subcmdCallbacks[name]
if !hasSubCommand {
log.Error(errBadSubcmd, "unknown command", "command", "webhook-server")
return subcmdFn, errBadSubcmd
}
return subcmdFn, nil
}
func startSubCommand(name string, cmd subCommand, startInfo *startupInfo) {
mgr, err := cmd(startInfo.namespace, startInfo.cfg)
if err != nil {
log.Error(err, "")
os.Exit(1)
}
log.Info(fmt.Sprintf("starting manager '%s'", name))
if err := mgr.Start(startInfo.signalHandler); err != nil {
log.Error(err, "problem running manager")
os.Exit(1)
}
}