-
Notifications
You must be signed in to change notification settings - Fork 3
/
preflight.go
53 lines (48 loc) · 1.1 KB
/
preflight.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
package main
import (
"flag"
"fmt"
"os"
"github.com/doddle/lander/pkg/endpoints"
"github.com/withmandala/go-log"
"k8s.io/client-go/kubernetes"
)
func envVarExists(key string) bool {
_, exists := os.LookupEnv(key)
return exists
}
// using flag.Visit, check if a flag was provided
// if not.. tell the user, print `-help` and bail
func checkRequredFlag() {
required := []string{}
seen := make(map[string]bool)
flag.Visit(func(f *flag.Flag) { seen[f.Name] = true })
for _, req := range required {
if !seen[req] {
fmt.Printf("ERROR: missing required flag: '-%s'\n-------------\n", req)
flag.PrintDefaults()
os.Exit(2)
}
}
}
func onStartup(logger *log.Logger) {
logger.Info("Startup: Prefetch endpoints & index icons")
clientSet, err := kubernetes.NewForConfig(kubeConfig)
if err != nil {
logger.Fatal(err)
}
_ = endpoints.ReallyAssemble(
logger,
clientSet,
*flagLanderAnnotationBase,
)
files, err := os.ReadDir("./frontend/dist/assets")
if err != nil {
logger.Fatal(err)
}
for _, f := range files {
if !f.IsDir() {
availableIcons = append(availableIcons, f.Name())
}
}
}