|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "flag" |
| 5 | + "fmt" |
| 6 | + "log" |
| 7 | + "net/http" |
| 8 | + _ "net/http/pprof" |
| 9 | + |
| 10 | + "github.com/Kindling-project/kindling/collector/pkg/metadata/kubernetes" |
| 11 | + "github.com/Kindling-project/kindling/collector/pkg/metadata/metaprovider/service" |
| 12 | +) |
| 13 | + |
| 14 | +func main() { |
| 15 | + authType := flag.String("authType", "serviceAccount", "AuthType describes the type of authentication to use for the K8s API, support 'kubeConfig' or 'serviceAccount'. ") |
| 16 | + kubeConfigPath := flag.String("kubeConfig", "/root/.kube/config", "kubeConfig describe the filePath to your kubeConfig,only used when authType is 'kubeConfig'") |
| 17 | + httpPort := flag.Int("http-port", 9504, "port describe which port will be used to expose data") |
| 18 | + enableFetchReplicaset := flag.Bool("enableFetchReplicaset", false, "controls whether to fetch ReplicaSet information. The default value is false. It should be enabled if the ReplicaSet is used to control pods in the third-party CRD except for Deployment.") |
| 19 | + logInterval := flag.Int("logInterval", 120, "Interval(Second) to show how many event mp received, default 120s") |
| 20 | + |
| 21 | + flag.Parse() |
| 22 | + |
| 23 | + config := &service.Config{ |
| 24 | + KubeAuthType: kubernetes.AuthType(*authType), |
| 25 | + KubeConfigDir: *kubeConfigPath, |
| 26 | + EnableFetchReplicaSet: *enableFetchReplicaset, |
| 27 | + LogInterval: *logInterval, |
| 28 | + } |
| 29 | + |
| 30 | + if mdw, err := service.NewMetaDataWrapper(config); err != nil { |
| 31 | + log.Fatalf("create MetaData Wrapper failed, err: %v", err) |
| 32 | + } else { |
| 33 | + http.HandleFunc("/listAndWatch", mdw.ListAndWatch) |
| 34 | + log.Printf("[http] service start at port: %d", *httpPort) |
| 35 | + log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", *httpPort), nil)) |
| 36 | + } |
| 37 | +} |
0 commit comments