Skip to content

Introduce usage of fieldPath for more readable failure responses #183

@pmalek

Description

@pmalek

Problem statement

Currently, types in this repo do not have fieldPath set in their kubebuilder code markers. This can greatly improve readability of response body when invalid object is provided, e.g.

The KongCustomEntity "degraphql-route-example" is invalid:
* <nil>: Invalid value: "object": The spec.type field is immutable
* spec: Invalid value: "object": The type field cannot be one of the known Kong entity types

vs setting the fieldPath

The KongCustomEntity "degraphql-route-example" is invalid:
* spec.type: Invalid value: "object": The spec.type field is immutable
* spec.type: Invalid value: "object": The type field cannot be one of the known Kong entity types

Proposed solution

Set fieldPath for all relevant validation rules, example

diff --git a/api/configuration/v1alpha1/kong_custom_entity_types.go b/api/configuration/v1alpha1/kong_custom_entity_types.go
index 87e6c99..7176abe 100644
--- a/api/configuration/v1alpha1/kong_custom_entity_types.go
+++ b/api/configuration/v1alpha1/kong_custom_entity_types.go
@@ -23,7 +23,7 @@ type KongEntityScope string
 // +kubebuilder:printcolumn:name="Entity Type",type=string,JSONPath=`.spec.type`,description="type of the Kong entity"
 // +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`,description="Age"
 // +kubebuilder:printcolumn:name="Programmed",type=string,JSONPath=`.status.conditions[?(@.type=="Programmed")].status`
-// +kubebuilder:validation:XValidation:rule="self.spec.type == oldSelf.spec.type",message="The spec.type field is immutable"
+// +kubebuilder:validation:XValidation:rule="self.spec.type == oldSelf.spec.type",message="The spec.type field is immutable",fieldPath=".spec.type"
 // +apireference:kic:include
 // +kong:channels=ingress-controller
 type KongCustomEntity struct {

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions