|
| 1 | +/* |
| 2 | +Copyright 2025 The NGINX Gateway Fabric Authors. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package v1alpha1 |
| 18 | + |
| 19 | +import ( |
| 20 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 21 | + gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" |
| 22 | +) |
| 23 | + |
| 24 | +// +genclient |
| 25 | +// +kubebuilder:object:root=true |
| 26 | +// +kubebuilder:storageversion |
| 27 | +// +kubebuilder:subresource:status |
| 28 | +// +kubebuilder:resource:shortName=snipol |
| 29 | +// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp` |
| 30 | +// +kubebuilder:printcolumn:name="Accepted",type=string,JSONPath=`.status.conditions[?(@.type=="Accepted")].status` |
| 31 | +// +kubebuilder:printcolumn:name="Reason",type=string,JSONPath=`.status.conditions[?(@.type=="Accepted")].reason` |
| 32 | + |
| 33 | +// SnippetsPolicy provides a way to inject NGINX snippets into the configuration. |
| 34 | +type SnippetsPolicy struct { |
| 35 | + metav1.TypeMeta `json:",inline"` |
| 36 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 37 | + |
| 38 | + // Spec defines the desired state of the SnippetsPolicy. |
| 39 | + Spec SnippetsPolicySpec `json:"spec"` |
| 40 | + |
| 41 | + // Status defines the current state of the SnippetsPolicy. |
| 42 | + // +optional |
| 43 | + Status gatewayv1.PolicyStatus `json:"status,omitempty"` |
| 44 | +} |
| 45 | + |
| 46 | +// SnippetsPolicySpec defines the desired state of the SnippetsPolicy. |
| 47 | +type SnippetsPolicySpec struct { |
| 48 | + // TargetRef is the reference to the Gateway that this policy should be applied to. |
| 49 | + TargetRef SnippetsPolicyTargetRef `json:"targetRef"` |
| 50 | + |
| 51 | + // Snippets is a list of snippets to be injected into the NGINX configuration. |
| 52 | + // +kubebuilder:validation:MaxItems=3 |
| 53 | + // +kubebuilder:validation:XValidation:message="Only one snippet allowed per context",rule="self.all(s1, self.exists_one(s2, s1.context == s2.context))" |
| 54 | + // +kubebuilder:validation:XValidation:message="http.server.location context is not supported in SnippetsPolicy",rule="!self.exists(s, s.context == 'http.server.location')" |
| 55 | + Snippets []Snippet `json:"snippets"` |
| 56 | +} |
| 57 | + |
| 58 | +// SnippetsPolicyTargetRef identifies an API object to apply the policy to. |
| 59 | +type SnippetsPolicyTargetRef struct { |
| 60 | + gatewayv1.LocalPolicyTargetReference `json:",inline"` |
| 61 | +} |
| 62 | + |
| 63 | +// +kubebuilder:object:root=true |
| 64 | + |
| 65 | +// SnippetsPolicyList contains a list of SnippetsPolicies. |
| 66 | +type SnippetsPolicyList struct { |
| 67 | + metav1.TypeMeta `json:",inline"` |
| 68 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 69 | + Items []SnippetsPolicy `json:"items"` |
| 70 | +} |
0 commit comments