Test resources
Try out the resource validation capability in Gloo Gateway to check configuration before you apply it to your cluster.
About
You can use the Kubernetes dry run capability to verify your resource configuration or send requests directly to the Gloo Gateway validation API.
The information in this guide assumes that you enabled strict validation, including the rejection of resources that result in a Warning
state. To enable these settings, update your Gloo Gateway installation and include --set gateway.validation.alwaysAcceptResources=false
, --set gateway.validation.enabled=true
, and --set gateway.validation.allowWarnings=false
. You can also edit the Settings resource directly. For more information, see Enable strict resource validation.
Use the dry run capability in Kubernetes
To test whether a YAML file is accepted by the validation webhook, you can use the kubectl apply --dry-run=server
command as shown in the following examples.
Send requests to the validation API directly
Send a curl request to the validation API to test your resource configurations. For an overview of the fields that you must include as part of your request, see Validation API reference.
If an empty response {}
is returned from the validation API, you might need to add or remove a bracket from your request. This response is returned also if the wrong bracket type is used, such as when you used {}
instead of []
.
The validation API currently assumes that all configuration that is sent to the API passes the Kubernetes object schema validation. For example, if your configuration contains valid Gloo Gateway configuration, but you use an API version or API kind that does not exist in your cluster, the validation API logs a warning, but accepts the request. To ensure that your resource configuration passes the Kubernetes object schema validation, use the dry run capability in Kubernetes instead.
Port-forward the gloo service on port 8443.
Send a request with your resource configuration to the Gloo Gateway validation API. The following example shows successful and unsuccessful resource configuration validation for the RouteOption and VirtualHostOption resources.
Validation API reference
The Gloo Gateway validation API is implemented as a validating admission webhook in Kubernetes with the following sample JSON structure:
Parameter | Type | Required | Description |
---|---|---|---|
request.uid | String | No | A unique identifier for the validation request. You can use this field to find the validation output for a specific resource more easily. |
request.kind | Object | Yes | Information about the type of Kubernetes object that is involved in the validation request. The following fields can be defined:
rules section in the Gloo Gateway validating admission webhook configuration. |
request.resource | Object | Yes | Information about the resource that is admitted to the webhook. In most cases, the resource defined in request.kind and request.resource is the same. They might differ only when changes in API versions or variations in resource naming were introduced, or if the resource that you admit belongs to a subresource. If this is the case, you must include the request.resource field in your request to the validation API. If request.kind and request.resource are the same, the request.resource section can be omitted.The following fields can be defined:
|
request.name | String | No | The name of the resource that you want to validate. |
request.namespace | String | No | The namespace where you want to create, update, or delete the resource. |
request.operation | String | Yes | The operation in Kubernetes that you want to use for your resource. The operation that you can set depends on the resource that you want to validate. You can find supported operations in the rules section in the Gloo Gateway validating admission webhook configuration. |
request.userInfo | Object | No | Information about the user that sends the validation request. The following fields can be provided:
|
request.object | Object | Yes | The resource configuration that you want to validate, such as a RouteOption or VirtualHostOption, in JSON format. Refer to the API reference for more information about the fields that you can set for each resource. |