-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmain.go
More file actions
148 lines (130 loc) · 5.93 KB
/
main.go
File metadata and controls
148 lines (130 loc) · 5.93 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package main
import (
"time"
"github.com/Devatoria/go-mesos-executor/container"
"github.com/Devatoria/go-mesos-executor/executor"
"github.com/Devatoria/go-mesos-executor/hook"
"github.com/Devatoria/go-mesos-executor/logger"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"go.uber.org/zap"
)
var (
agentEndpoint string
cgroupsEnableCFS bool
containerName string
docker string
dockerSocket string
executorID string
externalLogFile string
frameworkID string
help bool
initializeDriverLogging bool
launcherDir string
logBufSecs uint
logDir string
loggingLevel string
mappedDirectory string
quiet bool
sandboxDirectory string
stopTimeout string
taskEnvironment []string
)
var rootCmd = &cobra.Command{
Use: "mesos-docker-executor",
Short: "Custom Mesos Docker executor",
Run: func(cmd *cobra.Command, args []string) {
logger.GetInstance().Info("Initializing the executor",
zap.String("executorID", executorID),
zap.String("frameworkID", frameworkID),
)
// Prepare docker containerizer
c, err := container.NewDockerContainerizer(dockerSocket)
if err != nil {
logger.GetInstance().Fatal("An error occured while initializing the containerizer",
zap.Error(err),
)
}
// Create hook manager
hooks := viper.GetStringSlice("hooks")
logger.GetInstance().Info("Creating hook manager",
zap.Reflect("hooks", hooks),
)
m := hook.NewManager(hooks)
m.RegisterHooks(&hook.ACLHook)
m.RegisterHooks(&hook.IptablesHook)
m.RegisterHooks(&hook.NetnsHook)
m.RegisterHooks(&hook.RemoveContainerHook)
m.RegisterHooks(&hook.NetworkHook)
// Create and run the executor
e := executor.NewExecutor(executor.Config{
AgentEndpoint: agentEndpoint,
ContainerName: containerName,
ExecutorID: executorID,
FrameworkID: frameworkID,
}, c, m)
if err := e.Execute(); err != nil {
logger.GetInstance().Fatal("An error occured while running the executor",
zap.Error(err),
)
}
},
}
func init() {
cobra.OnInitialize(readConfig)
// Flags given by the agent when running th executor
rootCmd.PersistentFlags().BoolVar(&cgroupsEnableCFS, "cgroups_enable_cfs", false, "Cgroups feature flag to enable hard limits on CPU resources via the CFS bandwidth limiting subfeature")
rootCmd.PersistentFlags().StringVar(&containerName, "container", "", "Container name")
rootCmd.PersistentFlags().StringVar(&docker, "docker", "", "Docker executable path (unused)")
rootCmd.PersistentFlags().StringVar(&dockerSocket, "docker_socket", "", "Docker socket path")
rootCmd.PersistentFlags().StringVar(&externalLogFile, "external_log_file", "", "File to log in if not using the default system")
rootCmd.PersistentFlags().BoolVar(&help, "help", false, "Prints the help message (unused)")
rootCmd.PersistentFlags().BoolVar(&initializeDriverLogging, "initialize_driver_logging", true, "This option has no effect when using the HTTP scheduler/executor APIs")
rootCmd.PersistentFlags().StringVar(&launcherDir, "launcher_dir", "", "Folder from where the executor is launched")
rootCmd.PersistentFlags().UintVar(&logBufSecs, "logbufsecs", 0, "Maximum number of seconds that logs may be buffered for.")
rootCmd.PersistentFlags().StringVar(&logDir, "log_dir", "", "Location to put log files")
rootCmd.PersistentFlags().StringVar(&loggingLevel, "logging_level", "", "Logging level")
rootCmd.PersistentFlags().StringVar(&mappedDirectory, "mapped_directory", "", "The sandbox directory path that is mapped in the docker container")
rootCmd.PersistentFlags().BoolVar(&quiet, "quiet", false, "Disable logging to stderr")
rootCmd.PersistentFlags().StringVar(&sandboxDirectory, "sandbox_directory", "", "The path to the container sandbox holding stdout and stderr files into which docker container logs will be redirected")
rootCmd.PersistentFlags().StringVar(&stopTimeout, "stop_timeout", "", "Time to wait before killing a currently stopping container")
rootCmd.PersistentFlags().StringSliceVar(&taskEnvironment, "task_environment", []string{}, "A JSON map of environment variables and values that should be passed into the task launched by this executor.")
// Custom flags
rootCmd.PersistentFlags().Bool("debug", true, "Enable debug mode")
viper.BindPFlag("debug", rootCmd.PersistentFlags().Lookup("debug"))
rootCmd.PersistentFlags().StringSlice("hooks", []string{}, "Enabled hooks")
viper.BindPFlag("hooks", rootCmd.PersistentFlags().Lookup("hooks"))
rootCmd.PersistentFlags().String("proc_path", "/proc", "Proc mount path")
viper.BindPFlag("proc_path", rootCmd.PersistentFlags().Lookup("proc_path"))
rootCmd.PersistentFlags().Duration("registering_retry", 100*time.Millisecond, "Executor registering delay in duration")
viper.BindPFlag("registering_retry", rootCmd.PersistentFlags().Lookup("registering_retry"))
rootCmd.PersistentFlags().Duration("docker_exec_poll_interval", 1*time.Second, "Rate of docker exec polling for result")
viper.BindPFlag("docker_exec_poll_interval", rootCmd.PersistentFlags().Lookup("docker_exec_poll_interval"))
// Iptables hook
viper.SetDefault("iptables.ip_forwarding", true)
viper.SetDefault("iptables.ip_masquerading", true)
}
func readConfig() {
viper.SetEnvPrefix("mesos")
viper.SetConfigName("config")
viper.AddConfigPath("/etc/mesos-executor")
viper.AddConfigPath(".")
viper.BindEnv("agent_endpoint")
agentEndpoint = viper.GetString("agent_endpoint")
viper.BindEnv("executor_id")
executorID = viper.GetString("executor_id")
viper.BindEnv("framework_id")
frameworkID = viper.GetString("framework_id")
if err := viper.ReadInConfig(); err != nil {
logger.GetInstance().Fatal("An error occured while reading the configuration file",
zap.Error(err),
)
}
}
func main() {
if err := rootCmd.Execute(); err != nil {
logger.GetInstance().Fatal("An error occured while running the root command",
zap.Error(err),
)
}
}