Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start e2e tests #58

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Start e2e tests #58

wants to merge 1 commit into from

Conversation

nirs
Copy link
Owner

@nirs nirs commented Aug 25, 2024

The e2e module contains a helper tool (e2e) and a test suite (gather_test.go).

The helper tool creates and deletes 2 kind clusters. This takes about 35 seconds, and will likely take more when the cluster are more interesting, so we keep it outside of the test suite. This way we can run tests very quickly with the same cluster. Since the gathering from a cluster is mostly immutable, reusing the same cluster is safe.

Issues:

  • The test suite contain one trivial test, gathering both clusters
  • Gathered data is not validated yet
  • The logs are too noisy. We need to log debug logs only to test log. Normal output should include only the major events.
  • Test configurations and gathered output are stored in the e2e directory. This should move to a temporary test directory.

Example test flow:

$ make
go build -o e2e ./cmd

$ ./e2e
Manage the e2e testing environment

Usage:
  e2e [command]

Available Commands:
  completion  Generate the autocompletion script for the specified shell
  create      Create the e2e environment
  delete      Delete the e2e environment
  help        Help about any command

Flags:
  -h, --help   help for e2e

Use "e2e [command] --help" for more information about a command.

$ ./e2e create
2024/08/25 09:53:11 Creating clusters
2024/08/25 09:53:11 Creating cluster "kind-c2"
2024/08/25 09:53:11 Creating cluster "kind-c1"
2024/08/25 09:53:11 Running /usr/local/bin/kind create cluster --name c2 --kubeconfig kind-c2.yaml --wait 60s
2024/08/25 09:53:11 Running /usr/local/bin/kind create cluster --name c1 --kubeconfig kind-c1.yaml --wait 60s
2024/08/25 09:53:11 Creating cluster "c2" ...
2024/08/25 09:53:11  • Ensuring node image (kindest/node:v1.31.0) 🖼  ...
2024/08/25 09:53:11 Creating cluster "c1" ...
2024/08/25 09:53:11  • Ensuring node image (kindest/node:v1.31.0) 🖼  ...
2024/08/25 09:53:11  ✓ Ensuring node image (kindest/node:v1.31.0) 🖼
2024/08/25 09:53:11  • Preparing nodes 📦   ...
2024/08/25 09:53:11  ✓ Ensuring node image (kindest/node:v1.31.0) 🖼
2024/08/25 09:53:11  • Preparing nodes 📦   ...
2024/08/25 09:53:12  ✓ Preparing nodes 📦
2024/08/25 09:53:12  ✓ Preparing nodes 📦
2024/08/25 09:53:12  • Writing configuration 📜  ...
2024/08/25 09:53:12  • Writing configuration 📜  ...
2024/08/25 09:53:12  ✓ Writing configuration 📜
2024/08/25 09:53:12  • Starting control-plane 🕹️  ...
2024/08/25 09:53:12  ✓ Writing configuration 📜
2024/08/25 09:53:12  • Starting control-plane 🕹️  ...
2024/08/25 09:53:23  ✓ Starting control-plane 🕹️
2024/08/25 09:53:23  • Installing CNI 🔌  ...
2024/08/25 09:53:23  ✓ Installing CNI 🔌
2024/08/25 09:53:23  • Installing StorageClass 💾  ...
2024/08/25 09:53:23  ✓ Starting control-plane 🕹️
2024/08/25 09:53:23  • Installing CNI 🔌  ...
2024/08/25 09:53:23  ✓ Installing StorageClass 💾
2024/08/25 09:53:23  • Waiting ≤ 1m0s for control-plane = Ready ⏳  ...
2024/08/25 09:53:23  ✓ Installing CNI 🔌
2024/08/25 09:53:23  • Installing StorageClass 💾  ...
2024/08/25 09:53:24  ✓ Installing StorageClass 💾
2024/08/25 09:53:24  • Waiting ≤ 1m0s for control-plane = Ready ⏳  ...
2024/08/25 09:53:40  ✓ Waiting ≤ 1m0s for control-plane = Ready ⏳
2024/08/25 09:53:40  • Ready after 17s 💚
2024/08/25 09:53:40 Set kubectl context to "kind-c1"
2024/08/25 09:53:40 You can now use your cluster with:
2024/08/25 09:53:40
2024/08/25 09:53:40 kubectl cluster-info --context kind-c1 --kubeconfig kind-c1.yaml
2024/08/25 09:53:40
2024/08/25 09:53:40 Thanks for using kind! 😊
2024/08/25 09:53:43  ✓ Waiting ≤ 1m0s for control-plane = Ready ⏳
2024/08/25 09:53:43  • Ready after 19s 💚
2024/08/25 09:53:43 Set kubectl context to "kind-c2"
2024/08/25 09:53:43 You can now use your cluster with:
2024/08/25 09:53:43
2024/08/25 09:53:43 kubectl cluster-info --context kind-c2 --kubeconfig kind-c2.yaml
2024/08/25 09:53:43
2024/08/25 09:53:43 Thanks for using kind! 😊
2024/08/25 09:53:43 Merging cluster kubconfigs to "clusters.yaml"
2024/08/25 09:53:43 Running /usr/bin/kubectl config view --flatten
2024/08/25 09:53:43 Clusters created

