From 1d9c290cbd2bd09a52544126364c327822f174d9 Mon Sep 17 00:00:00 2001 From: Pablo Chacin Date: Sat, 5 Jan 2019 20:29:40 +0100 Subject: [PATCH] Add parameters for node container Add a parameter to create cluster command for specifying arguments to be passed to the node container run command. The `Arg' parameter receives a string with the parameters which are appended to the docker run command used for launching the node container. Signed-off-by: Pablo Chacin --- cmd/kind/create/cluster/createcluster.go | 4 +++- pkg/cluster/context.go | 10 ++++++++-- pkg/cluster/nodes/create.go | 5 ++++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/cmd/kind/create/cluster/createcluster.go b/cmd/kind/create/cluster/createcluster.go index 8769595c48..5fcfa5f5bf 100644 --- a/cmd/kind/create/cluster/createcluster.go +++ b/cmd/kind/create/cluster/createcluster.go @@ -35,6 +35,7 @@ type flagpole struct { ImageName string Retain bool Wait time.Duration + Args string } // NewCommand returns a new cobra.Command for cluster creation @@ -51,6 +52,7 @@ func NewCommand() *cobra.Command { cmd.Flags().StringVar(&flags.Name, "name", "1", "cluster context name") cmd.Flags().StringVar(&flags.Config, "config", "", "path to a kind config file") cmd.Flags().StringVar(&flags.ImageName, "image", "", "node docker image to use for booting the cluster") + cmd.Flags().StringVar(&flags.Args, "args", "", "additional parameters for launching node container") cmd.Flags().BoolVar(&flags.Retain, "retain", false, "retain nodes for debugging when cluster creation fails") cmd.Flags().DurationVar(&flags.Wait, "wait", time.Duration(0), "Wait for control plane node to be ready (default 0s)") return cmd @@ -84,7 +86,7 @@ func runE(flags *flagpole, cmd *cobra.Command, args []string) error { return fmt.Errorf("aborting due to invalid configuration") } } - if err = ctx.Create(cfg, flags.Retain, flags.Wait); err != nil { + if err = ctx.Create(cfg, flags.Retain, flags.Wait, flags.Args); err != nil { return fmt.Errorf("failed to create cluster: %v", err) } diff --git a/pkg/cluster/context.go b/pkg/cluster/context.go index bc15d7a72d..1f20f4cc83 100644 --- a/pkg/cluster/context.go +++ b/pkg/cluster/context.go @@ -51,6 +51,7 @@ type createContext struct { *Context status *logutil.Status config *config.Config + args []string retain bool // if we should retain nodes after failing to create. waitForReady time.Duration // Wait for the control plane node to be ready. ControlPlaneMeta *ControlPlaneMeta @@ -124,7 +125,7 @@ func (c *Context) KubeConfigPath() string { } // Create provisions and starts a kubernetes-in-docker cluster -func (c *Context) Create(cfg *config.Config, retain bool, wait time.Duration) error { +func (c *Context) Create(cfg *config.Config, retain bool, wait time.Duration, args string) error { // validate config first if err := cfg.Validate(); err != nil { return err @@ -133,10 +134,15 @@ func (c *Context) Create(cfg *config.Config, retain bool, wait time.Duration) er cc := &createContext{ Context: c, config: cfg, + args: []string{}, retain: retain, waitForReady: wait, } + if args != "" { + cc.args = strings.Split(args," ") + } + fmt.Printf("Creating cluster '%s' ...\n", c.ClusterName()) cc.status = logutil.NewStatus(os.Stdout) cc.status.MaybeWrapLogrus(log.StandardLogger()) @@ -211,7 +217,7 @@ func (cc *createContext) provisionControlPlane( ) (kubeadmConfigPath string, err error) { cc.status.Start(fmt.Sprintf("[%s] Creating node container 📦", nodeName)) // create the "node" container (docker run, but it is paused, see createNode) - node, port, err := nodes.CreateControlPlaneNode(nodeName, cc.config.Image, cc.ClusterLabel()) + node, port, err := nodes.CreateControlPlaneNode(nodeName, cc.config.Image, cc.ClusterLabel(), cc.args) if err != nil { return "", err } diff --git a/pkg/cluster/nodes/create.go b/pkg/cluster/nodes/create.go index a04da7a941..879475036a 100644 --- a/pkg/cluster/nodes/create.go +++ b/pkg/cluster/nodes/create.go @@ -45,7 +45,7 @@ func getPort() (int, error) { // CreateControlPlaneNode `docker run`s the node image, note that due to // images/node/entrypoint being the entrypoint, this container will // effectively be paused until we call actuallyStartNode(...) -func CreateControlPlaneNode(name, image, clusterLabel string) (handle *Node, port int, err error) { +func CreateControlPlaneNode(name, image, clusterLabel string, args []string) (handle *Node, port int, err error) { port, err = getPort() if err != nil { return nil, 0, errors.Wrap(err, "failed to get port for API server") @@ -80,6 +80,9 @@ func CreateControlPlaneNode(name, image, clusterLabel string) (handle *Node, por runArgs = append(runArgs, "--userns=host") } + runArgs = append(runArgs, args...) + + id, err := docker.Run( image, runArgs,