-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathmain.go
92 lines (73 loc) · 2.48 KB
/
main.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package main
import (
"context"
goflag "flag"
"fmt"
"math/rand"
"os"
"time"
"github.com/linode/linode-cloud-controller-manager/cloud/linode"
"github.com/linode/linode-cloud-controller-manager/sentry"
"github.com/spf13/pflag"
utilflag "k8s.io/apiserver/pkg/util/flag"
"k8s.io/apiserver/pkg/util/logs"
"k8s.io/kubernetes/cmd/cloud-controller-manager/app"
_ "k8s.io/kubernetes/pkg/client/metrics/prometheus" // for client metric registration
_ "k8s.io/kubernetes/pkg/version/prometheus" // for version metric registration
)
const (
sentryDSNVariable = "SENTRY_DSN"
sentryEnvironmentVariable = "SENTRY_ENVIRONMENT"
sentryReleaseVariable = "SENTRY_RELEASE"
)
func initializeSentry() {
var (
dsn string
environment string
release string
ok bool
)
if dsn, ok = os.LookupEnv(sentryDSNVariable); !ok {
fmt.Printf("%s not set, not initializing Sentry\n", sentryDSNVariable)
return
}
if environment, ok = os.LookupEnv(sentryEnvironmentVariable); !ok {
fmt.Printf("%s not set, not initializing Sentry\n", sentryEnvironmentVariable)
return
}
if release, ok = os.LookupEnv(sentryReleaseVariable); !ok {
fmt.Printf("%s not set, defaulting to unknown", sentryReleaseVariable)
release = "unknown"
}
if err := sentry.Initialize(dsn, environment, release); err != nil {
fmt.Printf("error initializing sentry: %s\n", err.Error())
return
}
fmt.Print("Sentry successfully initialized\n")
}
func main() {
fmt.Printf("Linode Cloud Controller Manager starting up\n")
initializeSentry()
ctx := sentry.SetHubOnContext(context.Background())
rand.Seed(time.Now().UTC().UnixNano())
command := app.NewCloudControllerManagerCommand()
// Add Linode-specific flags
command.Flags().BoolVar(&linode.Options.LinodeGoDebug, "linodego-debug", false, "enables debug output for the LinodeAPI wrapper")
// Make the Linode-specific CCM bits aware of the kubeconfig flag
linode.Options.KubeconfigFlag = command.Flags().Lookup("kubeconfig")
if linode.Options.KubeconfigFlag == nil {
msg := "kubeconfig missing from CCM flag set"
sentry.CaptureError(ctx, fmt.Errorf(msg))
fmt.Fprintf(os.Stderr, "kubeconfig missing from CCM flag set"+"\n")
os.Exit(1)
}
pflag.CommandLine.SetNormalizeFunc(utilflag.WordSepNormalizeFunc)
pflag.CommandLine.AddGoFlagSet(goflag.CommandLine)
logs.InitLogs()
defer logs.FlushLogs()
if err := command.Execute(); err != nil {
sentry.CaptureError(ctx, err)
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
}
}