|
| 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 | +) |
0 commit comments