This tool allows you to easily create and delete mock resources for stoplightio/prism within your Kubernetes cluster. Prism responds to requests based on your OpenAPI definition.
The tool not only creates a Pod for Prism, but also provisions related resources such as AWS ECR, Kubernetes Namespace, Deployment, Service, and VirtualService. By editing the VirtualService, you can introduce fixed delays using fault injection, providing a more realistic mock environment.
This should be especially useful for load testing or developing microservice clients.
- AWS and Kubernetes credentials
- Go
- kubectl
- Docker
Copy and paste your OpenAPI definition into app/openapi.yaml
.
In my case, I use awsp and kubie.
awsp <your_profile>
kubie ctx <your_context>
Regardless of the tools you use, please ensure your credentials are set.
Set the necessary parameters in config/params.yaml
.
At a minimum, you need to set the following parameters:
- microserviceName
- Your microservice name
- microserviceNamespace
- Your microservice namespace
Run the following command:
$ make run-create
The following resources will be created:
- AWS
- ECR
- Kubernetes
- Namespace
- Deployment
- Service
- VirtualService
To make your mock more realistic, set spec.http.fault.delay.fixedDelay
in the VirtualService resource.
$ kubectl edit VirtualService -n <your_namespace> <your_virtual_service_name>
You can now perform load testing!
Make sure to specify the mock Service.
When you're done, delete the mock resources with:
$ make run-delete
Parameter Name | Description | Default | Required |
---|---|---|---|
microserviceName |
Name of microservice | sample |
Yes |
microserviceNamespace |
Namespace of microservice | sample |
Yes |
prismMockSuffix |
Suffix for the mock service name | "-prism-mock" |
Yes |
timeout |
Timeout for this tool | 10m |
No |
prismPort |
Port number for Prism | 80 |
No |
prismCpu |
CPU request for Prism | "500m" |
No |
prismMemory |
Memory request for Prism | "512Mi" |
No |
istioMode |
Whether to use istio | true |
No |
istioProxyCpu |
CPU request for Istio | "500m" |
No |
istioProxyMemory |
Memory request for Istio | "512Mi" |
No |
priorityClassName |
Value of priorityClassName | - | No |
ecrTags |
Pairs of ECR tag | - | No |
sample:
microserviceName: "sample"
microserviceNamespace: "sample"
prismMockSuffix: "-prism-mock"
istioMode: false
priorityClassName: "high-priority"
ecrTags:
- key: "CostEnv"
value: "stg"
- key: "CostService"
value: "pet-store"
Please install the following tools before running the test:
- kind
- istio-ctl
$ make test-go
This make target runs the go unit tests.
$ make test-e2e
This make target does the following:
- Setup kind cluster
- Boot mock resources on the cluster
- Boot curl pod on the cluster
- Execute curl command from the curl pod to the mock service
- Check the response
This takes a few minutes to wait resources to be ready.
Please install golangci-lint
before running the lint:
https://golangci-lint.run/welcome/install/#local-installation
$ make lint