-
Notifications
You must be signed in to change notification settings - Fork 0
/
dispatcher.go
73 lines (61 loc) · 1.81 KB
/
dispatcher.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
package testwave
import (
"os"
"github.com/celestiaorg/testwave/pkg/deployer"
"github.com/celestiaorg/testwave/pkg/dispatcher"
"github.com/celestiaorg/testwave/pkg/playbook"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"k8s.io/client-go/util/homedir"
)
const (
flagKubeConfig = "kubeconfig"
flagLogLevel = "log-level"
)
var flagsDispatcher struct {
kubeConfig string
logLevel string
}
func dispatcherCmd(testPlanPlaybook playbook.Playbook) *cobra.Command {
if testPlanPlaybook == nil {
logrus.Errorf("Error: test plan playbook is nil")
os.Exit(1)
}
cmd := &cobra.Command{
Use: DispatcherCmd,
Short: "start the dispatcher node",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
clientset, err := deployer.KubeClientset(flagsDispatcher.kubeConfig)
if err != nil {
logrus.Errorf("Error building kubeconfig: %v\n", err)
os.Exit(1)
}
workerImage := os.Getenv(dispatcher.EnvWorkerImage)
if workerImage == "" {
logrus.Errorf("Error reading worker image from environment variable %s", dispatcher.EnvWorkerImage)
os.Exit(1)
}
namespace := os.Getenv(dispatcher.EnvNamespace)
if namespace == "" {
namespace = "default"
logrus.Info("Using `default` k8s namespace")
}
d := &dispatcher.Dispatcher{
Clientset: clientset,
Namespace: namespace,
Playbook: testPlanPlaybook,
WorkerImage: workerImage,
}
d.RunTest()
return nil
},
}
defaultKubeConfig := ""
if home := homedir.HomeDir(); home != "" {
defaultKubeConfig = home + "/.kube/config"
}
cmd.Flags().StringVar(&flagsDispatcher.kubeConfig, flagKubeConfig, defaultKubeConfig, "Path to kubeconfig file")
// cmd.Flags().StringVar(&flagsDispatcher.logLevel, flagLogLevel, "info", "Log level (debug, info, warn, error, fatal, panic)")
return cmd
}