Repository navigation
Expand file tree
/
Copy pathmain.go
More file actions
62 lines (52 loc) · 1.57 KB
/
Copy pathmain.go
File metadata and controls
62 lines (52 loc) · 1.57 KB
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
package main
import (
"context"
"log/slog"
"os"
"time"
apiclient "github.com/metal-stack/api/go/client"
apiv2 "github.com/metal-stack/api/go/metalstack/api/v2"
"github.com/metal-stack/metal-console/internal/console"
"github.com/kelseyhightower/envconfig"
"github.com/metal-stack/v"
)
func main() {
spec := &console.Specification{}
jsonHandler := slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelDebug})
log := slog.New(jsonHandler)
if err := envconfig.Process("METAL_CONSOLE", spec); err != nil {
log.Error("failed to read env config", "error", err)
os.Exit(1)
}
if err := spec.Parse(); err != nil {
log.Error("failed to parse configuration", "error", err)
os.Exit(1)
}
if spec.MetalAPIServerURL != "" {
apiv2client, err := apiclient.New(&apiclient.DialConfig{
BaseURL: spec.MetalAPIServerURL,
TokenFile: spec.TokenFile,
Log: log,
})
if err != nil {
log.Error("failed to create metal-apiserver v2 client", "error", err)
os.Exit(1)
}
// Ping apiserver every 5min
apiv2client.Ping(context.Background(), &apiclient.PingConfig{
ComponentType: apiv2.ComponentType_COMPONENT_TYPE_METAL_CONSOLE,
StartedAt: time.Now(),
Version: apiv2.Version{
Version: v.Version,
Revision: v.Revision,
GitSha1: v.GitSHA1,
BuildDate: v.BuildDate,
},
})
}
log.Info("metal-console", "version", v.V.String(), "port", spec.Port, "metal-apiserver", spec.MetalAPIServerURL)
if err := console.NewServer(log, spec).Run(); err != nil {
log.Error("unable to start console server", "error", err)
os.Exit(1)
}
}