Skip to content

Commit 7d4764b

Browse files
theRealWardodilyevsky
authored andcommitted
feat(api/gateway): add DirectResponse CRD for static HTTP responses
Add a new Gateway API extension CRD called DirectResponse that allows HTTPRoute rules to return static HTTP responses without a backend service. This supports the HTTP-01 ACME challenge workflow for serving challenge tokens directly from Envoy. Changes: - Create api/gateway/v1alpha1/ package with DirectResponse type definition - Implement DirectResponseSpec with status code, content-type, headers, and body - Generate deepcopy and register helpers via k8s.io/code-generator - Update codegen/update.sh to include v1alpha1 in code generation pipeline - Generate versioned client code for gateway.apoxy.dev/v1alpha1
1 parent 20a78d2 commit 7d4764b

File tree

11 files changed

+649
-13
lines changed

11 files changed

+649
-13
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package v1alpha2
2+
3+
import (
4+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
5+
)
6+
7+
// BodyType defines how the response body is specified.
8+
// +kubebuilder:validation:Enum=Inline
9+
type BodyType string
10+
11+
const (
12+
// BodyTypeInline indicates the body is specified inline as a string.
13+
BodyTypeInline BodyType = "Inline"
14+
)
15+
16+
// CustomResponseBody defines the body of the direct response.
17+
type CustomResponseBody struct {
18+
// Type specifies how the body is provided.
19+
// Currently only "Inline" is supported.
20+
// +kubebuilder:validation:Required
21+
Type BodyType `json:"type"`
22+
23+
// Inline is the literal body content when Type is "Inline".
24+
// +optional
25+
Inline *string `json:"inline,omitempty"`
26+
}
27+
28+
// Header defines a custom HTTP header to include in the response.
29+
type Header struct {
30+
// Name is the header name.
31+
// +kubebuilder:validation:Required
32+
// +kubebuilder:validation:MinLength=1
33+
Name string `json:"name"`
34+
35+
// Value is the header value.
36+
// +kubebuilder:validation:Required
37+
Value string `json:"value"`
38+
}
39+
40+
// DirectResponseSpec defines the desired state of DirectResponse.
41+
type DirectResponseSpec struct {
42+
// StatusCode is the HTTP status code to return.
43+
// Defaults to 200 if not specified.
44+
// +kubebuilder:validation:Minimum=100
45+
// +kubebuilder:validation:Maximum=599
46+
// +kubebuilder:default=200
47+
// +optional
48+
StatusCode *int32 `json:"statusCode,omitempty"`
49+
50+
// ContentType is the Content-Type header value.
51+
// Defaults to "text/plain" if not specified.
52+
// +kubebuilder:default="text/plain"
53+
// +optional
54+
ContentType *string `json:"contentType,omitempty"`
55+
56+
// Headers are additional HTTP headers to include in the response.
57+
// +optional
58+
Headers []Header `json:"headers,omitempty"`
59+
60+
// Body is the response body configuration.
61+
// +optional
62+
Body *CustomResponseBody `json:"body,omitempty"`
63+
}
64+
65+
// DirectResponseStatus defines the observed state of DirectResponse.
66+
type DirectResponseStatus struct {
67+
// Conditions describe the current conditions of the DirectResponse.
68+
// +optional
69+
Conditions []metav1.Condition `json:"conditions,omitempty"`
70+
}
71+
72+
// +kubebuilder:object:root=true
73+
// +kubebuilder:subresource:status
74+
// +kubebuilder:resource:categories=gateway-api
75+
// +kubebuilder:printcolumn:name="Status Code",type=integer,JSONPath=`.spec.statusCode`
76+
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`
77+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
78+
79+
// DirectResponse is the Schema for the directresponses API.
80+
// It defines a static response that can be returned by an HTTPRoute
81+
// instead of forwarding to a backend.
82+
type DirectResponse struct {
83+
metav1.TypeMeta `json:",inline"`
84+
metav1.ObjectMeta `json:"metadata,omitempty"`
85+
86+
Spec DirectResponseSpec `json:"spec,omitempty"`
87+
Status DirectResponseStatus `json:"status,omitempty"`
88+
}
89+
90+
// +kubebuilder:object:root=true
91+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
92+
93+
// DirectResponseList contains a list of DirectResponse.
94+
type DirectResponseList struct {
95+
metav1.TypeMeta `json:",inline"`
96+
metav1.ListMeta `json:"metadata,omitempty"`
97+
Items []DirectResponse `json:"items"`
98+
}

api/extensions/v1alpha2/zz_generated.deepcopy.go

Lines changed: 157 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/extensions/v1alpha2/zz_generated.register.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)