This document outlines the testing strategy for kro, focusing on integration tests and end-to-end testing. It defines the purpose, approach and boundaries of each type of testing, providing clear guidelines for contributors and maintainers.
kro is a complex controller that interacts with multiple Kubernetes resources and depends on various Kubernetes features, such as custom resources, custom controllers, informers, and client-go. The testing strategy aims to ensure that kro works as expected in a Kubernetes environment, and that it can be safely deployed in production clusters.
- Use existing Kubernetes testing frameworks (when possible): Don't reinvent the wheel. If a feature is not covered by existing frameworks, contribute to them.
- Focus on kro's logic, not on other controllers or Kubernetes components. e.g avoid testing native controllers, ACK or Karpenter's behaviour...
- Prioritize integration tests, validate with end to end tests.
- Maintain seperation of concerns, controller logic, integration tests, and e2e tests
- Ensure readability: similar to the codebase, tests should be easy to read, understand and maintain.
integration/
: Contains integration test suites for kro.e2e/
: Contains e2e test suites for kro.testdata/
: Directory for test data, such as Kubernetes manifests, resourcegroups ...
In integration tests, the focus should be on your custom controller's logic and its interactions with the Kubernetes API server. Instead of emulating other controllers, you should:
- Mock the Kubernetes API server responses
- Verify that your controller makes the correct API calls
- Test your controller's reconciliation logic
- Check status updates on your custom resources
- Create a ResourceGroup
- Trigger ResourceGroup reconciliation
- Check that the ResourceGroup status was updated correctly
- Verify that the correct Create (CRD) call was made to the API server
- Check that the controller is watching the correct RG instances
- Create a ResourceGroup instance
- Trigger the ResourceGroup instance reconciliation
- Check that the ResourceGroup instance status was updated correctly
- Verify that the some resources were created in the cluster
- Trigger a second reconciliation and check that the status was updated correctly
- Repeat until all the RG instances are created
- Do the same for updates and deletions
E2E tests for kro should focus on validating the entire system's behavior in a real Kubernetes environment. These tests ensure that kro works correctly with actual Kubernetes resources and other controllers. The approach for E2E tests should:
- Use a real Kubernetes cluster (e.g. kind, minikube, or EKS)
- Deploy kro controller and it's CRDs
- Deploy other controllers or resources that will interact with kro resources.
- Create kro ResourceGroups and ResourceGroupInstances and verify their full lifecycle.
- Deploy kro controller and CRDs
- Deploy a sample application that uses kro
- Create a
ResourceGroup
custom resource - Verify that the corresponding CRD is created in the cluster
- Create an instance of the
ResourceGroup
- Wait for all resources defined in the
ResourceGroup
to be created - Verify that all resources are correctly created and configured
- Update the
ResourceGroup
instance - Verify that the changes are correctly propagated to the managed resources
- Delete the
ResourceGroup
instance - Verify that all managed resources are correctly deleted
- Delete the
ResourceGroup
custom resource - Verify that the corresponding CRD is removed from the cluster
- Cross namespace resource management
- Scaling testing: Create a large number of ResourceGroups and ResourceGroup instances to test kro at scale.
- Failure recovery: Simulate failures in the controller or the Kubernetes API server and verify that kro recovers correctly
- Controller upgrade testing: Deploy a new version of kro and verify that it
can handle existing
ResourceGroups
andResourceGroup
instances - ResourceGroup conflict testing: Create multiple
ResourceGroups
with conflicting resources and verify that kro handles the conflicts correctly - Integration with other controllers: Deploy other controllers that interact with kro resources and verify that they work correctly together