Skip to content

Commit 381e44e

Browse files
salonichf5sjberman
authored andcommitted
Add SnippetFilter CRD (#2472)
Problem: User wants to define a CRD for snippetsFilter to apply custom nginx configurations Solution: Defined a CRD for snippetsFilter
1 parent 31e7e66 commit 381e44e

File tree

5 files changed

+670
-0
lines changed

5 files changed

+670
-0
lines changed

apis/v1alpha1/register.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ func addKnownTypes(scheme *runtime.Scheme) error {
4040
&ObservabilityPolicyList{},
4141
&ClientSettingsPolicy{},
4242
&ClientSettingsPolicyList{},
43+
&SnippetsFilter{},
44+
&SnippetsFilterList{},
4345
)
4446
// AddToGroupVersion allows the serialization of client types like ListOptions.
4547
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)

apis/v1alpha1/snippetsfilter_types.go

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
package v1alpha1
2+
3+
import (
4+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
5+
)
6+
7+
// +genclient
8+
// +kubebuilder:object:root=true
9+
// +kubebuilder:storageversion
10+
// +kubebuilder:subresource:status
11+
// +kubebuilder:resource:categories=nginx-gateway-fabric,shortName=snippetsfilter
12+
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`
13+
14+
// SnippetsFilter is a filter that allows inserting NGINX configuration into the
15+
// generated NGINX config for HTTPRoute and GRPCRoute resources.
16+
type SnippetsFilter struct {
17+
metav1.TypeMeta `json:",inline"`
18+
metav1.ObjectMeta `json:"metadata,omitempty"`
19+
20+
// Spec defines the desired state of the SnippetsFilter.
21+
Spec SnippetsFilterSpec `json:"spec"`
22+
23+
// Status defines the state of the SnippetsFilter.
24+
Status SnippetsFilterStatus `json:"status,omitempty"`
25+
}
26+
27+
// +kubebuilder:object:root=true
28+
29+
// SnippetsFilterList contains a list of SnippetFilters.
30+
type SnippetsFilterList struct {
31+
metav1.TypeMeta `json:",inline"`
32+
metav1.ListMeta `json:"metadata,omitempty"`
33+
Items []SnippetsFilter `json:"items"`
34+
}
35+
36+
// SnippetsFilterSpec defines the desired state of the SnippetsFilter.
37+
type SnippetsFilterSpec struct {
38+
// Snippets is a list of NGINX configuration snippets.
39+
// There can only be one snippet per context.
40+
// Allowed contexts: main, http, http.server, http.server.location.
41+
Snippets []Snippet `json:"snippets"`
42+
}
43+
44+
// Snippet represents an NGINX configuration snippet.
45+
type Snippet struct {
46+
// Context is the NGINX context to insert the snippet into.
47+
Context NginxContext `json:"context"`
48+
49+
// Value is the NGINX configuration snippet.
50+
Value string `json:"value"`
51+
}
52+
53+
// NginxContext represents the NGINX configuration context.
54+
//
55+
// +kubebuilder:validation:Enum=main;http;http.server;http.server.location
56+
type NginxContext string
57+
58+
const (
59+
// NginxContextMain is the main context of the NGINX configuration.
60+
NginxContextMain NginxContext = "main"
61+
62+
// NginxContextHTTP is the http context of the NGINX configuration.
63+
// https://nginx.org/en/docs/http/ngx_http_core_module.html#http
64+
NginxContextHTTP NginxContext = "http"
65+
66+
// NginxContextHTTPServer is the server context of the NGINX configuration.
67+
// https://nginx.org/en/docs/http/ngx_http_core_module.html#server
68+
NginxContextHTTPServer NginxContext = "http.server"
69+
70+
// NginxContextHTTPServerLocation is the location context of the NGINX configuration.
71+
// https://nginx.org/en/docs/http/ngx_http_core_module.html#location
72+
NginxContextHTTPServerLocation NginxContext = "http.server.location"
73+
)
74+
75+
// SnippetsFilterStatus defines the state of SnippetsFilter.
76+
type SnippetsFilterStatus struct {
77+
// Conditions describes the state of the SnippetsFilter.
78+
// +optional
79+
// +listType=map
80+
// +listMapKey=type
81+
// +kubebuilder:validation:MaxItems=8
82+
Conditions []metav1.Condition `json:"conditions,omitempty"`
83+
}
84+
85+
// SnippetsFilterConditionType is a type of condition associated with SnippetsFilter.
86+
type SnippetsFilterConditionType string
87+
88+
// SnippetsFilterConditionReason is a reason for a SnippetsFilter condition type.
89+
type SnippetsFilterConditionReason string
90+
91+
const (
92+
// SnippetsFilterConditionTypeAccepted indicates that the SnippetsFilter is accepted.
93+
//
94+
// Possible reasons for this condition to be True:
95+
//
96+
// * Accepted
97+
//
98+
// Possible reasons for this condition to be False:
99+
//
100+
// * Invalid.
101+
SnippetsFilterConditionTypeAccepted SnippetsFilterConditionType = "Accepted"
102+
103+
// SnippetsFilterConditionReasonAccepted is used with the Accepted condition type when
104+
// the condition is true.
105+
SnippetsFilterConditionReasonAccepted SnippetsFilterConditionReason = "Accepted"
106+
107+
// SnippetsFilterConditionTypeInvalid is used with the Accepted condition type when
108+
// SnippetsFilter is invalid.
109+
SnippetsFilterConditionTypeInvalid SnippetsFilterConditionType = "Invalid"
110+
)

apis/v1alpha1/zz_generated.deepcopy.go

Lines changed: 116 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
---
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
annotations:
6+
controller-gen.kubebuilder.io/version: v0.16.3
7+
name: snippetsfilters.gateway.nginx.org
8+
spec:
9+
group: gateway.nginx.org
10+
names:
11+
categories:
12+
- nginx-gateway-fabric
13+
kind: SnippetsFilter
14+
listKind: SnippetsFilterList
15+
plural: snippetsfilters
16+
shortNames:
17+
- snippetsfilter
18+
singular: snippetsfilter
19+
scope: Namespaced
20+
versions:
21+
- additionalPrinterColumns:
22+
- jsonPath: .metadata.creationTimestamp
23+
name: Age
24+
type: date
25+
name: v1alpha1
26+
schema:
27+
openAPIV3Schema:
28+
description: |-
29+
SnippetsFilter is a filter that allows inserting NGINX configuration into the
30+
generated NGINX config for HTTPRoute and GRPCRoute resources.
31+
properties:
32+
apiVersion:
33+
description: |-
34+
APIVersion defines the versioned schema of this representation of an object.
35+
Servers should convert recognized schemas to the latest internal value, and
36+
may reject unrecognized values.
37+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
38+
type: string
39+
kind:
40+
description: |-
41+
Kind is a string value representing the REST resource this object represents.
42+
Servers may infer this from the endpoint the client submits requests to.
43+
Cannot be updated.
44+
In CamelCase.
45+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
46+
type: string
47+
metadata:
48+
type: object
49+
spec:
50+
description: Spec defines the desired state of the SnippetsFilter.
51+
properties:
52+
snippets:
53+
description: |-
54+
Snippets is a list of NGINX configuration snippets.
55+
There can only be one snippet per context.
56+
Allowed contexts: main, http, http.server, http.server.location.
57+
items:
58+
description: Snippet represents an NGINX configuration snippet.
59+
properties:
60+
context:
61+
description: Context is the NGINX context to insert the snippet
62+
into.
63+
enum:
64+
- main
65+
- http
66+
- http.server
67+
- http.server.location
68+
type: string
69+
value:
70+
description: Value is the NGINX configuration snippet.
71+
type: string
72+
required:
73+
- context
74+
- value
75+
type: object
76+
type: array
77+
required:
78+
- snippets
79+
type: object
80+
status:
81+
description: Status defines the state of the SnippetsFilter.
82+
properties:
83+
conditions:
84+
description: Conditions describes the state of the SnippetsFilter.
85+
items:
86+
description: Condition contains details for one aspect of the current
87+
state of this API Resource.
88+
properties:
89+
lastTransitionTime:
90+
description: |-
91+
lastTransitionTime is the last time the condition transitioned from one status to another.
92+
This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable.
93+
format: date-time
94+
type: string
95+
message:
96+
description: |-
97+
message is a human readable message indicating details about the transition.
98+
This may be an empty string.
99+
maxLength: 32768
100+
type: string
101+
observedGeneration:
102+
description: |-
103+
observedGeneration represents the .metadata.generation that the condition was set based upon.
104+
For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date
105+
with respect to the current state of the instance.
106+
format: int64
107+
minimum: 0
108+
type: integer
109+
reason:
110+
description: |-
111+
reason contains a programmatic identifier indicating the reason for the condition's last transition.
112+
Producers of specific condition types may define expected values and meanings for this field,
113+
and whether the values are considered a guaranteed API.
114+
The value should be a CamelCase string.
115+
This field may not be empty.
116+
maxLength: 1024
117+
minLength: 1
118+
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
119+
type: string
120+
status:
121+
description: status of the condition, one of True, False, Unknown.
122+
enum:
123+
- "True"
124+
- "False"
125+
- Unknown
126+
type: string
127+
type:
128+
description: type of condition in CamelCase or in foo.example.com/CamelCase.
129+
maxLength: 316
130+
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
131+
type: string
132+
required:
133+
- lastTransitionTime
134+
- message
135+
- reason
136+
- status
137+
- type
138+
type: object
139+
maxItems: 8
140+
type: array
141+
x-kubernetes-list-map-keys:
142+
- type
143+
x-kubernetes-list-type: map
144+
type: object
145+
required:
146+
- spec
147+
type: object
148+
served: true
149+
storage: true
150+
subresources:
151+
status: {}

0 commit comments

Comments
 (0)