-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
53 lines (40 loc) · 1.34 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
package main
import (
"flag"
"os"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/component-base/logs"
"k8s.io/klog/v2"
basecmd "sigs.k8s.io/custom-metrics-apiserver/pkg/cmd"
// this is the path to our provider
ackbarProvider "bespinian.io/ackbar-adapter/provider"
)
type AckbarAdapter struct {
basecmd.AdapterBase
// the message printed on startup
Message string
// The URL for the ackbar instance to use for metrics
AckbarURL string
}
func main() {
logs.InitLogs()
defer logs.FlushLogs()
// initialize the flags, with one custom flag for the message and one for the URL of ackbar
cmd := &AckbarAdapter{}
cmd.Flags().StringVar(&cmd.Message, "msg", "starting adapter...", "startup message")
cmd.Flags().StringVar(&cmd.AckbarURL, "ackbar-url", "", "The URL of the ackbar instance to use for metrics")
// make sure you get the klog flags
logs.AddGoFlags(flag.CommandLine)
cmd.Flags().AddGoFlagSet(flag.CommandLine)
cmd.Flags().Parse(os.Args)
if cmd.AckbarURL == "" {
klog.Fatalf("ackbar URL not configured. Please set command line flag --ackbar-url")
}
provider := ackbarProvider.NewProvider(cmd.AckbarURL)
cmd.WithExternalMetrics(provider)
klog.Infof("ackbar URL configured as %s", cmd.AckbarURL)
klog.Infof(cmd.Message)
if err := cmd.Run(wait.NeverStop); err != nil {
klog.Fatalf("unable to run custom metrics adapter: %v", err)
}
}