$ go test . -count=1
ok  	github.com/nirs/kubectl-gather/e2e	0.177s

$ go test . -count=1 -v
=== RUN   TestGather
2024/08/25 11:53:09 Running ../kubectl-gather --contexts kind-c1,kind-c2 --kubeconfig clusters.yaml --directory test-gather.out
2024/08/25 11:53:09 2024-08-25T11:53:09.144+0300	INFO	gather	Using kubeconfig "clusters.yaml"
2024/08/25 11:53:09 2024-08-25T11:53:09.144+0300	INFO	gather	Gathering from all namespaces
2024/08/25 11:53:09 2024-08-25T11:53:09.145+0300	INFO	gather	Using all addons
2024/08/25 11:53:09 2024-08-25T11:53:09.145+0300	INFO	gather	Gathering from cluster "kind-c1"
2024/08/25 11:53:09 2024-08-25T11:53:09.145+0300	INFO	gather	Gathering from cluster "kind-c2"
2024/08/25 11:53:09 2024-08-25T11:53:09.310+0300	INFO	gather	Gathered 320 resources from cluster "kind-c1" in 0.166 seconds
2024/08/25 11:53:09 2024-08-25T11:53:09.316+0300	INFO	gather	Gathered 338 resources from cluster "kind-c2" in 0.171 seconds
2024/08/25 11:53:09 2024-08-25T11:53:09.316+0300	INFO	gather	Gathered 658 resources from 2 clusters in 0.171 seconds
--- PASS: TestGather (0.19s)
PASS
ok  	github.com/nirs/kubectl-gather/e2e	0.188s

$ ./e2e delete
2024/08/25 09:57:43 Deleting clusters
2024/08/25 09:57:43 Deleting cluster "kind-c2"
2024/08/25 09:57:43 Deleting cluster "kind-c1"
2024/08/25 09:57:43 Running /usr/local/bin/kind delete cluster --name c2 --kubeconfig kind-c2.yaml
2024/08/25 09:57:43 Running /usr/local/bin/kind delete cluster --name c1 --kubeconfig kind-c1.yaml
2024/08/25 09:57:43 Deleting cluster "c2" ...
2024/08/25 09:57:43 Deleting cluster "c1" ...
2024/08/25 09:57:43 Deleted nodes: ["c2-control-plane"]
2024/08/25 09:57:43 Deleted nodes: ["c1-control-plane"]
2024/08/25 09:57:43 Clusters deleted

