From 4e52afd57834ff9a4407f48bf8b7c242f6ed9c51 Mon Sep 17 00:00:00 2001 From: misakwa Date: Tue, 30 Jul 2019 22:04:40 -0500 Subject: [PATCH] Add agent-arg and pass through to container --- cli/commands.go | 7 ++++++- cli/container.go | 1 + main.go | 4 ++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/cli/commands.go b/cli/commands.go index 84ee0968..a0973462 100644 --- a/cli/commands.go +++ b/cli/commands.go @@ -105,6 +105,7 @@ func CreateCluster(c *cli.Context) error { return err } + k3AgentArgs := make([]string, 0) k3sServerArgs := []string{"--https-listen-port", apiPort.Port} // When the 'host' is not provided by --api-port, try to fill it using Docker Machine's IP address. @@ -129,6 +130,10 @@ func CreateCluster(c *cli.Context) error { k3sServerArgs = append(k3sServerArgs, c.StringSlice("server-arg")...) } + if c.IsSet("agent-arg") { + k3AgentArgs = append(k3AgentArgs, c.StringSlice("agent-arg")...) + } + // new port map portmap, err := mapNodesToPortSpecs(c.StringSlice("publish"), GetAllContainerNames(c.String("name"), defaultServerCount, c.Int("workers"))) if err != nil { @@ -145,7 +150,7 @@ func CreateCluster(c *cli.Context) error { volumes = append(volumes, fmt.Sprintf("%s:/images", imageVolume.Name)) clusterSpec := &ClusterSpec{ - AgentArgs: []string{}, + AgentArgs: k3AgentArgs, APIPort: *apiPort, AutoRestart: c.Bool("auto-restart"), ClusterName: c.String("name"), diff --git a/cli/container.go b/cli/container.go index d9c8a93f..aadbb454 100644 --- a/cli/container.go +++ b/cli/container.go @@ -204,6 +204,7 @@ func createWorker(spec *ClusterSpec, postfix int) (string, error) { Hostname: containerName, Image: spec.Image, Env: env, + Cmd: append([]string{"agent"}, spec.AgentArgs...), Labels: containerLabels, ExposedPorts: workerPublishedPorts.ExposedPorts, } diff --git a/main.go b/main.go index 5b9b24ff..57518db8 100644 --- a/main.go +++ b/main.go @@ -116,6 +116,10 @@ func main() { Name: "server-arg, x", Usage: "Pass an additional argument to k3s server (new flag per argument)", }, + cli.StringSliceFlag{ + Name: "agent-arg", + Usage: "Pass an additional argument to k3s agent (new flag per argument)", + }, cli.StringSliceFlag{ Name: "env, e", Usage: "Pass an additional environment variable (new flag per variable)",