forked from topfreegames/pitaya-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremote_manager_launcher.go
46 lines (40 loc) · 1.39 KB
/
remote_manager_launcher.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
package launcher
import (
"time"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
pbKubernetes "github.com/topfreegames/pitaya-bot/kubernetes"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
)
// LaunchRemoteManager launches the manager in kubernetes cluster, that will instantiate jobs and manage them until the end
func LaunchRemoteManager(config *viper.Viper, specsDirectory string, duration time.Duration, shouldReportMetrics, deleteBeforeRun bool, logger logrus.FieldLogger) {
logger = logger.WithFields(logrus.Fields{
"function": "LaunchRemoteManager",
})
specs, err := GetSpecs(specsDirectory)
if err != nil {
logger.Fatal(err)
}
logger.Infof("Found %d specs to be executed", len(specs))
clusterConfig, err := rest.InClusterConfig()
if err != nil {
logger.Fatal(err)
}
clientset, err := kubernetes.NewForConfig(clusterConfig)
if err != nil {
logger.Fatal(err)
}
logger.Infof("Kubernetes In Cluster Client created")
if deleteBeforeRun {
pbKubernetes.DeleteAll(logger, clientset, config)
}
if pbKubernetes.CheckAll(logger, clientset, config) {
return
}
pbKubernetes.DeployJobsRemote(logger, clientset, config, specs, duration, shouldReportMetrics)
controller := pbKubernetes.NewManagerController(logger, clientset, config)
controller.Run(1, duration)
pbKubernetes.DeleteAll(logger, clientset, config)
pbKubernetes.DeleteAllManager(logger, clientset, config)
}