-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
59 lines (47 loc) · 1.88 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
package main
import (
"flag"
"os"
"k8s.io/klog"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/component-base/logs"
basecmd "github.com/kubernetes-incubator/custom-metrics-apiserver/pkg/cmd"
"github.com/kubernetes-incubator/custom-metrics-apiserver/pkg/provider"
myprovider "github.com/sarweshsuman/elastic-worker-custommetrics-adapter/pkg/provider"
)
type ElasticWorkerMetricsAdapter struct {
basecmd.AdapterBase
myprovider.RedisConfigs
Message string
}
func main() {
logs.InitLogs()
defer logs.FlushLogs()
cmd := &ElasticWorkerMetricsAdapter{}
cmd.Flags().StringVar(&cmd.Message, "msg", "starting ElasticWorkerMetrics adapter...", "startup message")
cmd.Flags().StringVar(&cmd.Hostname, "redishost", "localhost", "redis hostname")
cmd.Flags().StringVar(&cmd.Port, "redisport", "6379", "redis port")
cmd.Flags().IntVar(&cmd.Database, "redisdb", 0, "Redis database")
cmd.Flags().StringVar(&cmd.Password, "redispassword", "", "Redis password")
cmd.Flags().AddGoFlagSet(flag.CommandLine) // make sure you get the klog flags
cmd.Flags().Parse(os.Args)
providerInstance := cmd.makeProviderOrDie()
cmd.WithCustomMetrics(providerInstance)
klog.Infof(cmd.Message)
if err := cmd.Run(wait.NeverStop); err != nil {
klog.Fatalf("unable to run custom metrics adapter: %v", err)
}
}
func (adapter *ElasticWorkerMetricsAdapter) makeProviderOrDie() provider.CustomMetricsProvider {
client, err := adapter.DynamicClient()
if err != nil {
klog.Fatalf("unable to construct dynamic client: %v", err)
}
mapper, err := adapter.RESTMapper()
if err != nil {
klog.Fatalf("unable to construct discovery REST mapper: %v", err)
}
providerInstance := myprovider.NewElasticWorkerMetricsProvider(client, mapper, adapter.RedisConfigs)
providerInstance.Run()
return providerInstance
}