From 6cc0d9c7488e241d79cb6d943248421a524c9461 Mon Sep 17 00:00:00 2001 From: Simon Gerber Date: Thu, 9 Dec 2021 16:54:00 +0100 Subject: [PATCH 01/17] Adjust README headings --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6e30c9dc..441cd75c 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ # control-api -### Generate Kubernetes code +## Generate Kubernetes code If you make changes to the CRD structs you'll need to run code generation. This can be done with make: @@ -17,7 +17,7 @@ This can be done with make: make generate ``` -### Building +## Building See `make help` for a list of build targets. @@ -25,6 +25,6 @@ See `make help` for a list of build targets. * `make build -e GOOS=darwin -e GOARCH=arm64`: Build binary for macos/arm64 * `make build.docker`: Build Docker image for local environment -### Install CRDs +## Install CRDs -CRDs can be either installed on the cluster by running `kubectl apply -k config/crd/apiextensions.k8s.io/v1`. +CRDs can be installed on the cluster by running `kubectl apply -k config/crd/apiextensions.k8s.io/v1`. From e2fad6f266b37a7ab9b671840113012106a4d106 Mon Sep 17 00:00:00 2001 From: Simon Gerber Date: Thu, 9 Dec 2021 16:56:59 +0100 Subject: [PATCH 02/17] Add kind setup script and templates --- .gitignore | 2 + setup-kind.sh | 73 ++ templates/README.md | 3 + templates/kind-oidc.yaml.tpl | 13 + templates/realm.json.tpl | 2026 ++++++++++++++++++++++++++++++++++ 5 files changed, 2117 insertions(+) create mode 100755 setup-kind.sh create mode 100644 templates/README.md create mode 100644 templates/kind-oidc.yaml.tpl create mode 100644 templates/realm.json.tpl diff --git a/.gitignore b/.gitignore index 9018a9c2..330d42a0 100644 --- a/.gitignore +++ b/.gitignore @@ -27,6 +27,8 @@ _archive/ crd*.yaml /control-api +/kind.kubeconfig +/realm.json # Go releaser dist/ diff --git a/setup-kind.sh b/setup-kind.sh new file mode 100755 index 00000000..9ad0a46b --- /dev/null +++ b/setup-kind.sh @@ -0,0 +1,73 @@ +#!/bin/bash +# vim:sts=2:ts=2:et:sw=2:tw=0 + +keycloak_url=https://id.dev.appuio.cloud + +step() { + echo + echo "$1" + read -n 1 -s -r -p "Press any key to continue" + echo +} + +check_command() { + if ! command -v "${1}" >/dev/null 2>&1; then + step "Install ${2}. Follow the instructions at ${3}" + fi +} + +check_command "kubectl" "kubectl" "https://kubernetes.io/docs/tasks/tools/#kubectl" +check_command "kubectl-oidc_login" "kubectl oidc-login plugin" "Follow the instructions at https://github.com/int128/kubelogin#setup" +check_command "kind" "kind" "https://kind.sigs.k8s.io/docs/user/quick-start/#installation" + +read -r -p "Provide the URL of the Keycloak to connect the local environment to (default=${keycloak_url}): " user_url +if [ x"${user_url}" != x"" ]; then + keycloak_url="${user_url}" +fi + +identifier= +while [ x"$identifier" == x"" ]; do + read -r -p "Provide an identifier for your local-dev Keycloak realm: " identifier +done + +realm_name="local-dev-${identifier}" +sed -e "s/REPLACEME/${realm_name}/g" templates/realm.json.tpl > realm.json + +step "Navigate to ${keycloak_url} and create a new realm by importing the 'realm.json' file in this directory". + +step "Create a user in the new realm, grant it realm role 'admin', and ensure 'Email Verified' is set to 'On'." + +step "Note: In the next step, a browser window will open where you have to sign in to Keycloak with the user you've created in the previous step". + +export KUBECONFIG=./kind.kubeconfig +sed -e "s#ISSUER_KEYCLOAK#${keycloak_url}#; s/REALM/${realm_name}/g" templates/kind-oidc.yaml.tpl > .kind-oidc.yaml +kind create cluster --name appuio-cloud-controlapi-localdev --config=.kind-oidc.yaml +rm .kind-oidc.yaml +kubectl apply -f - < Date: Thu, 9 Dec 2021 16:57:15 +0100 Subject: [PATCH 03/17] Update README --- README.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/README.md b/README.md index 441cd75c..a2db4e8c 100644 --- a/README.md +++ b/README.md @@ -28,3 +28,28 @@ See `make help` for a list of build targets. ## Install CRDs CRDs can be installed on the cluster by running `kubectl apply -k config/crd/apiextensions.k8s.io/v1`. + +## Local development environment + +We provide a script and some templates to setup a local test environment based on [kind](https://kind.sigs.k8s.io/). +The templates can be found in directory `templates/`. + +### Prerequisites + +* `bash` +* `sed` +* `kind` +* `kubectl` +* `kubelogin` as `kubectl-oidc_login` + +The setup script will provide links to the install guides for `kind`, `kubectl` and `kubelogin` if no appropriate command is found. + +### Installation + +The `setup.sh` script will guide you through the setup. +There are some steps that you have to perform manually on a Keycloak instance, which the script prompts you for. +The script defaults to VSHN's APPUiO Dev Keycloak instance, but you can provide an URL pointing to a different instance during the install process. + +```bash +./setup.sh +``` From eb2f08bac564496af8d72ae1f2d5651406cd970d Mon Sep 17 00:00:00 2001 From: Simon Gerber Date: Thu, 9 Dec 2021 17:56:56 +0100 Subject: [PATCH 04/17] Move local environment tooling to `local-env/` --- README.md | 23 ++++-------------- local-env/README.md | 24 +++++++++++++++++++ setup-kind.sh => local-env/setup-kind.sh | 0 {templates => local-env/templates}/README.md | 0 .../templates}/kind-oidc.yaml.tpl | 0 .../templates}/realm.json.tpl | 0 6 files changed, 28 insertions(+), 19 deletions(-) create mode 100644 local-env/README.md rename setup-kind.sh => local-env/setup-kind.sh (100%) rename {templates => local-env/templates}/README.md (100%) rename {templates => local-env/templates}/kind-oidc.yaml.tpl (100%) rename {templates => local-env/templates}/realm.json.tpl (100%) diff --git a/README.md b/README.md index a2db4e8c..e40399fc 100644 --- a/README.md +++ b/README.md @@ -31,25 +31,10 @@ CRDs can be installed on the cluster by running `kubectl apply -k config/crd/api ## Local development environment -We provide a script and some templates to setup a local test environment based on [kind](https://kind.sigs.k8s.io/). -The templates can be found in directory `templates/`. - -### Prerequisites - -* `bash` -* `sed` -* `kind` -* `kubectl` -* `kubelogin` as `kubectl-oidc_login` - -The setup script will provide links to the install guides for `kind`, `kubectl` and `kubelogin` if no appropriate command is found. - -### Installation - -The `setup.sh` script will guide you through the setup. -There are some steps that you have to perform manually on a Keycloak instance, which the script prompts you for. -The script defaults to VSHN's APPUiO Dev Keycloak instance, but you can provide an URL pointing to a different instance during the install process. +You can setup a kind-based local environment with ```bash -./setup.sh +make local-env-setup ``` + +See the [local-env/README.md](./local-env/README.md) for more details on the local environment setup. diff --git a/local-env/README.md b/local-env/README.md new file mode 100644 index 00000000..02ca9b20 --- /dev/null +++ b/local-env/README.md @@ -0,0 +1,24 @@ +# Local development environment + +We provide a script and some templates to setup a local test environment based on [kind](https://kind.sigs.k8s.io/). +The templates can be found in directory `templates/`. + +## Prerequisites + +* `bash` +* `sed` +* `kind` +* `kubectl` +* `kubelogin` as `kubectl-oidc_login` + +The setup script will provide links to the install guides for `kind`, `kubectl` and `kubelogin` if no appropriate command is found. + +## Installation + +The `setup.sh` script will guide you through the setup. +There are some steps that you have to perform manually on a Keycloak instance, which the script prompts you for. +The script defaults to VSHN's APPUiO Dev Keycloak instance, but you can provide an URL pointing to a different instance during the install process. + +```bash +./setup.sh +``` diff --git a/setup-kind.sh b/local-env/setup-kind.sh similarity index 100% rename from setup-kind.sh rename to local-env/setup-kind.sh diff --git a/templates/README.md b/local-env/templates/README.md similarity index 100% rename from templates/README.md rename to local-env/templates/README.md diff --git a/templates/kind-oidc.yaml.tpl b/local-env/templates/kind-oidc.yaml.tpl similarity index 100% rename from templates/kind-oidc.yaml.tpl rename to local-env/templates/kind-oidc.yaml.tpl diff --git a/templates/realm.json.tpl b/local-env/templates/realm.json.tpl similarity index 100% rename from templates/realm.json.tpl rename to local-env/templates/realm.json.tpl From 06666db0ac542158e8e46c9a98a845a2f701f52f Mon Sep 17 00:00:00 2001 From: Simon Gerber Date: Fri, 10 Dec 2021 10:30:27 +0100 Subject: [PATCH 05/17] Add kind as a go dependency --- go.mod | 1 + go.sum | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/go.mod b/go.mod index 88dc4283..8aa83b73 100644 --- a/go.mod +++ b/go.mod @@ -70,6 +70,7 @@ require ( k8s.io/klog/v2 v2.9.0 // indirect k8s.io/kube-openapi v0.0.0-20211109043538-20434351676c // indirect k8s.io/utils v0.0.0-20210819203725-bdf08cb9a70a // indirect + sigs.k8s.io/kind v0.11.1 // indirect sigs.k8s.io/kustomize/api v0.10.1 // indirect sigs.k8s.io/kustomize/cmd/config v0.10.2 // indirect sigs.k8s.io/kustomize/kyaml v0.13.0 // indirect diff --git a/go.sum b/go.sum index f5c469c6..ff740d1a 100644 --- a/go.sum +++ b/go.sum @@ -46,6 +46,7 @@ github.com/Azure/go-autorest/autorest/date v0.3.0/go.mod h1:BI0uouVdmngYNUzGWeSY github.com/Azure/go-autorest/autorest/mocks v0.4.1/go.mod h1:LTp+uSrOhSkaKrUy935gNZuuIPPVsHlr9DSOxSayd+k= github.com/Azure/go-autorest/logger v0.2.1/go.mod h1:T9E3cAhj2VqvPOtCYAvby9aBXkZmbF5NWuPV8+WeEW8= github.com/Azure/go-autorest/tracing v0.6.0/go.mod h1:+vhtPC754Xsa23ID7GlGsrdKBpUA79WCAKPPZVC2DeU= +github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ= @@ -60,6 +61,8 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuy github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= +github.com/alessio/shellescape v1.4.1 h1:V7yhSDDn8LP4lc4jS8pFkt0zCnzVJlG5JXy9BVKJUX0= +github.com/alessio/shellescape v1.4.1/go.mod h1:PZAiSCk0LJaZkiCSkPv8qIobYglO3FPpyFjDCtHLS30= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= @@ -109,6 +112,7 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= +github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM= github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc= @@ -122,8 +126,11 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.m github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/evanphx/json-patch v0.5.2/go.mod h1:ZWS5hhDbVDyob71nXKNL0+PWn6ToqBHMikGIFbs31qQ= +github.com/evanphx/json-patch v4.9.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= github.com/evanphx/json-patch v4.11.0+incompatible h1:glyUF9yIYtMHzn8xaKw5rMhdWcwsYV8dZHIq5567/xs= github.com/evanphx/json-patch v4.11.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= +github.com/evanphx/json-patch/v5 v5.2.0 h1:8ozOH5xxoMYDt5/u+yMTsVXydVCbTORFnOOoq2lumco= +github.com/evanphx/json-patch/v5 v5.2.0/go.mod h1:G79N1coSVB93tBe7j6PhzjmR3/2VvlbKOFpnXhI9Bw4= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/color v1.12.0 h1:mRhaKNwANqRgUBGKmnI5ZxEk7QXmjQeCcuYFMX2bfcc= github.com/fatih/color v1.12.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM= @@ -134,6 +141,7 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/getsentry/raven-go v0.2.0/go.mod h1:KungGk8q33+aIAZUIVWZDr2OfAEBsO49PX4NzFV5kcQ= +github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/go-errors/errors v1.0.1 h1:LUHzmkK3GUKUrL/1gfBUxAHzcev3apQlezX/+O7ma6w= github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= @@ -150,12 +158,16 @@ github.com/go-logr/logr v0.4.0 h1:K7/B1jt6fIBQVd4Owv2MqGQClcgf0R266+7C/QjRcLc= github.com/go-logr/logr v0.4.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU= github.com/go-logr/zapr v0.4.0 h1:uc1uML3hRYL9/ZZPdgHS/n8Nzo+eaYL/Efxkkamf7OM= github.com/go-logr/zapr v0.4.0/go.mod h1:tabnROwaDl0UNxkVeFRbY8bwB37GwRv0P8lg6aAiEnk= +github.com/go-openapi/jsonpointer v0.19.2/go.mod h1:3akKfEdA7DF1sugOqz1dVQHBcuDBPKZGEoHC/NkiQRg= github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY= github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= +github.com/go-openapi/jsonreference v0.19.2/go.mod h1:jMjeRr2HHw6nAVajTXJ4eiUwohSTlpa0o73RUL1owJc= github.com/go-openapi/jsonreference v0.19.3/go.mod h1:rjx6GuL8TTa9VaixXglHmQmIL98+wF9xc8zWvFonSJ8= github.com/go-openapi/jsonreference v0.19.5 h1:1WJP/wi4OjB4iV8KVbH73rQaoialJrqv8gitZLxGLtM= github.com/go-openapi/jsonreference v0.19.5/go.mod h1:RdybgQwPxbL4UEjuAruzK1x3nE69AqPYEJeo/TWfEeg= +github.com/go-openapi/spec v0.19.3/go.mod h1:FpwSN1ksY1eteniUU7X0N/BgJ7a4WvBFVA8Lj9mJglo= +github.com/go-openapi/swag v0.19.2/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= github.com/go-openapi/swag v0.19.14 h1:gm3vOOXfiuw5i9p5N9xJvfjvuofpyvLA9Wr6QfK5Fng= github.com/go-openapi/swag v0.19.14/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ= @@ -241,6 +253,7 @@ github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= +github.com/googleapis/gnostic v0.4.1/go.mod h1:LRhVm6pbyptWbWbuZ38d1eyptfvIytN3ir6b65WBswg= github.com/googleapis/gnostic v0.5.1/go.mod h1:6U4PtQXGIEt/Z3h5MAT7FNofLnw9vXk2cUuW7uA/OeU= github.com/googleapis/gnostic v0.5.5/go.mod h1:7+EbHbldMins07ALC74bsA81Ovc97DwqyJO1AENw9kA= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= @@ -306,6 +319,7 @@ github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFB github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= @@ -363,11 +377,13 @@ github.com/olekukonko/tablewriter v0.0.4 h1:vHD/YYe1Wolo78koG299f7V/VAS08c6IpCLn github.com/olekukonko/tablewriter v0.0.4/go.mod h1:zq6QwlOf5SlnkVbMSr5EoBv3636FWnp+qbPhuoO21uA= github.com/onsi/ginkgo v0.0.0-20170829012221-11459a886d9c/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.11.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY= github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc= github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= +github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/onsi/gomega v1.14.0/go.mod h1:cIuvLEne0aoVhAgh/O6ac0Op8WWw9H6eYCriF+tEHG0= @@ -376,6 +392,8 @@ github.com/onsi/gomega v1.15.0/go.mod h1:cIuvLEne0aoVhAgh/O6ac0Op8WWw9H6eYCriF+t github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= +github.com/pelletier/go-toml v1.8.1/go.mod h1:T2/BmBdy8dvIRq1a/8aqjN41wvWlN4lrapLU/GW4pbc= +github.com/pelletier/go-toml v1.9.3 h1:zeC5b1GviRUyKYd6OJPvBU/mcVDVoL1OhT17FCt5dSQ= github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -432,6 +450,7 @@ github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE= +github.com/spf13/cobra v1.1.1/go.mod h1:WnodtKOvamDL/PwE2M4iKs8aMDBZ5Q5klgD3qfVJQMI= github.com/spf13/cobra v1.1.3/go.mod h1:pGADOWyqRD/YMrPZigI/zbliZ2wVD/23d+is3pSWzOo= github.com/spf13/cobra v1.2.1 h1:+KmjbUw1hriSNMF55oPrkZcb27aECyrj8V2ytv7kWDw= github.com/spf13/cobra v1.2.1/go.mod h1:ExllRjgxM/piMAM+3tAZvg8fsklGAf3tPfi+i8t68Nk= @@ -518,6 +537,7 @@ golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnf golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= @@ -643,6 +663,7 @@ golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190616124812-15dcb6c0061f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -675,6 +696,7 @@ golang.org/x/sys v0.0.0-20200831180312-196b9ba8737a/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200905004654-be1d3432aa8f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200923182605-d9f96fdee20d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201112073958-5cba982894dd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210104204734-6f8348627aad/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -723,6 +745,7 @@ golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBn golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190614205625-5aca471b1d59/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190624222133-a101b041ded4/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= @@ -926,6 +949,7 @@ k8s.io/api v0.22.4 h1:UvyHW0ezB2oIgHAxlYoo6UJQObYXU7awuNarwoHEOjw= k8s.io/api v0.22.4/go.mod h1:Rgs+9gIGYC5laXQSZZ9JqT5NevNgoGiOdVWi1BAB3qk= k8s.io/apiextensions-apiserver v0.22.2 h1:zK7qI8Ery7j2CaN23UCFaC1hj7dMiI87n01+nKuewd4= k8s.io/apiextensions-apiserver v0.22.2/go.mod h1:2E0Ve/isxNl7tWLSUDgi6+cmwHi5fQRdwGVCxbC+KFA= +k8s.io/apimachinery v0.20.2/go.mod h1:WlLqWAHZGg07AeltaI0MV5uk1Omp8xaN0JGLY6gkRpU= k8s.io/apimachinery v0.22.2/go.mod h1:O3oNtNadZdeOMxHFVxOreoznohCpy0z6mocxbZr7oJ0= k8s.io/apimachinery v0.22.4 h1:9uwcvPpukBw/Ri0EUmWz+49cnFtaoiyEhQTK+xOe7Ck= k8s.io/apimachinery v0.22.4/go.mod h1:yU6oA6Gnax9RrxGzVvPFFJ+mpnW6PBSqp0sx0I0HHW0= @@ -937,8 +961,10 @@ k8s.io/gengo v0.0.0-20200413195148-3a45101e95ac/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8 k8s.io/gengo v0.0.0-20201214224949-b6c5ce23f027/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E= k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE= k8s.io/klog/v2 v2.2.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y= +k8s.io/klog/v2 v2.4.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y= k8s.io/klog/v2 v2.9.0 h1:D7HV+n1V57XeZ0m6tdRkfknthUaM06VFbWldOFh8kzM= k8s.io/klog/v2 v2.9.0/go.mod h1:hy9LJ/NvuK+iVyP4Ehqva4HxZG/oXyIS3n3Jmire4Ec= +k8s.io/kube-openapi v0.0.0-20201113171705-d219536bb9fd/go.mod h1:WOJ3KddDSol4tAGcJo0Tvi+dK12EcqSLqcWsryKMpfM= k8s.io/kube-openapi v0.0.0-20210421082810-95288971da7e/go.mod h1:vHXdDvt9+2spS2Rx9ql3I8tycm3H9FDfdUoIuKCefvw= k8s.io/kube-openapi v0.0.0-20211109043538-20434351676c h1:jvamsI1tn9V0S8jicyX82qaFC0H/NKxv2e5mbqsgR80= k8s.io/kube-openapi v0.0.0-20211109043538-20434351676c/go.mod h1:vHXdDvt9+2spS2Rx9ql3I8tycm3H9FDfdUoIuKCefvw= @@ -952,6 +978,8 @@ sigs.k8s.io/controller-runtime v0.10.3 h1:s5Ttmw/B4AuIbwrXD3sfBkXwnPMMWrqpVj4WRt sigs.k8s.io/controller-runtime v0.10.3/go.mod h1:CQp8eyUQZ/Q7PJvnIrB6/hgfTC1kBkGylwsLgOQi1WY= sigs.k8s.io/controller-tools v0.7.0 h1:iZIz1vEcavyEfxjcTLs1WH/MPf4vhPCtTKhoHqV8/G0= sigs.k8s.io/controller-tools v0.7.0/go.mod h1:bpBAo0VcSDDLuWt47evLhMLPxRPxMDInTEH/YbdeMK0= +sigs.k8s.io/kind v0.11.1 h1:pVzOkhUwMBrCB0Q/WllQDO3v14Y+o2V0tFgjTqIUjwA= +sigs.k8s.io/kind v0.11.1/go.mod h1:fRpgVhtqAWrtLB9ED7zQahUimpUXuG/iHT88xYqEGIA= sigs.k8s.io/kustomize/api v0.10.1 h1:KgU7hfYoscuqag84kxtzKdEC3mKMb99DPI3a0eaV1d0= sigs.k8s.io/kustomize/api v0.10.1/go.mod h1:2FigT1QN6xKdcnGS2Ppp1uIWrtWN28Ms8A3OZUZhwr8= sigs.k8s.io/kustomize/cmd/config v0.10.2 h1:2GD3+knDaqZo6rSibkc4kKGp8auNBJrGPZQCTWN4Rtc= @@ -963,5 +991,6 @@ sigs.k8s.io/kustomize/kyaml v0.13.0/go.mod h1:FTJxEZ86ScK184NpGSAQcfEqee0nul8oLC sigs.k8s.io/structured-merge-diff/v4 v4.0.2/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK1F7G282QMXDPYydCw= sigs.k8s.io/structured-merge-diff/v4 v4.1.2 h1:Hr/htKFmJEbtMgS/UD0N+gtgctAqz81t3nu+sPzynno= sigs.k8s.io/structured-merge-diff/v4 v4.1.2/go.mod h1:j/nl6xW8vLS49O8YvXW1ocPhZawJtm+Yrr7PPRQ0Vg4= +sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q= sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc= From 062e9215d4d2738a11ab0cbc0bc5a906fc82ba22 Mon Sep 17 00:00:00 2001 From: Simon Gerber Date: Thu, 9 Dec 2021 17:58:40 +0100 Subject: [PATCH 06/17] Vaguely replicate K8up e2e setup --- .gitignore | 6 ++++-- Makefile | 10 ++++++++++ Makefile.vars.mk | 10 ++++++++++ README.md | 2 +- local-env/Makefile | 44 +++++++++++++++++++++++++++++++++++++++++ local-env/kind.mk | 30 ++++++++++++++++++++++++++++ local-env/setup-kind.sh | 29 ++++++++++++++++++--------- 7 files changed, 119 insertions(+), 12 deletions(-) create mode 100644 local-env/Makefile create mode 100644 local-env/kind.mk diff --git a/.gitignore b/.gitignore index 330d42a0..ab83aa3b 100644 --- a/.gitignore +++ b/.gitignore @@ -27,8 +27,10 @@ _archive/ crd*.yaml /control-api -/kind.kubeconfig -/realm.json +/local-env/kind-kubeconfig-* +/local-env/realm.json +/local-env/.created +/local-env/.kind-setup_complete # Go releaser dist/ diff --git a/Makefile b/Makefile index 3fc527ea..06a946d4 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,8 @@ MAKEFLAGS += --no-builtin-variables PROJECT_ROOT_DIR = . include Makefile.vars.mk +localenv_make := $(MAKE) -C local-env + .PHONY: help help: ## Show this help @grep -E -h '\s##\s' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' @@ -56,6 +58,14 @@ build.docker: $(BIN_FILENAME) ## Build the docker image clean: ## Cleans up the generated resources rm -rf dist/ cover.out $(BIN_FILENAME) || true +.PHONY: local-env +local-env-setup: ## Setup local kind-based dev environment + $(localenv_make) setup + +.PHONY: local-env-clean-setup +local-env-clean-setup: ## Setup local kind-based dev environment + $(localenv_make) clean-setup + ### ### Assets ### diff --git a/Makefile.vars.mk b/Makefile.vars.mk index 6e2a5896..42eb00f7 100644 --- a/Makefile.vars.mk +++ b/Makefile.vars.mk @@ -10,3 +10,13 @@ KUSTOMIZE ?= go run sigs.k8s.io/kustomize/kustomize/v4 # Image URL to use all building/pushing image targets GHCR_IMG ?= ghcr.io/appuio/control-api:$(IMG_TAG) + +# Local dev environment setup +localenv_dir ?= $(CURDIR)/$(PROJECT_ROOT_DIR)/local-env +localenv_dir_created = $(localenv_dir)/.created + +# Kind config +KIND_NODE_VERSION ?= v1.22.1 +KIND ?= go run sigs.k8s.io/kind +KIND_KUBECONFIG ?= $(localenv_dir)/kind-kubeconfig-$(KIND_NODE_VERSION) +KIND_CLUSTER ?= control-api-$(KIND_NODE_VERSION) diff --git a/README.md b/README.md index e40399fc..8b86949c 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ CRDs can be installed on the cluster by running `kubectl apply -k config/crd/api You can setup a kind-based local environment with ```bash -make local-env-setup +local-env/setup-kind.sh ``` See the [local-env/README.md](./local-env/README.md) for more details on the local environment setup. diff --git a/local-env/Makefile b/local-env/Makefile new file mode 100644 index 00000000..a813fef2 --- /dev/null +++ b/local-env/Makefile @@ -0,0 +1,44 @@ +# Set Shell to bash, otherwise some targets fail with dash/zsh etc. +SHELL := /bin/bash + +# Disable built-in rules +MAKEFLAGS += --no-builtin-rules +MAKEFLAGS += --no-builtin-variables +.SUFFIXES: +.SECONDARY: + +PROJECT_ROOT_DIR = .. +include ../Makefile.vars.mk +include kind.mk + +uname_s := $(shell uname -s) +ifeq ($(uname_s),Linux) + xargs := xargs --no-run-if-empty +else + xargs := xargs +endif + +.DEFAULT_GOAL := help + +.PHONY: setup +setup: export KUBECONFIG = $(KIND_KUBECONFIG) +setup: $(localenv_dir_created) kind-setup ## Setup the local environment + +.PHONY: clean-setup +clean-setup: export KUBECONFIG = $(KIND_KUBECONFIG) +clean-setup: kind-clean ## Clean the local environment (e.g. to rerun the setup) + rm $(localenv_dir_created) || true + +.PHONY: help +help: ## Show this help + @grep -E -h '\s##\s' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' + +### +### Artifacts +### + +# a marker file must be created, because the date of the +# directory may update when content in it is created/updated, +# which would cause a rebuild / re-initialization of dependants +$(localenv_dir_created): + @touch $(localenv_dir_created) diff --git a/local-env/kind.mk b/local-env/kind.mk new file mode 100644 index 00000000..eaf8f669 --- /dev/null +++ b/local-env/kind.mk @@ -0,0 +1,30 @@ +kind_marker := $(localenv_dir)/.kind-setup_complete + +curl_args ?= --location --fail --silent --show-error + +.DEFAULT_TARGET: kind-setup + +.PHONY: kind-setup +kind-setup: export KUBECONFIG = $(KIND_KUBECONFIG) +kind-setup: $(kind_marker) $(localenv_dir_created) ## Creates the kind cluster + +.PHONY: kind-clean +kind-clean: export KUBECONFIG = $(KIND_KUBECONFIG) +kind-clean: ## Remove the kind Cluster + @$(KIND) delete cluster --name $(KIND_CLUSTER) || true + @rm $(kind_marker) $(KIND_KUBECONFIG) || true + +### +### Artifacts +### + +$(KIND_KUBECONFIG): export KUBECONFIG = $(KIND_KUBECONFIG) +$(KIND_KUBECONFIG): + $(localenv_dir)/setup-kind.sh "$(KIND)" "$(KIND_CLUSTER)" "$(KIND_NODE_VERSION)" "$(KIND_KUBECONFIG)" + @kubectl version + @kubectl cluster-info + +$(kind_marker): export KUBECONFIG = $(KIND_KUBECONFIG) +$(kind_marker): $(KIND_KUBECONFIG) + @kubectl config use-context kind-$(KIND_CLUSTER) + @touch $(kind_marker) diff --git a/local-env/setup-kind.sh b/local-env/setup-kind.sh index 9ad0a46b..59a1691f 100755 --- a/local-env/setup-kind.sh +++ b/local-env/setup-kind.sh @@ -1,6 +1,14 @@ #!/bin/bash # vim:sts=2:ts=2:et:sw=2:tw=0 +readonly script_dir=$(dirname "$0") +readonly kind_cmd="${1}" +readonly kind_cluster="${2}" +readonly kind_node_version="${3}" +readonly kind_kubeconfig="${4}" + +export KUBECONFIG="${kind_kubeconfig}" + keycloak_url=https://id.dev.appuio.cloud step() { @@ -18,31 +26,34 @@ check_command() { check_command "kubectl" "kubectl" "https://kubernetes.io/docs/tasks/tools/#kubectl" check_command "kubectl-oidc_login" "kubectl oidc-login plugin" "Follow the instructions at https://github.com/int128/kubelogin#setup" -check_command "kind" "kind" "https://kind.sigs.k8s.io/docs/user/quick-start/#installation" +echo read -r -p "Provide the URL of the Keycloak to connect the local environment to (default=${keycloak_url}): " user_url if [ x"${user_url}" != x"" ]; then keycloak_url="${user_url}" fi +echo identifier= while [ x"$identifier" == x"" ]; do read -r -p "Provide an identifier for your local-dev Keycloak realm: " identifier done realm_name="local-dev-${identifier}" -sed -e "s/REPLACEME/${realm_name}/g" templates/realm.json.tpl > realm.json +sed -e "s/REPLACEME/${realm_name}/g" "${script_dir}/templates/realm.json.tpl" > "${script_dir}/realm.json" -step "Navigate to ${keycloak_url} and create a new realm by importing the 'realm.json' file in this directory". +step "Navigate to ${keycloak_url} and create a new realm by importing the '${script_dir}/realm.json' file." step "Create a user in the new realm, grant it realm role 'admin', and ensure 'Email Verified' is set to 'On'." step "Note: In the next step, a browser window will open where you have to sign in to Keycloak with the user you've created in the previous step". -export KUBECONFIG=./kind.kubeconfig -sed -e "s#ISSUER_KEYCLOAK#${keycloak_url}#; s/REALM/${realm_name}/g" templates/kind-oidc.yaml.tpl > .kind-oidc.yaml -kind create cluster --name appuio-cloud-controlapi-localdev --config=.kind-oidc.yaml -rm .kind-oidc.yaml +sed -e "s#ISSUER_KEYCLOAK#${keycloak_url}#; s/REALM/${realm_name}/g" "${script_dir}/templates/kind-oidc.yaml.tpl" > "${script_dir}/.kind-oidc.yaml" +${kind_cmd} create cluster \ + --name "${kind_cluster}" \ + --image "kindest/node:${kind_node_version}" \ + --config="${script_dir}/.kind-oidc.yaml" +rm "${script_dir}/.kind-oidc.yaml" kubectl apply -f - < Date: Fri, 10 Dec 2021 10:34:34 +0100 Subject: [PATCH 07/17] Provide cleaned file paths in setup-kind.sh script --- local-env/setup-kind.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/local-env/setup-kind.sh b/local-env/setup-kind.sh index 59a1691f..21d95cfe 100755 --- a/local-env/setup-kind.sh +++ b/local-env/setup-kind.sh @@ -42,7 +42,7 @@ done realm_name="local-dev-${identifier}" sed -e "s/REPLACEME/${realm_name}/g" "${script_dir}/templates/realm.json.tpl" > "${script_dir}/realm.json" -step "Navigate to ${keycloak_url} and create a new realm by importing the '${script_dir}/realm.json' file." +step "Navigate to ${keycloak_url} and create a new realm by importing the '$(realpath "${script_dir}/realm.json")' file." step "Create a user in the new realm, grant it realm role 'admin', and ensure 'Email Verified' is set to 'On'." @@ -81,4 +81,4 @@ kubectl config set-credentials oidc-user \ kubectl config set-context --current --user=oidc-user kubectl apply -k "${script_dir}/../config/crd/apiextensions.k8s.io/v1" -step "Setup finished. Set environment variable KUBECONFIG to '${kind_kubeconfig}' to interact with the local dev cluster" +step "Setup finished. Set environment variable KUBECONFIG to '$(realpath "${kind_kubeconfig}")' to interact with the local dev cluster" From 15d6ea2437e549ef175b4f6e27390e922e3149f1 Mon Sep 17 00:00:00 2001 From: Simon Gerber Date: Fri, 10 Dec 2021 10:34:49 +0100 Subject: [PATCH 08/17] Suppress output of `kubectl oidc-login setup` --- local-env/setup-kind.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/local-env/setup-kind.sh b/local-env/setup-kind.sh index 21d95cfe..3065a13f 100755 --- a/local-env/setup-kind.sh +++ b/local-env/setup-kind.sh @@ -69,7 +69,7 @@ subjects: EOF kubectl oidc-login setup \ --oidc-issuer-url="${keycloak_url}/auth/realms/${realm_name}" \ - --oidc-client-id=local-dev + --oidc-client-id=local-dev >/dev/null 2>&1 kubectl config set-credentials oidc-user \ --exec-api-version=client.authentication.k8s.io/v1beta1 \ --exec-command=kubectl \ From 5465f67a4929867715048c969a1437cbf7eb66fa Mon Sep 17 00:00:00 2001 From: Simon Gerber Date: Tue, 14 Dec 2021 10:36:39 +0100 Subject: [PATCH 09/17] Update READMEs to match the latest implementation --- README.md | 2 +- local-env/README.md | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 8b86949c..e40399fc 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ CRDs can be installed on the cluster by running `kubectl apply -k config/crd/api You can setup a kind-based local environment with ```bash -local-env/setup-kind.sh +make local-env-setup ``` See the [local-env/README.md](./local-env/README.md) for more details on the local environment setup. diff --git a/local-env/README.md b/local-env/README.md index 02ca9b20..9c5b89a0 100644 --- a/local-env/README.md +++ b/local-env/README.md @@ -11,14 +11,16 @@ The templates can be found in directory `templates/`. * `kubectl` * `kubelogin` as `kubectl-oidc_login` -The setup script will provide links to the install guides for `kind`, `kubectl` and `kubelogin` if no appropriate command is found. +The setup script will provide links to the install guides for `kubectl` and `kubelogin` if no appropriate command is found. ## Installation -The `setup.sh` script will guide you through the setup. +The `setup-kind.sh` script will guide you through the setup. There are some steps that you have to perform manually on a Keycloak instance, which the script prompts you for. The script defaults to VSHN's APPUiO Dev Keycloak instance, but you can provide an URL pointing to a different instance during the install process. -```bash -./setup.sh +Since the setup script requires a few arguments, we provide a make target to run the script: + +``` +make setup ``` From bbf8920fbf01b7ee6e18a8b95d5e8721ea5a66e5 Mon Sep 17 00:00:00 2001 From: Simon Gerber Date: Tue, 14 Dec 2021 10:36:52 +0100 Subject: [PATCH 10/17] Update local-env cleanup target name and help text --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 06a946d4..0f4778c3 100644 --- a/Makefile +++ b/Makefile @@ -63,7 +63,7 @@ local-env-setup: ## Setup local kind-based dev environment $(localenv_make) setup .PHONY: local-env-clean-setup -local-env-clean-setup: ## Setup local kind-based dev environment +local-env-clean: ## Clean the local dev environment $(localenv_make) clean-setup ### From 5b0e813a00329def417feea992593edd35e8ac6d Mon Sep 17 00:00:00 2001 From: Simon Gerber Date: Tue, 14 Dec 2021 10:41:24 +0100 Subject: [PATCH 11/17] Add default values for setup-kind.sh command line arguments --- local-env/setup-kind.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/local-env/setup-kind.sh b/local-env/setup-kind.sh index 3065a13f..64d1f1aa 100755 --- a/local-env/setup-kind.sh +++ b/local-env/setup-kind.sh @@ -2,10 +2,10 @@ # vim:sts=2:ts=2:et:sw=2:tw=0 readonly script_dir=$(dirname "$0") -readonly kind_cmd="${1}" -readonly kind_cluster="${2}" -readonly kind_node_version="${3}" -readonly kind_kubeconfig="${4}" +readonly kind_cmd="${1:-kind}" +readonly kind_cluster="${2:-control-api-localenv}" +readonly kind_node_version="${3:-v1.22.1}" +readonly kind_kubeconfig="${4:-"${script_dir}/control-api.kubeconfig"}" export KUBECONFIG="${kind_kubeconfig}" From 5fbd0f6b353f81144bcf70913e978a02baabcd83 Mon Sep 17 00:00:00 2001 From: Simon Gerber Date: Tue, 14 Dec 2021 10:52:19 +0100 Subject: [PATCH 12/17] Exit script on errors --- local-env/setup-kind.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/local-env/setup-kind.sh b/local-env/setup-kind.sh index 64d1f1aa..5bc6f029 100755 --- a/local-env/setup-kind.sh +++ b/local-env/setup-kind.sh @@ -1,6 +1,8 @@ #!/bin/bash # vim:sts=2:ts=2:et:sw=2:tw=0 +set -euo pipefail + readonly script_dir=$(dirname "$0") readonly kind_cmd="${1:-kind}" readonly kind_cluster="${2:-control-api-localenv}" From 69f07ab8e9114b10ed921dfd85c8a410ba741618 Mon Sep 17 00:00:00 2001 From: Simon Gerber Date: Tue, 14 Dec 2021 10:53:07 +0100 Subject: [PATCH 13/17] Make user setup instructions clearer --- local-env/setup-kind.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/local-env/setup-kind.sh b/local-env/setup-kind.sh index 5bc6f029..88155186 100755 --- a/local-env/setup-kind.sh +++ b/local-env/setup-kind.sh @@ -15,7 +15,7 @@ keycloak_url=https://id.dev.appuio.cloud step() { echo - echo "$1" + echo -e "$1" read -n 1 -s -r -p "Press any key to continue" echo } @@ -46,7 +46,7 @@ sed -e "s/REPLACEME/${realm_name}/g" "${script_dir}/templates/realm.json.tpl" > step "Navigate to ${keycloak_url} and create a new realm by importing the '$(realpath "${script_dir}/realm.json")' file." -step "Create a user in the new realm, grant it realm role 'admin', and ensure 'Email Verified' is set to 'On'." +step "Create a user in the new realm, grant it realm role 'admin'.\nMake sure the user has an email configured and 'Email Verified' is set to 'On'." step "Note: In the next step, a browser window will open where you have to sign in to Keycloak with the user you've created in the previous step". From 8afbfb44b791dda92c478aeb0a12fef206a023fe Mon Sep 17 00:00:00 2001 From: Simon Gerber Date: Tue, 14 Dec 2021 10:53:27 +0100 Subject: [PATCH 14/17] Make note about having to login bold but don't prompt user to continue --- local-env/setup-kind.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/local-env/setup-kind.sh b/local-env/setup-kind.sh index 88155186..c911051f 100755 --- a/local-env/setup-kind.sh +++ b/local-env/setup-kind.sh @@ -48,7 +48,11 @@ step "Navigate to ${keycloak_url} and create a new realm by importing the '$(rea step "Create a user in the new realm, grant it realm role 'admin'.\nMake sure the user has an email configured and 'Email Verified' is set to 'On'." -step "Note: In the next step, a browser window will open where you have to sign in to Keycloak with the user you've created in the previous step". +echo "" +echo -e "\033[1m================================================================================" +echo "Note: After the cluster is created, a browser window will open where you have to sign in to Keycloak with the user you've created in the previous step." +echo -e "================================================================================\033[0m" +echo "" sed -e "s#ISSUER_KEYCLOAK#${keycloak_url}#; s/REALM/${realm_name}/g" "${script_dir}/templates/kind-oidc.yaml.tpl" > "${script_dir}/.kind-oidc.yaml" ${kind_cmd} create cluster \ From 4d351a15252ad38af38bbe6cda7aa189f79343cf Mon Sep 17 00:00:00 2001 From: Simon Gerber Date: Tue, 14 Dec 2021 10:55:52 +0100 Subject: [PATCH 15/17] Remove user prompt at the end of the script --- local-env/setup-kind.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/local-env/setup-kind.sh b/local-env/setup-kind.sh index c911051f..91d65a6d 100755 --- a/local-env/setup-kind.sh +++ b/local-env/setup-kind.sh @@ -87,4 +87,4 @@ kubectl config set-credentials oidc-user \ kubectl config set-context --current --user=oidc-user kubectl apply -k "${script_dir}/../config/crd/apiextensions.k8s.io/v1" -step "Setup finished. Set environment variable KUBECONFIG to '$(realpath "${kind_kubeconfig}")' to interact with the local dev cluster" +echo "Setup finished. Set environment variable KUBECONFIG to '$(realpath "${kind_kubeconfig}")' to interact with the local dev cluster" From 438a77009cc1c18a898304d39ee0e30b6df99fd8 Mon Sep 17 00:00:00 2001 From: Simon Gerber Date: Tue, 14 Dec 2021 11:09:36 +0100 Subject: [PATCH 16/17] Add note about K8s distribution in README --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e40399fc..8ae48751 100644 --- a/README.md +++ b/README.md @@ -31,10 +31,14 @@ CRDs can be installed on the cluster by running `kubectl apply -k config/crd/api ## Local development environment -You can setup a kind-based local environment with +You can setup a [kind]-based local environment with ```bash make local-env-setup ``` See the [local-env/README.md](./local-env/README.md) for more details on the local environment setup. + +Please be aware that the productive deployment of the control-api may run on a different Kubernetes distribution than [kind]. + +[kind]: https://kind.sigs.k8s.io/ From efe41125e1608b4a7f3be9c02135a5da679838d1 Mon Sep 17 00:00:00 2001 From: Simon Gerber Date: Tue, 14 Dec 2021 13:03:08 +0100 Subject: [PATCH 17/17] Apply suggestions from code review Co-authored-by: Chris --- local-env/setup-kind.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/local-env/setup-kind.sh b/local-env/setup-kind.sh index 91d65a6d..316b39a1 100755 --- a/local-env/setup-kind.sh +++ b/local-env/setup-kind.sh @@ -27,7 +27,7 @@ check_command() { } check_command "kubectl" "kubectl" "https://kubernetes.io/docs/tasks/tools/#kubectl" -check_command "kubectl-oidc_login" "kubectl oidc-login plugin" "Follow the instructions at https://github.com/int128/kubelogin#setup" +check_command "kubectl-oidc_login" "kubectl oidc-login plugin" "https://github.com/int128/kubelogin#setup" echo read -r -p "Provide the URL of the Keycloak to connect the local environment to (default=${keycloak_url}): " user_url @@ -87,4 +87,7 @@ kubectl config set-credentials oidc-user \ kubectl config set-context --current --user=oidc-user kubectl apply -k "${script_dir}/../config/crd/apiextensions.k8s.io/v1" -echo "Setup finished. Set environment variable KUBECONFIG to '$(realpath "${kind_kubeconfig}")' to interact with the local dev cluster" +echo ======= +echo "Setup finished. To interact with the local dev cluster, set the KUBECONFIG environment variable as follows:" +echo "\"export \$KUBECONFIG=$(realpath "${kind_kubeconfig}")\"" +echo =======