Skip to content

kokuwaio/k3s-maven-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

k3s Maven Plugin

Apache License 2.0 Maven Central Build

This is a plugin to manage k3s for integration tests.

Why k3s-maven-plugin?

For unit testing JUnit5 and Testcontainers (e.g. for PostgreSQL) can be used. This is not sufficient for complex setups or running systems for ui development outside of JUnit context. docker-compose is a common technology to describe this setups.

If your production system is Kubernetes it would be better to use some kind of Kubernetes for integration tests:

Because k3s has a very fast startup and can run in docker this plugin relies on k3s. This plugin runs k3s as docker container (like k3d). As alternative it was considered to use k3s in rootless mode. This assumes packages like newguimap which are not installed everywhere. Feel free to create a PR for adding a non-docker mode of this plugin.

If you don't like to use this plugin you can:

Goals

Goal Description Default Lifecycle Phase
k3s:run Create and start k3s container pre-integration-test
k3s:image Prepare images for containerd pre-integration-test
k3s:apply Run kubectl aplpy pre-integration-test
k3s:restart Restart resources pre-integration-test
k3s:rm Stop and remove k3s containers post-integration-test

Examples

To plugin is tested with maven-invoker-plugin. The testcases can be used as examples.

  • manifest are applied with k3s:apply
  • k3s and pod image is always pulled via k3s:iamge, pod has imagePullPolicy: Never
  • Pod is running with hostport 8080
  • test uses http://127.0.0.1:8080 as endpoint
  • manifest are applied with k3s:apply
  • image is build with jib-maven-plugin to tar file
  • image is imported from tar file
  • image is Never pulled from registries
  • Pod is running with hostport 8080
  • test uses http://127.0.0.1:8080 as endpoint
  • manifest are applied with k3s:apply
  • image is build with jib-maven-plugin to local docker deamon
  • image is imported from local docker deamon
  • image is Never pulled from registries
  • Pod is running with hostport 8080
  • test uses http://127.0.0.1:8080 as endpoint
  • manifest are applied with k3s:apply using custom command with kustomize
  • PostgreSQL is running with hostport 5432
  • test uses http://127.0.0.1:5432 as endpoint
  • manifest are generated with helm template, using the helm-maven-plugin
  • manifest are applied with k3s:apply
  • test itself doesn't assert anything, but success verifies that the job completed and was taken as success.

Usage out of Build

Add to your settings.xml (or prefix goals with groupId):

<pluginGroups>
 ...
 <pluginGroup>io.kokuwa.maven</pluginGroup>
</pluginGroups>

Start k3s with deployments for manual testing:

mvn k3s:run k3s:apply \
  -Dk3s.portBindings=8080:8080 \
  -Dk3s.manifests=src/it/traefik/src/test/k3s \
  -Dk3s.kustomize'
  -Dk3s.debug

Now you can access this urls:

Use external kubectl:

export KUBECONFIG=~/.kube/k3s-maven-plugin/mount/kubeconfig.yaml && kubectl get all --all-namespaces

Stop k3s after manual testing:

mvn k3s:rm