From 3de468b37289fecf65e93e67d74eb039eb9fa33c Mon Sep 17 00:00:00 2001 From: Irbe Krumina Date: Wed, 17 Jul 2024 11:39:05 +0300 Subject: [PATCH] wip Signed-off-by: Irbe Krumina --- scripts/kubetests/cleanup.sh | 9 ++++ scripts/kubetests/setup.sh | 71 +++++++++++++++++++++++++++++++ scripts/kubetests/test_on_kind.sh | 39 +++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100755 scripts/kubetests/cleanup.sh create mode 100755 scripts/kubetests/setup.sh create mode 100755 scripts/kubetests/test_on_kind.sh diff --git a/scripts/kubetests/cleanup.sh b/scripts/kubetests/cleanup.sh new file mode 100755 index 000000000..8332fdfc7 --- /dev/null +++ b/scripts/kubetests/cleanup.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env sh + +set -eu + +helm uninstall operator --namespace tailscale + +kubectl delete -f ./cmd/k8s-operator/deploy/crds + +helm uninstall ingress diff --git a/scripts/kubetests/setup.sh b/scripts/kubetests/setup.sh new file mode 100755 index 000000000..0112f29ca --- /dev/null +++ b/scripts/kubetests/setup.sh @@ -0,0 +1,71 @@ +#!/usr/bin/env bash + +set -eu + +# This script builds the latest operator and proxy images and manifests and +# installs them as well as ingress-nginx chart to the current kube cluster. Run +# it with KIND= to upload images to a kind cluster else you must +# pass REPO env var pointing at a public repository where the images will be +# pushed. +# This script is also run from ./scripts/kubetests/test_on_kind.sh +# Run it with: +# OAUTH_CLIENT_ID= \ +# OAUTH_CLIENT_SECRET= \ +# [REPO=] \ +# [KIND=] \ +# ./scripts/kubetests/setup.sh + +OAUTH_CLIENT_ID="$OAUTH_CLIENT_ID" +OAUTH_CLIENT_SECRET="$OAUTH_CLIENT_SECRET" +KIND=${KIND:-} + +if [[ ! -z "$KIND" ]]; then + REPO="tailscale-for-kind" +fi + +REPO="$REPO" + +eval `./tool/go run ./cmd/mkversion` + +args=(TAGS="${VERSION_SHORT}") + +make kube-generate-all # ensure things are up to date + +if [[ ! -z "$KIND" ]]; then +args+=" PLATFORM=local" +fi + +make ${args[@]} REPO="${REPO}/proxy" publishdevimage +make ${args[@]} REPO="${REPO}/operator" publishdevoperator + +if [[ ! -z "$KIND" ]]; then + kind load docker-image "${REPO}/operator:${VERSION_SHORT}" --name "${KIND}" + kind load docker-image "${REPO}/proxy:${VERSION_SHORT}" --name "${KIND}" +fi + +kubectl apply -f ./cmd/k8s-operator/deploy/crds/ + +helm upgrade \ + --install \ + operator ./cmd/k8s-operator/deploy/chart \ + --namespace tailscale \ + --create-namespace \ + --set operator.image.repo="${REPO}/operator" \ + --set operator.image.tag="${VERSION_SHORT} \ + --set opertor.image.pullPolicy="IfNotPresent" \ + --set proxy.image.repo="${REPO}/proxy \ + --set proxy.image.tag="${VERSION_SHORT}" \ + --set installCRDs=false \ + --set-string apiServerProxyConfig.mode="true" \ + --set oauth.clientId="${OAUTH_CLIENT_ID}" \ + --set oauth.clientSecret="${OAUTH_CLIENT_SECRET}" \ + --set operatorConfig.logging=debug \ + --wait + +# ingress-nginx is used in tests. +# Note that this command CANNOT be ran with --wait as the Service will never +# become ready (load balancer cannot be provisioned on kind). +helm upgrade --install ingress ingress-nginx/ingress-nginx + +# TODO: either wait for the ingress-controller Pod to become ready or do +# something else to wait for the parts we care about to be ready. diff --git a/scripts/kubetests/test_on_kind.sh b/scripts/kubetests/test_on_kind.sh new file mode 100755 index 000000000..a98ee6830 --- /dev/null +++ b/scripts/kubetests/test_on_kind.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env sh + +# Copyright (c) Tailscale Inc & AUTHORS +# SPDX-License-Identifier: BSD-3-Clause + +set -eu + +# This script creates a kind cluster, sets up test dependencies and runs e2e +# tests. It builds the latest operator and proxy image as well as manifests from +# this repo. The operator and proxy images are uploaded to the local container +# registry (i.e docker) and the kind cluster. +# +# Run it with: +# OAUTH_CLIENT_ID= \ +# OAUTH_CLIENT_SECRET= \ +# [K8S_VERSION=] \ +# [CLUSTER_NAME=