Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce usage of fieldPath for more readable failure responses #183

Open
pmalek opened this issue Dec 6, 2024 · 0 comments
Open

Introduce usage of fieldPath for more readable failure responses #183

pmalek opened this issue Dec 6, 2024 · 0 comments

Comments

@pmalek
Copy link
Member

pmalek commented Dec 6, 2024

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 {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant