From d9477ea7fa3066fd2cdca596a364d4f585590517 Mon Sep 17 00:00:00 2001 From: Dahlia Bock Date: Fri, 4 Dec 2020 10:22:22 -0600 Subject: [PATCH] Update the local testing with Kind with some scripts to create and delete the cluster --- docs/build.md | 4 +- docs/testing-with-kind.md | 59 +++++-------------- e2e-testing/with-kind/create-cluster.sh | 22 +++++++ e2e-testing/with-kind/delete-cluster.sh | 5 ++ e2e-testing/with-kind/kind-config-darwin.yaml | 15 +++++ e2e-testing/with-kind/kind-config-linux.yaml | 15 +++++ 6 files changed, 75 insertions(+), 45 deletions(-) create mode 100755 e2e-testing/with-kind/create-cluster.sh create mode 100755 e2e-testing/with-kind/delete-cluster.sh create mode 100644 e2e-testing/with-kind/kind-config-darwin.yaml create mode 100644 e2e-testing/with-kind/kind-config-linux.yaml diff --git a/docs/build.md b/docs/build.md index 99579c73..5aa3ffd5 100644 --- a/docs/build.md +++ b/docs/build.md @@ -4,7 +4,7 @@ Building the Instana Agent Operator from Source The following command will build the `instana/instana-agent-operator` Docker image locally: ```bash -./mvnw package +./mvnw -C -B clean package docker build -f src/main/docker/Dockerfile.jvm -t instana/instana-agent-operator . ``` @@ -13,6 +13,6 @@ To build the Docker image with GraalVM native image, use the following command: > Note: The native image does not work yet because of [https://github.com/quarkusio/quarkus/issues/3077](https://github.com/quarkusio/quarkus/issues/3077) ```bash -./mvnw package -Pnative -Dnative-image.docker-build=true +./mvnw -C -B clean package -Pnative -Dnative-image.docker-build=true docker build -f src/main/docker/Dockerfile.native -t instana/instana-agent-operator . ``` diff --git a/docs/testing-with-kind.md b/docs/testing-with-kind.md index 64131586..c6932eda 100644 --- a/docs/testing-with-kind.md +++ b/docs/testing-with-kind.md @@ -10,57 +10,25 @@ Kind (**K**ubernetes **in** **D**ocker) will set up a local cluster where all no Set up a local Kubernetes Cluster with Kind ------------------------------------------- -Create `kind-config.yaml` with the following content (replace `/home` with `/Users` on macOS): - -```yaml -kind: Cluster -apiVersion: kind.sigs.k8s.io/v1alpha3 -nodes: -- role: control-plane - extraMounts: - - containerPath: /hosthome - hostPath: /home -- role: worker - extraMounts: - - containerPath: /hosthome - hostPath: /home -- role: worker - extraMounts: - - containerPath: /hosthome - hostPath: /home -``` - Install [kind](https://kind.sigs.k8s.io/) (a single executable that can be downloaded from the [Github release page](https://github.com/kubernetes-sigs/kind/releases)) and run the following commands to create the cluster: ```sh -kind --config kind-config.yaml create cluster -export KUBECONFIG="$(kind get kubeconfig-path --name="kind")" -kubectl get nodes +./e2e-testing/with-kind/create-cluster.sh ``` You should see a cluster with one control-pane and two worker nodes up and running. -Prepare the Docker Images -------------------------- - -In the `instana-agent-operator` project, build the `instana/instana-agent-operator` Docker image and push it to the local Kind cluster: - -```sh -mvn package docker:build -kind load docker-image instana/instana-agent-operator -``` - -Pull the `instana/agent` Docker image and push it to the local Kind cluster: - -```sh -docker pull instana/agent -kind load docker-image instana/agent -``` +This script will also do the following: +- Build the `instana/instana-agent-operator` Docker image locally and load it into the local Kind cluster +- Pull the latest `instana/agent` Docker image locally and load it into the local Kind cluster Install the Operator -------------------- -Follow the steps described in [Install Operator Manually](https://docs.instana.io/setup_and_manage/host_agent/on/kubernetes/#install-operator-manually) +Follow the steps described in [Install Operator Manually](https://www.instana.com/docs/setup_and_manage/host_agent/on/kubernetes/#install-operator-manually). + +Instead of using the `instana-agent-operator.yaml` file directly from the latest [GitHub release](https://github.com/instana/instana-agent-operator/releases), download that latest `instana-agent-operator.yaml` file locally, and change the `imagePullPolicy` for the `Deployment` from `Always` to `IfNotPresent`. +This will ensure that it uses the locally built `instana/instana-agent-operator` image. Expected result --------------- @@ -69,12 +37,17 @@ Expected result kubectl -n instana-agent get pods ``` -should show two instances of the `instana-agent-operator` (see the number of `replicas` configured in `instana-agent-operator-deploy.yaml`), and two instances of `instana-agent` (one on each node in the cluster). +This should show one instance of the `instana-agent-operator` (see the number of `replicas` configured in `olm/operator-resources/instana-agent-operator.yaml`), and two instances of `instana-agent` (one on each worker node in the cluster). + +Delete a node +------------- + +Delete one of the worker nodes that is running the `instana-agent` leader pod. The operator should reassign leadership to another agent pod. +You should see the reassignment if you tail the logs for the operator pod. Clean up -------- ```sh -kind delete cluster -unset KUBECONFIG +./e2e-testing/with-kind/delete-cluster.sh ``` diff --git a/e2e-testing/with-kind/create-cluster.sh b/e2e-testing/with-kind/create-cluster.sh new file mode 100755 index 00000000..d26efdad --- /dev/null +++ b/e2e-testing/with-kind/create-cluster.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +set -e + +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +BASE_DIR="$SCRIPT_DIR/../../" +OS_NAME=$(uname | tr '[:upper:]' '[:lower:]') +KIND_CONFIG_FILE="$SCRIPT_DIR/kind-config-$OS_NAME.yaml" + +printf "%s\n" "Creating cluster with kind-config-$OS_NAME.yaml" +kind --config $KIND_CONFIG_FILE create cluster + +kubectl get nodes + +printf "%s\n" "Build and load Operator image into kind cluster" +./mvnw -C -B clean package +docker build -f $BASE_DIR/src/main/docker/Dockerfile.jvm -t instana/instana-agent-operator $BASE_DIR +kind load docker-image instana/instana-agent-operator + +printf "%s\n" "Load Agent image into kind cluster" +docker pull instana/agent +kind load docker-image instana/agent diff --git a/e2e-testing/with-kind/delete-cluster.sh b/e2e-testing/with-kind/delete-cluster.sh new file mode 100755 index 00000000..a85c68e6 --- /dev/null +++ b/e2e-testing/with-kind/delete-cluster.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +set -e + +kind delete cluster diff --git a/e2e-testing/with-kind/kind-config-darwin.yaml b/e2e-testing/with-kind/kind-config-darwin.yaml new file mode 100644 index 00000000..726d675c --- /dev/null +++ b/e2e-testing/with-kind/kind-config-darwin.yaml @@ -0,0 +1,15 @@ +kind: Cluster +apiVersion: kind.x-k8s.io/v1alpha4 +nodes: + - role: control-plane + extraMounts: + - containerPath: /hosthome + hostPath: /Users + - role: worker + extraMounts: + - containerPath: /hosthome + hostPath: /Users + - role: worker + extraMounts: + - containerPath: /hosthome + hostPath: /Users diff --git a/e2e-testing/with-kind/kind-config-linux.yaml b/e2e-testing/with-kind/kind-config-linux.yaml new file mode 100644 index 00000000..5730f528 --- /dev/null +++ b/e2e-testing/with-kind/kind-config-linux.yaml @@ -0,0 +1,15 @@ +kind: Cluster +apiVersion: kind.x-k8s.io/v1alpha4 +nodes: + - role: control-plane + extraMounts: + - containerPath: /hosthome + hostPath: /home + - role: worker + extraMounts: + - containerPath: /hosthome + hostPath: /home + - role: worker + extraMounts: + - containerPath: /hosthome + hostPath: /home