generated from vshn/go-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sos_command.go
69 lines (60 loc) · 1.76 KB
/
sos_command.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
package main
import (
"github.com/urfave/cli/v2"
"github.com/vshn/exoscale-metrics-collector/src/sos"
db "github.com/vshn/exoscale-metrics-collector/src/database"
"github.com/vshn/exoscale-metrics-collector/src/exoscale"
k8s "github.com/vshn/exoscale-metrics-collector/src/kubernetes"
ctrl "sigs.k8s.io/controller-runtime"
)
const (
objectStorageName = "objectstorage"
)
type objectStorageCommand struct {
clusterFilePath string
}
func NewCommand() *cli.Command {
command := &objectStorageCommand{}
return &cli.Command{
Name: objectStorageName,
Usage: "Get metrics from object storage service",
Action: command.execute,
Flags: []cli.Flag{
&cli.StringFlag{Name: "path-to-cluster-file", Aliases: []string{"clusters"}, Required: true, TakesFile: true,
Usage: "File containing a list of clusters with the format server=token..",
Destination: &command.clusterFilePath,
},
},
}
}
func (c *objectStorageCommand) execute(ctx *cli.Context) error {
log := AppLogger(ctx).WithName(objectStorageName)
ctrl.SetLogger(log)
log.Info("Loading Exoscale API credentials")
accessKey, secretKey, err := exoscale.LoadAPICredentials()
if err != nil {
return err
}
log.Info("Creating Exoscale client")
exoscaleClient, err := exoscale.InitClient(accessKey, secretKey)
if err != nil {
return err
}
log.Info("Reading input cluster file configuration")
clusters, err := k8s.ReadConf(c.clusterFilePath)
if err != nil {
return err
}
log.Info("Creating k8s clients")
err = k8s.InitClients(ctx.Context, clusters)
if err != nil {
return err
}
log.Info("Loading database URL")
databaseInstance, err := db.Configure()
if err != nil {
return err
}
o := sos.NewObjectStorage(exoscaleClient, clusters, databaseInstance)
return o.Execute(ctx.Context)
}