Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parameters for node container #199

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cmd/kind/create/cluster/createcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
}

Expand Down
10 changes: 8 additions & 2 deletions pkg/cluster/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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())
Expand Down Expand Up @@ -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
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/cluster/nodes/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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,
Expand Down