Merge pull request #9 from rancher/development

Migration to Rancher space and new features
pull/16/head v0.3.0
Thorsten Klein 6 years ago committed by GitHub
commit 38dd37566d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      .travis.yml
  2. 2
      Makefile
  3. 20
      README.md
  4. 24
      cli/commands.go
  5. 2
      go.mod
  6. 2
      install.sh
  7. 23
      main.go

@ -25,5 +25,5 @@ deploy:
- _dist/k3d-linux-arm64 - _dist/k3d-linux-arm64
- _dist/k3d-windows-amd64.exe - _dist/k3d-windows-amd64.exe
on: on:
repo: iwilltry42/k3d repo: rancher/k3d
tags: true tags: true

@ -16,7 +16,7 @@ PKG := $(shell go mod vendor)
TAGS := TAGS :=
TESTS := . TESTS := .
TESTFLAGS := 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 := GOFLAGS :=
BINDIR := $(CURDIR)/bin BINDIR := $(CURDIR)/bin
BINARIES := k3d BINARIES := k3d

@ -1,35 +1,33 @@
# k3d # k3d
[![Build Status](https://travis-ci.com/iwilltry42/k3d.svg?branch=master)](https://travis-ci.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/iwilltry42/k3d)](https://goreportcard.com/report/github.com/iwilltry42/k3d) [![Go Report Card](https://goreportcard.com/badge/github.com/rancher/k3d)](https://goreportcard.com/report/github.com/rancher/k3d)
## k3s in docker ## k3s in docker
k3s is the lightweight Kubernetes distribution by Rancher: [rancher/k3s](https://github.com/rancher/k3s) 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. 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).
Thanks to @zeerorg for the original work!
## Requirements ## Requirements
- docker - [docker](https://docs.docker.com/install/)
## Install ## Install
You have several options there: You have several options there:
- use the install script to grab the latest release: - use the install script to grab the latest release:
- wget: `wget -q -O - https://raw.githubusercontent.com/iwilltry42/k3d/master/install.sh | bash` - wget: `wget -q -O - https://raw.githubusercontent.com/rancher/k3d/master/install.sh | bash`
- curl: `curl -s https://raw.githubusercontent.com/iwilltry42/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/iwilltry42/k3d/releases) and install it yourself. - Grab a release from the [release tab](https://github.com/rancher/k3d/releases) and install it yourself.
- Via go: `go install github.com/iwilltry42/k3d` - Via go: `go install github.com/rancher/k3d`
or... or...
## Build ## 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 2. Inside the repo run
- `make` to build for your current system - `make` to build for your current system
- `go install` to install it to your `GOPATH` - `go install` to install it to your `GOPATH`

@ -30,34 +30,54 @@ func CreateCluster(c *cli.Context) error {
if c.IsSet("timeout") && !c.IsSet("wait") { if c.IsSet("timeout") && !c.IsSet("wait") {
return errors.New("Cannot use --timeout flag without --wait flag") return errors.New("Cannot use --timeout flag without --wait flag")
} }
port := fmt.Sprintf("%s:%s", c.String("port"), c.String("port")) port := fmt.Sprintf("%s:%s", c.String("port"), c.String("port"))
image := fmt.Sprintf("rancher/k3s:%s", c.String("version")) image := fmt.Sprintf("rancher/k3s:%s", c.String("version"))
cmd := "docker" cmd := "docker"
// default docker arguments
args := []string{ args := []string{
"run", "run",
"--name", c.String("name"), "--name", c.String("name"),
"-e", "K3S_KUBECONFIG_OUTPUT=/output/kubeconfig.yaml",
"--publish", port, "--publish", port,
"--privileged", "--privileged",
"--detach",
"--env", "K3S_KUBECONFIG_OUTPUT=/output/kubeconfig.yaml",
} }
// additional docker arguments
extraArgs := []string{} extraArgs := []string{}
if c.IsSet("env") || c.IsSet("e") {
for _, env := range c.StringSlice("env") {
extraArgs = append(extraArgs, "--env", env)
}
}
if c.IsSet("volume") { if c.IsSet("volume") {
extraArgs = append(extraArgs, "--volume", c.String("volume")) extraArgs = append(extraArgs, "--volume", c.String("volume"))
} }
if len(extraArgs) > 0 { if len(extraArgs) > 0 {
args = append(args, extraArgs...) args = append(args, extraArgs...)
} }
// k3s version and options
args = append(args, args = append(args,
"-d",
image, image,
"server", // cmd "server", // cmd
"--https-listen-port", c.String("port"), //args "--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")) log.Printf("Creating cluster [%s]", c.String("name"))
if err := runCommand(true, cmd, args...); err != nil { if err := runCommand(true, cmd, args...); err != nil {
return fmt.Errorf("ERROR: couldn't create cluster [%s]\n%+v", c.String("name"), err) 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() start := time.Now()
timeout := time.Duration(c.Int("timeout")) * time.Second timeout := time.Duration(c.Int("timeout")) * time.Second
for c.IsSet("wait") { for c.IsSet("wait") {

@ -1,4 +1,4 @@
module github.com/iwilltry42/k3d module github.com/rancher/k3d
go 1.12 go 1.12

@ -1,7 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
APP_NAME="k3d" APP_NAME="k3d"
REPO_URL="https://github.com/iwilltry42/k3d" REPO_URL="https://github.com/rancher/k3d"
: ${USE_SUDO:="true"} : ${USE_SUDO:="true"}
: ${K3D_INSTALL_DIR:="/usr/local/bin"} : ${K3D_INSTALL_DIR:="/usr/local/bin"}

@ -4,8 +4,8 @@ import (
"log" "log"
"os" "os"
"github.com/iwilltry42/k3d/cli" run "github.com/rancher/k3d/cli"
"github.com/iwilltry42/k3d/version" "github.com/rancher/k3d/version"
"github.com/urfave/cli" "github.com/urfave/cli"
) )
@ -19,9 +19,16 @@ func main() {
app.Version = version.GetVersion() app.Version = version.GetVersion()
app.Authors = []cli.Author{ app.Authors = []cli.Author{
cli.Author{ cli.Author{
Name: "iwilltry42", Name: "Thorsten Klein",
Email: "iwilltry42@gmail.com", 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 // commands that you can execute
@ -67,13 +74,21 @@ func main() {
Name: "wait, w", Name: "wait, w",
Usage: "Wait for the cluster to come up", 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, Action: run.CreateCluster,
}, },
{ {
// delete deletes an existing k3s cluster (remove container and cluster directory) // delete deletes an existing k3s cluster (remove container and cluster directory)
Name: "delete", Name: "delete",
Aliases: []string{"d"}, Aliases: []string{"d", "del"},
Usage: "Delete cluster", Usage: "Delete cluster",
Flags: []cli.Flag{ Flags: []cli.Flag{
cli.StringFlag{ cli.StringFlag{

Loading…
Cancel
Save