-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
94 lines (70 loc) · 2.13 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
93
94
package main
import (
"fmt"
"os"
"text/template"
"github.com/knadh/koanf"
"go.uber.org/zap"
)
type tctl struct {
logger *zap.Logger
config *koanf.Koanf
}
func main() {
k, err := initConfig()
if err != nil {
fmt.Println("Error when initializing config: ", err)
os.Exit(1)
}
var logger = initLogger()
tctl := tctl{
logger: logger,
config: k,
}
logger.Info("Generating endpoints")
vminsertUrls, vmselectUrls, err := tctl.TenantGen()
if err != nil {
tctl.logger.Error("Error when generating endpoints", zap.Error(err))
os.Exit(1)
}
tctl.logger.Debug("Showing vm tenant data on terminal")
tctl.RenderToTerminal(vminsertUrls, vmselectUrls)
if tctl.config.Bool("csv") {
tctl.RenderToCsv(vminsertUrls, vmselectUrls)
}
// Generate only endpoints and exit, no need to generate grafana datasource and docker-compose files
if !tctl.config.Bool("gen-endpoints") {
// vmselect endpoints for Grafana datasource file
ds := vmselectUrls
// vminsert endpoints for vminsert container in docker-compose file
dc := vminsertUrls
// Generate grafana datasource file
tctl.logger.Info("Generating grafana datasource file")
datasourceTmpl, err := template.ParseFiles("templates/datasource.tmpl")
if err != nil {
tctl.logger.Error("Failed to parse datasource template", zap.Error(err))
os.Exit(1)
}
datasourceFile, _ := os.Create("provisioning/datasources/datasource.yaml")
defer datasourceFile.Close()
err = datasourceTmpl.Execute(datasourceFile, ds)
if err != nil {
tctl.logger.Error("Failed to write to datasource file", zap.Error(err))
os.Exit(1)
}
// Generate docker compose file
tctl.logger.Info("Generating docker compose file")
dockercomposeTmpl, err := template.ParseFiles("templates/docker-compose.tmpl")
if err != nil {
tctl.logger.Error("Failed to parse docker-compose template", zap.Error(err))
os.Exit(1)
}
dockerComposeFile, _ := os.Create("docker-compose.yml")
defer dockerComposeFile.Close()
err = dockercomposeTmpl.Execute(dockerComposeFile, dc)
if err != nil {
tctl.logger.Error("Failed to write to docker-compose file", zap.Error(err))
os.Exit(1)
}
}
}