HTTP/API/Kubernetes Mock Server¶
KMock is a dummy/mock server to mimick the Kubernetes API, any other API, or bare HTTP servers.
The main practical purpose is testing Kubernetes operators developed with Kopf, operators migrated to or from Kopf (whether Pythonic or not), and for testing Kopf itself. Kopf is a framework to write Kubernetes operators in Python.
Usually, the developers populate the server with Kubernetes resources, raw request patterns and their supposed responses, then use the locally running server via any HTTP/API client of choice, be that in the same framework in Python or something external (e.g. curl, even kubectl). In the end, the developers assert which endpoints were called, with which specific requests, how many times, so on — thus verifying that the developed client works as intended.
KMock runs well with looptime, the time dilation/contraction library for asyncio & pytest.
Tutorial:
HTTP/API mocking:
Kubernetes mocking:
Developer's manuals:
Reference:
- kmock package
AiohttpInterceptorSelectableRequestCriteriaRawHandlerServerKubernetesScaffoldKubernetesEmulatorSinkBoxactionmethoddatatextbodyparamsheaderscookiesresourcesubresource()name()namespace()ViewRootGroupOrGroupAndGroupChainedExclusionSlicerFilterPriorityReactionStreamObjectVersionObjectHistoryObjectObjectsArrayResourceDictResourceInfoResourcesArrayKubernetesErrorKubernetesNotFoundErrorKubernetesEndpointNotFoundErrorKubernetesResourceNotFoundErrorKubernetesObjectNotFoundError