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

api: Introduce a v1alpha1 DirectResponseRoute CRD #9951

Conversation

timflannagan
Copy link
Contributor

Description

This commit introduces a new v1alpha1 CRD that allows users to configure direct response functionality within the K8S Gateway API integration.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works

This commit introduces a new v1alpha1 CRD that allows users
to configure direct response functionality within the K8S
Gateway API integration.

Signed-off-by: timflannagan <timflannagan@gmail.com>
@solo-changelog-bot
Copy link

Issues linked to changelog:
#9774

@@ -0,0 +1,8 @@
changelog:
- type: NON_USER_FACING
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NON_USER_FACING since I was planning on implementing this functionality in a separate PR. I can implement this in the same PR if folks have a strong opinion.

//
// +kubebuilder:validation:Optional
//
// TODO(tim): Make required? Add validation on length of body?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still an open question I'd like to get consensus on. I thought it was reasonable to make it optional via cel expressions when status code is a 403/404/etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also tested this locally:

$ kubectl apply -f - <<EOF
apiVersion: gateway.gloo.solo.io/v1alpha1
kind: DirectResponseRoute
metadata:
  name: test
  namespace: gloo-system
spec:
  code: 200
EOF

The DirectResponseRoute "test" is invalid: spec: Invalid value: "object": The 'body' field is required when 'code' is a 2xx status code

$ kubectl apply -f - <<EOF
apiVersion: gateway.gloo.solo.io/v1alpha1
kind: DirectResponseRoute
metadata:
  name: test
  namespace: gloo-system
spec:
  code: 403
EOF

directresponseroute.gateway.gloo.solo.io/test configured

Comment on lines +51 to +53
// TODO(tim): Do we need to add any status fields? If so, investigate how
// other APIs define status fields with the same pattern.
LastUpdated *metav1.Time `json:"lastUpdated,omitempty"`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: still relevant that I wanted to crowd source on whether folks with more historical context can answer.

// DirectResponseRouteSpec describes the desired state of a DirectResponseRoute.
//
// +kubebuilder:validation:XValidation:message="The 'body' field is required when 'code' is a 2xx status code",rule="self.code < 200 || self.code >= 300 || has(self.body)"
type DirectResponseRouteSpec struct {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm looking at the implementation and I'm wondering whether we should have an HTTPRoute targetRef field to make lookup easier? I was initially looking at implementing this as a route plugin.

@timflannagan
Copy link
Contributor Author

Closing - I'll open a full feature PR since the implementation doesn't look too rough.

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

Successfully merging this pull request may close these issues.

1 participant