forked from rancher/prometheus-federator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
79 lines (64 loc) · 2.38 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
package main
import (
_ "embed"
"log"
"net/http"
_ "net/http/pprof"
"github.com/rancher/helm-project-operator/pkg/controllers/common"
"github.com/rancher/helm-project-operator/pkg/operator"
"github.com/rancher/prometheus-federator/pkg/version"
command "github.com/rancher/wrangler-cli"
_ "github.com/rancher/wrangler/pkg/generated/controllers/apiextensions.k8s.io"
_ "github.com/rancher/wrangler/pkg/generated/controllers/networking.k8s.io"
"github.com/rancher/wrangler/pkg/kubeconfig"
"github.com/spf13/cobra"
)
const (
// HelmAPIVersion is the spec.helmApiVersion corresponding to the embedded monitoring chart (rancher-project-monitoring)
HelmAPIVersion = "monitoring.cattle.io/v1alpha1"
// ReleaseName is the release name this operator uses to prefix releases and project release namespaces created on
// deploying the embedded monitoring chart (rancher-project-monitoring)
ReleaseName = "monitoring"
)
var (
// SystemNamespaces is the system namespaces scoped for the embedded monitoring chart (rancher-project-monitoring)
SystemNamespaces = []string{"kube-system", "cattle-monitoring-system", "cattle-dashboards"}
//go:embed bin/rancher-project-monitoring/rancher-project-monitoring.tgz.base64
base64TgzChart string
debugConfig command.DebugConfig
)
type PrometheusFederator struct {
// Note: all Project Operator are expected to provide these RuntimeOptions
common.RuntimeOptions
Kubeconfig string `usage:"Kubeconfig file"`
}
func (f *PrometheusFederator) Run(cmd *cobra.Command, args []string) error {
go func() {
// required to set up healthz and pprof handlers
log.Println(http.ListenAndServe("localhost:80", nil))
}()
debugConfig.MustSetupDebug()
cfg := kubeconfig.GetNonInteractiveClientConfig(f.Kubeconfig)
ctx := cmd.Context()
if err := operator.Init(ctx, f.Namespace, cfg, common.Options{
OperatorOptions: common.OperatorOptions{
HelmAPIVersion: HelmAPIVersion,
ReleaseName: ReleaseName,
SystemNamespaces: SystemNamespaces,
ChartContent: base64TgzChart,
Singleton: true, // indicates only one HelmChart can be registered per project defined
},
RuntimeOptions: f.RuntimeOptions,
}); err != nil {
return err
}
<-cmd.Context().Done()
return nil
}
func main() {
cmd := command.Command(&PrometheusFederator{}, cobra.Command{
Version: version.FriendlyVersion(),
})
cmd = command.AddDebug(cmd, &debugConfig)
command.Main(cmd)
}