-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
80 lines (69 loc) · 1.93 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 (
"fmt"
"log"
"os"
"path/filepath"
"strconv"
"time"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
)
func main() {
repositoryURL := os.Getenv("REPOSITORY_URL")
refreshGvrsTimeInMinutes, err := strconv.ParseInt(os.Getenv("REFRESH_GVRS_TIME_IN_MINUTES"), 10, 64)
if err != nil {
log.Panic(err)
}
clusterConfig, err := getClusterConfig()
if err != nil {
log.Panic(err)
}
log.Print("Reset current directory")
fileManager := newFileManager()
if err := fileManager.resetCurrentDirectory(); err != nil {
log.Panic(err)
}
log.Print("Clone git repository from ", repositoryURL)
repository, err := newRepository(repositoryURL)
if err != nil {
log.Panic(err)
}
cypher := newCypher()
discovery := newDiscovery(clusterConfig)
filter, err := newFilter()
if err != nil {
log.Panic(err)
}
managerConfig := &managerConfig{
Discovery: discovery,
Cypher: cypher,
FileManager: fileManager,
Filter: filter,
Repository: repository,
RefreshGvrsTime: time.Duration(refreshGvrsTimeInMinutes) * time.Minute,
ClusterConfig: clusterConfig,
}
manager, err := newManager(managerConfig)
if err != nil {
log.Panic(err)
}
if err := manager.manage(); err != nil {
log.Panic(err)
}
}
func getClusterConfig() (*rest.Config, error) {
log.Println("Load in Custer Client Configuration")
clusterConfig, inClusterConfigErr := rest.InClusterConfig()
if inClusterConfigErr == nil {
return clusterConfig, nil
}
log.Println("Failed to load in Custer Client Configuration")
log.Println("Load out of Custer Client Configuration")
kubeConfigPath := filepath.Join(os.Getenv("HOME"), ".kube", "config")
clusterConfig, outClusterConfigErr := clientcmd.BuildConfigFromFlags("", kubeConfigPath)
if outClusterConfigErr != nil {
return nil, fmt.Errorf("Failed to load cluster config: [in: %s, out: %s]", inClusterConfigErr, outClusterConfigErr)
}
return clusterConfig, nil
}