- Notifications
You must be signed in to change notification settings - Fork0
test
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
parent directory.. | ||||
This document outlines the testing strategy forkro, focusing onintegration tests andend-to-end testing. It defines the purpose,approach and boundaries of each type of testing, providing clear guidelines forcontributors and maintainers.
kro is a complex controller that interacts with multiple Kubernetes resourcesand depends on various Kubernetes features, such as custom resources, customcontrollers, informers, and client-go. The testing strategy aims to ensure thatkro works as expected in a Kubernetes environment, and that it can be safelydeployed in production clusters.
- Use existing Kubernetes testing frameworks (when possible): Don't reinventthe wheel. If a feature is not covered by existing frameworks, contribute tothem.
- Focus on kro's logic, not on other controllers or Kubernetes components. e.gavoid 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 e2etests
- 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 andits interactions with the Kubernetes API server. Instead of emulating othercontrollers, 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 updatedcorrectly
- 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 areal Kubernetes environment. These tests ensure that kro works correctly withactual Kubernetes resources and other controllers. The approach for E2E testsshould:
- 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 fulllifecycle.
- 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 ResourceGroupinstances to test kro at scale.
- Failure recovery: Simulate failures in the controller or the Kubernetes APIserver and verify that kro recovers correctly
- Controller upgrade testing: Deploy a new version of kro and verify that itcan handle existing
ResourceGroups
andResourceGroup
instances - ResourceGroup conflict testing: Create multiple
ResourceGroups
withconflicting resources and verify that kro handles the conflicts correctly - Integration with other controllers: Deploy other controllers that interactwith kro resources and verify that they work correctly together