Skip to content

Conversation

@kacpersaw
Copy link
Contributor

Summary

Add integration tests that run against a real Kubernetes cluster using KinD (Kubernetes in Docker). This addresses #58.

Changes

New Files

  • integration_test.go - Integration tests with build tag //go:build integration
  • .github/workflows/integration.yaml - CI workflow for integration tests
  • scripts/kind-setup.sh - Helper script for local development

Test Coverage

Test Description
TestIntegration_PodEvents Pod creation and deletion events
TestIntegration_ReplicaSetEvents ReplicaSet event handling
TestIntegration_MultiNamespace Multi-namespace support
TestIntegration_LabelSelector Label selector filtering

CI Workflow

The new workflow runs in sequence:

  1. Lint - golangci-lint
  2. Unit tests - go test ./... -race
  3. Integration tests - Runs only after lint and unit tests pass, using KinD cluster
  • 10 minute timeout for the integration job
  • Runs on pushes to main and on all PRs

Local Development

# Create a KinD cluster
./scripts/kind-setup.sh create

# Run integration tests
go test -tags=integration -v ./...

# Clean up when done
./scripts/kind-setup.sh delete

Implementation Notes

  • Uses the existing fakeAgentAPI to mock the Coder server - this keeps tests fast and focused on validating real Kubernetes informer behavior
  • Tests create isolated namespaces with unique names and clean up after themselves
  • Pods use NodeSelector with non-existent labels to stay in Pending state (avoids needing to actually run containers)

Closes #58

@kacpersaw kacpersaw force-pushed the kacpersaw/kind-integration-tests branch from 65a45d7 to f58945d Compare December 9, 2025 09:47
Add integration tests that run against a real Kubernetes cluster using
KinD (Kubernetes in Docker). This addresses #58.

Changes:
- Add integration_test.go with tests for:
  - Pod events (create/delete)
  - ReplicaSet events
  - Multi-namespace support
  - Label selector filtering
- Add .github/workflows/integration.yaml CI workflow that:
  - Runs lint and unit tests first
  - Then runs integration tests with KinD
  - 10 minute timeout
- Add scripts/kind-setup.sh for local development
- Update README.md with integration test documentation

The integration tests use the existing fakeAgentAPI to mock the Coder
server, focusing on validating real Kubernetes informer behavior.
The integration tests were using quartz.NewMock(t) which creates a mock
clock that doesn't advance automatically. This caused timeouts when
waiting for log source registration because the timers in the log
queuer never fired.

Changes:
- Remove mock clock usage from all integration tests
- Use real clock (nil) which is the default
- Reduce logDebounce to 5s for faster test execution
- Increase informer sync wait to 1s for reliability
The tests now use waitForLogContaining which continuously collects
logs until finding the expected message, rather than expecting
specific messages in the first batch of logs received.

This fixes flaky tests caused by Kubernetes scheduling events
arriving before pod lifecycle events.
@kacpersaw kacpersaw force-pushed the kacpersaw/kind-integration-tests branch from 3aef12d to 7630eda Compare December 11, 2025 09:07
Copy link
Member

@deansheather deansheather left a comment

Choose a reason for hiding this comment

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

LGTM if it passes shellcheck. I don't think adding a job for shellchecking is necessary though.

- Add safety check to prevent running integration tests against
  non-KinD clusters (detects localhost/127.0.0.1/kind in host)
- Use SHA pinning for GitHub Actions with version comments
- Add INTEGRATION_TEST_UNSAFE=1 escape hatch for special cases
@kacpersaw kacpersaw force-pushed the kacpersaw/kind-integration-tests branch from 36ff121 to 693e95e Compare December 15, 2025 14:16
- Add Makefile with build, test, lint, and fmt targets
- Fix shellcheck warnings in scripts/helm.sh and scripts/version.sh
- Format shell scripts with shfmt
- Update actions/checkout to v6.0.1
- Update actions/setup-go to v6.1.0
- Update helm/kind-action to v1.13.0
- Remove buildcoder-logstream-kube from .gitignore
- Fix safety check logic: check INTEGRATION_TEST_UNSAFE env var
  before calling t.Fatalf, not after
- Fix .gitignore: add coder-logstream-kube and build/ on separate lines
@kacpersaw kacpersaw merged commit 8ea3f21 into main Dec 15, 2025
3 checks passed
@kacpersaw kacpersaw deleted the kacpersaw/kind-integration-tests branch December 15, 2025 15:32
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.

Add integration testing using KinD

2 participants