diff --git a/.travis.yml b/.travis.yml index 2f0c8fbd..92999ce4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,5 +25,5 @@ deploy: - _dist/k3d-linux-arm64 - _dist/k3d-windows-amd64.exe on: - repo: iwilltry42/k3d + repo: rancher/k3d tags: true diff --git a/Makefile b/Makefile index 8b322b0d..6131ede4 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ PKG := $(shell go mod vendor) TAGS := TESTS := . TESTFLAGS := -LDFLAGS := -w -s -X github.com/iwilltry42/k3d/version.Version=${GIT_TAG} +LDFLAGS := -w -s -X github.com/rancher/k3d/version.Version=${GIT_TAG} GOFLAGS := BINDIR := $(CURDIR)/bin BINARIES := k3d diff --git a/README.md b/README.md index 849f95a9..869b4f41 100644 --- a/README.md +++ b/README.md @@ -1,35 +1,33 @@ # k3d -[![Build Status](https://travis-ci.com/iwilltry42/k3d.svg?branch=master)](https://travis-ci.com/iwilltry42/k3d) -[![Go Report Card](https://goreportcard.com/badge/github.com/iwilltry42/k3d)](https://goreportcard.com/report/github.com/iwilltry42/k3d) +[![Build Status](https://travis-ci.com/rancher/k3d.svg?branch=master)](https://travis-ci.com/rancher/k3d) +[![Go Report Card](https://goreportcard.com/badge/github.com/rancher/k3d)](https://goreportcard.com/report/github.com/rancher/k3d) ## k3s in docker k3s is the lightweight Kubernetes distribution by Rancher: [rancher/k3s](https://github.com/rancher/k3s) -This repository is basically [zeerorg/k3s-in-docker](https://github.com/zeerorg/k3s-in-docker) reimplemented in Golang with some different/new functionality... just because I didn't have time to learn Rust. - -Thanks to @zeerorg for the original work! +This repository is based on @zeerorg's [zeerorg/k3s-in-docker](https://github.com/zeerorg/k3s-in-docker), reimplemented in Go by @iwilltry42 in [iwilltry42/k3d](https://github.com/iwilltry42/k3d), which is now [rancher/k3d](https://github.com/rancher/k3d). ## Requirements -- docker +- [docker](https://docs.docker.com/install/) ## Install You have several options there: - use the install script to grab the latest release: - - wget: `wget -q -O - https://raw.githubusercontent.com/iwilltry42/k3d/master/install.sh | bash` - - curl: `curl -s https://raw.githubusercontent.com/iwilltry42/k3d/master/install.sh | bash` -- Grab a release from the [release tab](https://github.com/iwilltry42/k3d/releases) and install it yourself. -- Via go: `go install github.com/iwilltry42/k3d` + - wget: `wget -q -O - https://raw.githubusercontent.com/rancher/k3d/master/install.sh | bash` + - curl: `curl -s https://raw.githubusercontent.com/rancher/k3d/master/install.sh | bash` +- Grab a release from the [release tab](https://github.com/rancher/k3d/releases) and install it yourself. +- Via go: `go install github.com/rancher/k3d` or... ## Build -1. Clone this repo, e.g. via `go get -u github.com/iwilltry42/k3d/releases` +1. Clone this repo, e.g. via `go get -u github.com/rancher/k3d/releases` 2. Inside the repo run - `make` to build for your current system - `go install` to install it to your `GOPATH` diff --git a/cli/commands.go b/cli/commands.go index 13a80dd3..f37ae62e 100644 --- a/cli/commands.go +++ b/cli/commands.go @@ -30,34 +30,54 @@ func CreateCluster(c *cli.Context) error { if c.IsSet("timeout") && !c.IsSet("wait") { return errors.New("Cannot use --timeout flag without --wait flag") } + port := fmt.Sprintf("%s:%s", c.String("port"), c.String("port")) image := fmt.Sprintf("rancher/k3s:%s", c.String("version")) cmd := "docker" + + // default docker arguments args := []string{ "run", "--name", c.String("name"), - "-e", "K3S_KUBECONFIG_OUTPUT=/output/kubeconfig.yaml", "--publish", port, "--privileged", + "--detach", + "--env", "K3S_KUBECONFIG_OUTPUT=/output/kubeconfig.yaml", } + + // additional docker arguments extraArgs := []string{} + if c.IsSet("env") || c.IsSet("e") { + for _, env := range c.StringSlice("env") { + extraArgs = append(extraArgs, "--env", env) + } + } if c.IsSet("volume") { extraArgs = append(extraArgs, "--volume", c.String("volume")) } if len(extraArgs) > 0 { args = append(args, extraArgs...) } + + // k3s version and options args = append(args, - "-d", image, "server", // cmd "--https-listen-port", c.String("port"), //args ) + + // additional k3s server arguments + if c.IsSet("server-arg") || c.IsSet("x") { + args = append(args, c.StringSlice("server-arg")...) + } + + // let's go log.Printf("Creating cluster [%s]", c.String("name")) if err := runCommand(true, cmd, args...); err != nil { return fmt.Errorf("ERROR: couldn't create cluster [%s]\n%+v", c.String("name"), err) } + // wait for k3s to be up and running if we want it start := time.Now() timeout := time.Duration(c.Int("timeout")) * time.Second for c.IsSet("wait") { diff --git a/go.mod b/go.mod index 7f069531..4d3f9f05 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/iwilltry42/k3d +module github.com/rancher/k3d go 1.12 diff --git a/install.sh b/install.sh index 8b31e6dc..1765b054 100755 --- a/install.sh +++ b/install.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash APP_NAME="k3d" -REPO_URL="https://github.com/iwilltry42/k3d" +REPO_URL="https://github.com/rancher/k3d" : ${USE_SUDO:="true"} : ${K3D_INSTALL_DIR:="/usr/local/bin"} diff --git a/main.go b/main.go index 69434422..bb66e12c 100644 --- a/main.go +++ b/main.go @@ -4,8 +4,8 @@ import ( "log" "os" - "github.com/iwilltry42/k3d/cli" - "github.com/iwilltry42/k3d/version" + run "github.com/rancher/k3d/cli" + "github.com/rancher/k3d/version" "github.com/urfave/cli" ) @@ -19,9 +19,16 @@ func main() { app.Version = version.GetVersion() app.Authors = []cli.Author{ cli.Author{ - Name: "iwilltry42", + Name: "Thorsten Klein", Email: "iwilltry42@gmail.com", }, + cli.Author{ + Name: "Rishabh Gupta", + Email: "r.g.gupta@outlook.com", + }, + cli.Author{ + Name: "Darren Shepherd", + }, } // commands that you can execute @@ -67,13 +74,21 @@ func main() { Name: "wait, w", Usage: "Wait for the cluster to come up", }, + cli.StringSliceFlag{ + Name: "server-arg, x", + Usage: "Pass an additional argument to k3s server (new flag per argument)", + }, + cli.StringSliceFlag{ + Name: "env, e", + Usage: "Pass an additional environment variable (new flag per variable)", + }, }, Action: run.CreateCluster, }, { // delete deletes an existing k3s cluster (remove container and cluster directory) Name: "delete", - Aliases: []string{"d"}, + Aliases: []string{"d", "del"}, Usage: "Delete cluster", Flags: []cli.Flag{ cli.StringFlag{