Skip to content

Unit tests rely on $KUBECONFIG / an active cluster

Summary

In this thread, we found that we had broken unit tests by removing the KUBECONFIG project variable. This means they were relying on an active cluster running to execute the tests.

Instead, we can run the tests in a container that has etcd and kube-apiserver installed to have better testing isolation.

Here's an example of how I test locally:

#!/bin/bash

HELM_CHARTS=$PWD/charts \
  GITLAB_OPERATOR_ASSETS=$PWD/hack/assets \
  TEST_ASSET_KUBE_APISERVER=/usr/local/bin/kube-apiserver \
  TEST_ASSET_ETCD=/usr/local/bin/etcd \
  ginkgo -progress -focus 'controller' -cover -outputdir=coverage ./...

We should be able to adapt this into the unit test jobs in CI and remove our hidden dependency on KUBECONFIG.

Acceptance criteria

  • Unit tests run without KUBECONFIG defined, instead leveraging locally-installed etcd and kube-apiserver
  • Timeouts increased in !203 (merged) are reverted
Edited by Mitchell Nielsen