From a25d1d346ac10e6e1834f20c6198da32f1ee9aa5 Mon Sep 17 00:00:00 2001 From: iwilltry42 Date: Wed, 15 Jan 2020 09:29:35 +0100 Subject: [PATCH] add clusterCreateOpts flag struct and implement extra args for k3s server/agent --- cmd/create/createCluster.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/cmd/create/createCluster.go b/cmd/create/createCluster.go index 7b7911a1..f0e37888 100644 --- a/cmd/create/createCluster.go +++ b/cmd/create/createCluster.go @@ -36,9 +36,17 @@ import ( log "github.com/sirupsen/logrus" ) +// createClusterOpts describes a set of options set via CLI flags +type createClusterOpts struct { + K3sServerArgs []string + K3sAgentArgs []string +} + // NewCmdCreateCluster returns a new cobra command func NewCmdCreateCluster() *cobra.Command { + opts := &createClusterOpts{} + // create new command cmd := &cobra.Command{ Use: "cluster NAME", @@ -46,7 +54,7 @@ func NewCmdCreateCluster() *cobra.Command { Long: `Create a new k3s cluster with containerized nodes (k3s in docker).`, Args: cobra.ExactArgs(1), // exactly one cluster name can be set // TODO: if not specified, use k3d.DefaultClusterName Run: func(cmd *cobra.Command, args []string) { - runtime, cluster := parseCreateClusterCmd(cmd, args) + runtime, cluster := parseCreateClusterCmd(cmd, args, opts) if err := k3dCluster.CreateCluster(cluster, runtime); err != nil { log.Fatalln(err) } @@ -90,8 +98,8 @@ func NewCmdCreateCluster() *cobra.Command { */ /* k3s */ // TODO: to implement extra args - cmd.Flags().StringArray("k3s-server-arg", nil, "[WIP] Additional args passed to the `k3s server` command on master nodes") - cmd.Flags().StringArray("k3s-agent-arg", nil, "[WIP] Additional args passed to the `k3s agent` command on worker nodes") + cmd.Flags().StringArrayVar(&opts.K3sServerArgs, "k3s-server-arg", nil, "Additional args passed to the `k3s server` command on master nodes (new flag per arg)") + cmd.Flags().StringArrayVar(&opts.K3sAgentArgs, "k3s-agent-arg", nil, "Additional args passed to the `k3s agent` command on worker nodes (new flag per arg)") /* Subcommands */ @@ -100,7 +108,7 @@ func NewCmdCreateCluster() *cobra.Command { } // parseCreateClusterCmd parses the command input into variables required to create a cluster -func parseCreateClusterCmd(cmd *cobra.Command, args []string) (runtimes.Runtime, *k3d.Cluster) { +func parseCreateClusterCmd(cmd *cobra.Command, args []string, opts *createClusterOpts) (runtimes.Runtime, *k3d.Cluster) { // --runtime rt, err := cmd.Flags().GetString("runtime") if err != nil { @@ -333,6 +341,7 @@ func parseCreateClusterCmd(cmd *cobra.Command, args []string) (runtimes.Runtime, node := k3d.Node{ Role: k3d.MasterRole, Image: image, + Args: opts.K3sServerArgs, MasterOpts: k3d.MasterOpts{}, } @@ -354,6 +363,7 @@ func parseCreateClusterCmd(cmd *cobra.Command, args []string) (runtimes.Runtime, node := k3d.Node{ Role: k3d.WorkerRole, Image: image, + Args: opts.K3sAgentArgs, } cluster.Nodes = append(cluster.Nodes, &node)