The e2e module contains a helper tool (e2e) and a test suite
(gather_test.go).

The helper tool creates and deletes 2 kind clusters. This takes about 35
seconds, and will likely take more when the cluster are more
interesting, so we keep it outside of the test suite. This way we can
run tests very quickly with the same cluster. Since the gathering from a
cluster is mostly immutable, reusing the same cluster is safe.

Issues:
- The test suite contain one trivial test, gathering both clusters
- Gathered data is not validated yet
- The logs are too noisy. We need to log debug logs only to test log.
  Normal output should include only the major events.
- Test configurations and gathered output are stored in the e2e
  directory.  This should move to a temporary test directory.

Example test flow:

    $ make
    go build -o e2e ./cmd

    $ ./e2e
    Manage the e2e testing environment

    Usage:
      e2e [command]

    Available Commands:
      completion  Generate the autocompletion script for the specified shell
      create      Create the e2e environment
      delete      Delete the e2e environment
      help        Help about any command

    Flags:
      -h, --help   help for e2e

    Use "e2e [command] --help" for more information about a command.

    $ ./e2e create
    2024/08/25 09:53:11 Creating clusters
    2024/08/25 09:53:11 Creating cluster "kind-c2"
    2024/08/25 09:53:11 Creating cluster "kind-c1"
    2024/08/25 09:53:11 Running /usr/local/bin/kind create cluster --name c2 --kubeconfig kind-c2.yaml --wait 60s
    2024/08/25 09:53:11 Running /usr/local/bin/kind create cluster --name c1 --kubeconfig kind-c1.yaml --wait 60s
    2024/08/25 09:53:11 Creating cluster "c2" ...
    2024/08/25 09:53:11  • Ensuring node image (kindest/node:v1.31.0) 🖼  ...
    2024/08/25 09:53:11 Creating cluster "c1" ...
    2024/08/25 09:53:11  • Ensuring node image (kindest/node:v1.31.0) 🖼  ...
    2024/08/25 09:53:11  ✓ Ensuring node image (kindest/node:v1.31.0) 🖼
    2024/08/25 09:53:11  • Preparing nodes 📦   ...
    2024/08/25 09:53:11  ✓ Ensuring node image (kindest/node:v1.31.0) 🖼
    2024/08/25 09:53:11  • Preparing nodes 📦   ...
    2024/08/25 09:53:12  ✓ Preparing nodes 📦
    2024/08/25 09:53:12  ✓ Preparing nodes 📦
    2024/08/25 09:53:12  • Writing configuration 📜  ...
    2024/08/25 09:53:12  • Writing configuration 📜  ...
    2024/08/25 09:53:12  ✓ Writing configuration 📜
    2024/08/25 09:53:12  • Starting control-plane 🕹️  ...
    2024/08/25 09:53:12  ✓ Writing configuration 📜
    2024/08/25 09:53:12  • Starting control-plane 🕹️  ...
    2024/08/25 09:53:23  ✓ Starting control-plane 🕹️
    2024/08/25 09:53:23  • Installing CNI 🔌  ...
    2024/08/25 09:53:23  ✓ Installing CNI 🔌
    2024/08/25 09:53:23  • Installing StorageClass 💾  ...
    2024/08/25 09:53:23  ✓ Starting control-plane 🕹️
    2024/08/25 09:53:23  • Installing CNI 🔌  ...
    2024/08/25 09:53:23  ✓ Installing StorageClass 💾
    2024/08/25 09:53:23  • Waiting ≤ 1m0s for control-plane = Ready ⏳  ...
    2024/08/25 09:53:23  ✓ Installing CNI 🔌
    2024/08/25 09:53:23  • Installing StorageClass 💾  ...
    2024/08/25 09:53:24  ✓ Installing StorageClass 💾
    2024/08/25 09:53:24  • Waiting ≤ 1m0s for control-plane = Ready ⏳  ...
    2024/08/25 09:53:40  ✓ Waiting ≤ 1m0s for control-plane = Ready ⏳
    2024/08/25 09:53:40  • Ready after 17s 💚
    2024/08/25 09:53:40 Set kubectl context to "kind-c1"
    2024/08/25 09:53:40 You can now use your cluster with:
    2024/08/25 09:53:40
    2024/08/25 09:53:40 kubectl cluster-info --context kind-c1 --kubeconfig kind-c1.yaml
    2024/08/25 09:53:40
    2024/08/25 09:53:40 Thanks for using kind! 😊
    2024/08/25 09:53:43  ✓ Waiting ≤ 1m0s for control-plane = Ready ⏳
    2024/08/25 09:53:43  • Ready after 19s 💚
    2024/08/25 09:53:43 Set kubectl context to "kind-c2"
    2024/08/25 09:53:43 You can now use your cluster with:
    2024/08/25 09:53:43
    2024/08/25 09:53:43 kubectl cluster-info --context kind-c2 --kubeconfig kind-c2.yaml
    2024/08/25 09:53:43
    2024/08/25 09:53:43 Thanks for using kind! 😊
    2024/08/25 09:53:43 Merging cluster kubconfigs to "clusters.yaml"
    2024/08/25 09:53:43 Running /usr/bin/kubectl config view --flatten
    2024/08/25 09:53:43 Clusters created

    $ go test . -count=1
    ok  	github.com/nirs/kubectl-gather/e2e	0.177s

    $ go test . -count=1 -v
    === RUN   TestGather
    2024/08/25 11:53:09 Running ../kubectl-gather --contexts kind-c1,kind-c2 --kubeconfig clusters.yaml --directory test-gather.out
    2024/08/25 11:53:09 2024-08-25T11:53:09.144+0300	INFO	gather	Using kubeconfig "clusters.yaml"
    2024/08/25 11:53:09 2024-08-25T11:53:09.144+0300	INFO	gather	Gathering from all namespaces
    2024/08/25 11:53:09 2024-08-25T11:53:09.145+0300	INFO	gather	Using all addons
    2024/08/25 11:53:09 2024-08-25T11:53:09.145+0300	INFO	gather	Gathering from cluster "kind-c1"
    2024/08/25 11:53:09 2024-08-25T11:53:09.145+0300	INFO	gather	Gathering from cluster "kind-c2"
    2024/08/25 11:53:09 2024-08-25T11:53:09.310+0300	INFO	gather	Gathered 320 resources from cluster "kind-c1" in 0.166 seconds
    2024/08/25 11:53:09 2024-08-25T11:53:09.316+0300	INFO	gather	Gathered 338 resources from cluster "kind-c2" in 0.171 seconds
    2024/08/25 11:53:09 2024-08-25T11:53:09.316+0300	INFO	gather	Gathered 658 resources from 2 clusters in 0.171 seconds
    --- PASS: TestGather (0.19s)
    PASS
    ok  	github.com/nirs/kubectl-gather/e2e	0.188s

    $ ./e2e delete
    2024/08/25 09:57:43 Deleting clusters
    2024/08/25 09:57:43 Deleting cluster "kind-c2"
    2024/08/25 09:57:43 Deleting cluster "kind-c1"
    2024/08/25 09:57:43 Running /usr/local/bin/kind delete cluster --name c2 --kubeconfig kind-c2.yaml
    2024/08/25 09:57:43 Running /usr/local/bin/kind delete cluster --name c1 --kubeconfig kind-c1.yaml
    2024/08/25 09:57:43 Deleting cluster "c2" ...
    2024/08/25 09:57:43 Deleting cluster "c1" ...
    2024/08/25 09:57:43 Deleted nodes: ["c2-control-plane"]
    2024/08/25 09:57:43 Deleted nodes: ["c1-control-plane"]
    2024/08/25 09:57:43 Clusters deleted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant