Skip to content

Commit

Permalink
Update the local testing with Kind with some scripts to create and de…
Browse files Browse the repository at this point in the history
…lete the cluster
  • Loading branch information
dlbock committed Dec 7, 2020
1 parent d07f72b commit d9477ea
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 45 deletions.
4 changes: 2 additions & 2 deletions docs/build.md
Expand Up @@ -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 .
```

Expand All @@ -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 .
```
59 changes: 16 additions & 43 deletions docs/testing-with-kind.md
Expand Up @@ -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
---------------
Expand All @@ -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
```
22 changes: 22 additions & 0 deletions 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
5 changes: 5 additions & 0 deletions e2e-testing/with-kind/delete-cluster.sh
@@ -0,0 +1,5 @@
#!/bin/bash

set -e

kind delete cluster
15 changes: 15 additions & 0 deletions 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
15 changes: 15 additions & 0 deletions 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

0 comments on commit d9477ea

Please sign in to comment.