Skip to content

Controller integration test#43

Merged
piceri merged 12 commits intomainfrom
controller-integration-test
Feb 27, 2026
Merged

Controller integration test#43
piceri merged 12 commits intomainfrom
controller-integration-test

Conversation

@piceri
Copy link
Contributor

@piceri piceri commented Feb 25, 2026

This change adds integration testing to the controller using https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/envtest

The integration test:

  • has a setup function that uses envtest to setup a mock controller environment that can be called by each test
  • Test deployment lifecycle by creating a deployment, scaling up, scaling down, then deleting a deployment
  • Tests deployment with init containers
  • Tests running controller to only watch one namespace
  • Tests running controller with excluded namespaces

@piceri piceri marked this pull request as ready for review February 26, 2026 21:52
@piceri piceri requested a review from a team as a code owner February 26, 2026 21:52
Copilot AI review requested due to automatic review settings February 26, 2026 21:52
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an envtest-based integration test suite for the Kubernetes controller to validate end-to-end behavior (pod lifecycle → deployment record posting) in a realistic API server environment, plus minimal plumbing to make the controller’s poster mockable.

Changes:

  • Introduces internal/controller/controller_integration_test.go with envtest setup and multiple controller integration scenarios (deployment lifecycle, init containers, namespace filtering).
  • Refactors the controller’s apiClient field behind a small interface to enable test-time mocking.
  • Updates make test and GitHub Actions workflow to install/use setup-envtest and set KUBEBUILDER_ASSETS for envtest.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
internal/controller/controller_integration_test.go New envtest integration tests and helper utilities for controller verification.
internal/controller/controller.go Makes the deployment record poster mockable via an interface.
go.mod Adds controller-runtime (envtest) and testify dependencies.
go.sum Updates sums for newly added/updated dependencies.
Makefile Runs tests with KUBEBUILDER_ASSETS populated via setup-envtest.
.github/workflows/build.yml Installs setup-envtest in CI before running make test.
Comments suppressed due to low confidence (1)

internal/controller/controller_integration_test.go:108

  • cache.WaitForCacheSync(ctx.Done(), ...) does not have its own timeout; with a non-cancelled ctx this can block forever and hang the test suite. Consider using a context.WithTimeout (or a time-bounded channel) specifically for cache sync and fail the test if it doesn’t sync in time.
	go func() {
		_ = ctrl.Run(ctx, 1)
	}()
	if !cache.WaitForCacheSync(ctx.Done(), ctrl.podInformer.HasSynced) {
		t.Fatal("timed out waiting for informer cache to sync")
	}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@piceri piceri marked this pull request as draft February 26, 2026 22:13
@piceri piceri marked this pull request as ready for review February 26, 2026 23:26
@piceri piceri merged commit f825daa into main Feb 27, 2026
6 checks passed
@piceri piceri deleted the controller-integration-test branch February 27, 2026 21:04
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.

4 participants