From 6ddcd659dabb4c45918df377f458a45154f559bb Mon Sep 17 00:00:00 2001 From: iwilltry42 Date: Fri, 2 Oct 2020 12:27:33 +0200 Subject: [PATCH 1/3] docs: quote node filters (ref #348) --- cmd/cluster/clusterCreate.go | 4 ++-- docs/usage/guides/exposing_services.md | 6 +++--- docs/usage/guides/registries.md | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cmd/cluster/clusterCreate.go b/cmd/cluster/clusterCreate.go index d8a1e97b0..fa1547519 100644 --- a/cmd/cluster/clusterCreate.go +++ b/cmd/cluster/clusterCreate.go @@ -126,8 +126,8 @@ func NewCmdClusterCreate() *cobra.Command { cmd.Flags().StringP("image", "i", fmt.Sprintf("%s:%s", k3d.DefaultK3sImageRepo, version.GetK3sVersion(false)), "Specify k3s image that you want to use for the nodes") cmd.Flags().String("network", "", "Join an existing network") cmd.Flags().String("token", "", "Specify a cluster token. By default, we generate one.") - cmd.Flags().StringArrayP("volume", "v", nil, "Mount volumes into the nodes (Format: `[SOURCE:]DEST[@NODEFILTER[;NODEFILTER...]]`\n - Example: `k3d cluster create --agents 2 -v /my/path@agent[0,1] -v /tmp/test:/tmp/other@server[0]`") - cmd.Flags().StringArrayP("port", "p", nil, "Map ports from the node containers to the host (Format: `[HOST:][HOSTPORT:]CONTAINERPORT[/PROTOCOL][@NODEFILTER]`)\n - Example: `k3d cluster create --agents 2 -p 8080:80@agent[0] -p 8081@agent[1]`") + cmd.Flags().StringArrayP("volume", "v", nil, "Mount volumes into the nodes (Format: `[SOURCE:]DEST[@NODEFILTER[;NODEFILTER...]]`\n - Example: `k3d cluster create --agents 2 -v \"/my/path@agent[0,1]\" -v \"/tmp/test:/tmp/other@server[0]\"`") + cmd.Flags().StringArrayP("port", "p", nil, "Map ports from the node containers to the host (Format: `[HOST:][HOSTPORT:]CONTAINERPORT[/PROTOCOL][@NODEFILTER]`)\n - Example: `k3d cluster create --agents 2 -p \"8080:80@agent[0]\" -p \"8081@agent[1]\"`") cmd.Flags().BoolVar(&createClusterOpts.WaitForServer, "wait", true, "Wait for the server(s) to be ready before returning. Use '--timeout DURATION' to not wait forever.") cmd.Flags().DurationVar(&createClusterOpts.Timeout, "timeout", 0*time.Second, "Rollback changes if cluster couldn't be created in specified duration.") cmd.Flags().BoolVar(&updateDefaultKubeconfig, "update-default-kubeconfig", true, "Directly update the default kubeconfig with the new cluster's context") diff --git a/docs/usage/guides/exposing_services.md b/docs/usage/guides/exposing_services.md index 0d8a2dff9..7c8d3205f 100644 --- a/docs/usage/guides/exposing_services.md +++ b/docs/usage/guides/exposing_services.md @@ -7,7 +7,7 @@ Therefore, we have to create the cluster in a way, that the internal port 80 (wh 1. Create a cluster, mapping the ingress port 80 to localhost:8081 - `#!bash k3d cluster create --api-port 6550 -p 8081:80@loadbalancer --agents 2` + `#!bash k3d cluster create --api-port 6550 -p "8081:80@loadbalancer" --agents 2` !!! info "Good to know" - `--api-port 6550` is not required for the example to work. It's used to have `k3s`'s API-Server listening on port 6550 with that port mapped to the host system. @@ -56,11 +56,11 @@ Therefore, we have to create the cluster in a way, that the internal port 80 (wh 1. Create a cluster, mapping the port 30080 from agent-0 to localhost:8082 - `#!bash k3d cluster create mycluster -p 8082:30080@agent[0] --agents 2` + `#!bash k3d cluster create mycluster -p "8082:30080@agent[0]" --agents 2` - **Note**: Kubernetes' default NodePort range is [`30000-32767`](https://kubernetes.io/docs/concepts/services-networking/service/#nodeport) - - **Note**: You may as well expose the whole NodePort range from the very beginning, e.g. via `k3d cluster create mycluster --agents 3 -p 30000-32767:30000-32767@server[0]` (See [this video from @portainer](https://www.youtube.com/watch?v=5HaU6338lAk)) + - **Note**: You may as well expose the whole NodePort range from the very beginning, e.g. via `k3d cluster create mycluster --agents 3 -p "30000-32767:30000-32767@server[0]"` (See [this video from @portainer](https://www.youtube.com/watch?v=5HaU6338lAk)) ... (Steps 2 and 3 like above) ... diff --git a/docs/usage/guides/registries.md b/docs/usage/guides/registries.md index fdc8aae63..2ebce4e32 100644 --- a/docs/usage/guides/registries.md +++ b/docs/usage/guides/registries.md @@ -3,7 +3,7 @@ ## Registries configuration file You can add registries by specifying them in a `registries.yaml` and mounting them at creation time: -`#!bash k3d cluster create mycluster --volume /home/YOU/my-registries.yaml:/etc/rancher/k3s/registries.yaml`. +`#!bash k3d cluster create mycluster --volume "/home/YOU/my-registries.yaml:/etc/rancher/k3s/registries.yaml"`. This file is a regular [k3s registries configuration file](https://rancher.com/docs/k3s/latest/en/installation/private-registry/), and looks like this: @@ -61,7 +61,7 @@ configs: Finally, we can create the cluster, mounting the CA file in the path we specified in `ca_file`: -`#!bash k3d cluster create --volume ${HOME}/.k3d/my-registries.yaml:/etc/rancher/k3s/registries.yaml --volume ${HOME}/.k3d/my-company-root.pem:/etc/ssl/certs/my-company-root.pem` +`#!bash k3d cluster create --volume "${HOME}/.k3d/my-registries.yaml:/etc/rancher/k3s/registries.yaml" --volume "${HOME}/.k3d/my-company-root.pem:/etc/ssl/certs/my-company-root.pem"` ## Using a local registry From a28ad768ccae7d58bf3f5bd2b3c1c18a0173e202 Mon Sep 17 00:00:00 2001 From: iwilltry42 Date: Mon, 5 Oct 2020 15:19:28 +0200 Subject: [PATCH 2/3] Misc: add new 'test' make target --- Makefile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 4b7a18c80..b9b903d8c 100644 --- a/Makefile +++ b/Makefile @@ -54,7 +54,7 @@ TARGET_OBJS ?= darwin-amd64.tar.gz darwin-amd64.tar.gz.sha256 linux-amd64.tar.gz GO ?= go PKG := $(shell go mod vendor) TAGS := -TESTS := . +TESTS := ./... TESTFLAGS := LDFLAGS := -w -s -X github.com/rancher/k3d/v3/version.Version=${GIT_TAG} -X github.com/rancher/k3d/v3/version.K3sVersion=${K3S_TAG} GCFLAGS := @@ -151,6 +151,9 @@ check: check-fmt lint ########## Tests ########## ########################### +test: + $(GO) test $(TESTS) $(TESTFLAGS) + e2e: build-docker-dind @echo "Running e2e tests in k3d:$(K3D_IMAGE_TAG)" LOG_LEVEL="$(E2E_LOG_LEVEL)" E2E_SKIP="$(E2E_SKIP)" E2E_EXTRA="$(E2E_EXTRA)" E2E_RUNNER_START_TIMEOUT=$(E2E_RUNNER_START_TIMEOUT) tests/dind.sh "${K3D_IMAGE_TAG}-dind" @@ -199,7 +202,7 @@ endif ci-setup: @echo "Installing Go tools..." curl -sfL $(PKG_GOLANGCI_LINT_SCRIPT) | sh -s -- -b ${GOPATH}/bin v$(PKG_GOLANGCI_LINT_VERSION) - go get $(PKG_GOX) + $(GO) get $(PKG_GOX) @echo "Installing kubectl..." curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl From d420ccf1f701f2215fe5e6e96c25a586796d3e08 Mon Sep 17 00:00:00 2001 From: iwilltry42 Date: Mon, 5 Oct 2020 15:53:41 +0200 Subject: [PATCH 3/3] tests/e2e: use imported image --- Dockerfile | 2 +- tests/test_full_lifecycle.sh | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 693ed7933..dc9a2d101 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ COPY . . RUN make build && bin/k3d version FROM docker:19.03-dind as dind -RUN apk add bash curl sudo jq git make +RUN apk update && apk add bash curl sudo jq git make netcat-openbsd RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl && \ chmod +x ./kubectl && \ mv ./kubectl /usr/local/bin/kubectl diff --git a/tests/test_full_lifecycle.sh b/tests/test_full_lifecycle.sh index 8b1826181..e97248955 100755 --- a/tests/test_full_lifecycle.sh +++ b/tests/test_full_lifecycle.sh @@ -46,11 +46,18 @@ info "Checking that we have 3 nodes available now..." check_multi_node "$clustername" 3 || failed "failed to verify number of nodes" # 4. load an image into the cluster -info "Loading an image into the cluster..." +info "Importing an image into the cluster..." docker pull nginx:latest > /dev/null docker tag nginx:latest nginx:local > /dev/null $EXE image import nginx:local -c $clustername || failed "could not import image in $clustername" +# 5. use that image +info "Spawning a pod using the imported image..." +kubectl run --image nginx:local testimage +info "Waiting for a bit for the pod to start..." +sleep 5 +kubectl get pod testimage | grep 'Running' || failed "Pod using the imported image is not running after 5 seconds" + # Cleanup info "Deleting cluster $clustername..."