Skip to content

Commit

Permalink
Complete k8s integration tests (#340)
Browse files Browse the repository at this point in the history
* Add kubernetes version test
* Add k8s integration test target
* Remove superseded kubernetes e2e tests
---------

Signed-off-by: Pablo Chacin <[email protected]>
  • Loading branch information
pablochacin authored Sep 13, 2023
1 parent f3324fa commit ce51386
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 239 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ e2e-disruptors: agent-image e2e-setup
e2e-cluster:
go test -tags e2e ./e2e/cluster/...

e2e-kubernetes:
go test -tags e2e ./e2e/kubernetes/...

e2e-setup: build-e2e
build/e2e-cluster setup

Expand All @@ -45,7 +42,10 @@ format:
integration-agent: agent-image
go test -tags integration ./pkg/agent/...

integration: integration-agent
integration-kubernetes:
go test -tags integration ./pkg/kubernetes/...

integration: integration-agent integration-kubernetes

# Running with -buildvcs=false works around the issue of `go list all` failing when git, which runs as root inside
# the container, refuses to operate on the disruptor source tree as it is not owned by the same user (root).
Expand Down
231 changes: 0 additions & 231 deletions e2e/kubernetes/kubernetes_e2e_test.go

This file was deleted.

43 changes: 43 additions & 0 deletions pkg/kubernetes/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,3 +306,46 @@ func Test_Kubernetes(t *testing.T) {
}
})
}

func Test_UnsupportedKubernetesVersion(t *testing.T) {
t.Parallel()

ctx := context.Background()

container, err := k3s.RunContainer(ctx, testcontainers.WithImage("docker.io/rancher/k3s:v1.22.17-k3s1"))
if err != nil {
t.Fatal(err)
}

// wait for the api server to complete initialization.
// see this issue for more details:
// https://github.com/testcontainers/testcontainers-go/issues/1547
timeout := time.Second * 30
err = waitForRegex(ctx, container, ".*Node controller sync successful.*", timeout)
if err != nil {
t.Fatalf("failed waiting for cluster ready: %s", err)
}

// Clean up the container after the test is complete
t.Cleanup(func() {
if err = container.Terminate(ctx); err != nil {
t.Fatalf("failed to terminate container: %s", err)
}
})

kubeConfigYaml, err := container.GetKubeConfig(ctx)
if err != nil {
t.Fatalf("failed to get kube-config : %s", err)
}

restcfg, err := clientcmd.RESTConfigFromKubeConfig(kubeConfigYaml)
if err != nil {
t.Fatalf("failed to create rest client for kubernetes : %s", err)
}

_, err = newFromConfig(restcfg)
if err == nil {
t.Errorf("should had failed creating kubernetes client")
return
}
}
6 changes: 2 additions & 4 deletions pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ Fixes # (issue)
- [ ] I have added tests that prove my fix is effective or that my feature works.
- [ ] I have run linter locally (`make lint`) and all checks pass.
- [ ] I have run tests locally (`make test`) and all tests pass.
- [ ] I have run relevant integration test locally (`make integration-xxx` for `agent` related changes)
- [ ] I have run relevant e2e test locally (`make e2e-xxx` for `disruptors`, `kubernetes` or `cluster` related changes)
- [ ] I have run relevant integration test locally (`make integration-xxx` for affected packages)
- [ ] I have run relevant e2e test locally (`make e2e-xxx` for `disruptors`, or `cluster` related changes)
- [ ] Any dependent changes have been merged and published in downstream modules<br>


0 comments on commit ce51386

Please sign in to comment.