Skip to content

Instantly share code, notes, and snippets.

@abstractmachines
Last active September 21, 2021 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abstractmachines/45e0a2c1b74368192f474542bd326afc to your computer and use it in GitHub Desktop.
Save abstractmachines/45e0a2c1b74368192f474542bd326afc to your computer and use it in GitHub Desktop.
Kubernetes envtest: An API Server

Kubernetes envtest

A testing environment for Kubernetes

Note: Everything mentioned here is also in the Controller Runtime's pkg envtest docs.

envtest can run on a local control plane, or an existing cluster.

  • To start up a local control plane, envtest spins up a local instance of control plane binaries. These would be, etcd and kube-apiserver. It's available as a package under controller-runtime.
  • Alternatively, an existing cluster can be used to run envtest, by loading up CRDs and client config.
  • We'll focus on the local control plane implementation instead. It provides a little cluster we can work with for our little test environment, and the lack of things such as a scheduler will allow us to learn more about the kube-apiserver along the way.

envtest in a local control plane is (basically) merely an API server (and etcd).

@abstractmachines
Copy link
Author

Setting up fixtures in envtest

pod := &corev1.Pod{
		ObjectMeta: metav1.ObjectMeta{
			Name:      "test-pod-123",
			Namespace: "default",
		},
		Spec: corev1.PodSpec{
			NodeName: nodeName,
			Containers: []corev1.Container{{
				Name:  "main-123",
				Image: "none",
			}},
		},
	}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment