This repository has been archived by the owner on Oct 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.go
80 lines (69 loc) · 1.9 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
package main
import (
"context"
"flag"
"fmt"
"log/slog"
"os"
"runtime/debug"
tea "github.com/charmbracelet/bubbletea"
"github.com/mjlshen/mirrosa/pkg/mirrosa"
"github.com/mjlshen/mirrosa/pkg/tui"
)
func main() {
f := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
clusterId := f.String("cluster-id", "", "OCM internal or external cluster id")
interactive := f.Bool("i", false, "run in an interactive exploratory mode")
verbose := f.Bool("v", false, "enable verbose logging")
f.Parse(os.Args[1:])
opts := slog.HandlerOptions{}
if *verbose {
opts.AddSource = true
opts.Level = slog.LevelDebug
}
logger := slog.New(slog.NewTextHandler(os.Stdout, &opts))
if info, ok := debug.ReadBuildInfo(); ok {
logger.Debug(fmt.Sprintf("Go Version: %s", info.GoVersion))
for _, setting := range info.Settings {
if setting.Key == "vcs.revision" {
logger.Debug(fmt.Sprintf("Git SHA: %s", setting.Value))
}
if setting.Key == "vcs.time" {
logger.Debug(fmt.Sprintf("From: %s", setting.Value))
}
}
}
if *interactive {
p := tea.NewProgram(tui.InitModel())
if _, err := p.Run(); err != nil {
logger.Error(err.Error())
}
os.Exit(0)
}
if *clusterId == "" {
logger.Error("cluster id must not be empty")
os.Exit(1)
}
m, err := mirrosa.NewRosaClient(context.Background(), logger, *clusterId)
if err != nil {
logger.Error(err.Error())
os.Exit(1)
}
logger.Debug("cluster info from OCM", "cluster info", *m.ClusterInfo)
logger.Info("who's the fairest of them all", "cluster", m.ClusterInfo.Name)
if err := m.ValidateComponents(context.TODO(),
m.NewVpc(),
m.NewDhcpOptions(),
m.NewSecurityGroup(),
m.NewVpcEndpointService(),
m.NewPublicHostedZone(),
m.NewPrivateHostedZone(),
m.NewApiLoadBalancer(),
m.NewInstances(),
); err != nil {
logger.Error(err.Error())
os.Exit(1)
}
logger.Info(fmt.Sprintf("%s is the fairest of them all!", m.ClusterInfo.Name))
os.Exit(0)
}