|
| 1 | +package v1alpha1 |
| 2 | + |
| 3 | +import ( |
| 4 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 5 | + v1 "sigs.k8s.io/gateway-api/apis/v1" |
| 6 | +) |
| 7 | + |
| 8 | +// +genclient |
| 9 | +// +kubebuilder:object:root=true |
| 10 | +// +kubebuilder:storageversion |
| 11 | +// +kubebuilder:subresource:status |
| 12 | +// +kubebuilder:resource:categories=nginx-gateway-fabric,shortName=snippetsfilter |
| 13 | +// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp` |
| 14 | + |
| 15 | +// SnippetsFilter is a filter that allows inserting NGINX configuration into the |
| 16 | +// generated NGINX config for HTTPRoute and GRPCRoute resources. |
| 17 | +type SnippetsFilter struct { |
| 18 | + metav1.TypeMeta `json:",inline"` |
| 19 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 20 | + |
| 21 | + // Spec defines the desired state of the SnippetsFilter. |
| 22 | + Spec SnippetsFilterSpec `json:"spec"` |
| 23 | + |
| 24 | + // Status defines the state of the SnippetsFilter. |
| 25 | + Status SnippetsFilterStatus `json:"status,omitempty"` |
| 26 | +} |
| 27 | + |
| 28 | +// +kubebuilder:object:root=true |
| 29 | + |
| 30 | +// SnippetsFilterList contains a list of SnippetFilters. |
| 31 | +type SnippetsFilterList struct { |
| 32 | + metav1.TypeMeta `json:",inline"` |
| 33 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 34 | + Items []SnippetsFilter `json:"items"` |
| 35 | +} |
| 36 | + |
| 37 | +// SnippetsFilterSpec defines the desired state of the SnippetsFilter. |
| 38 | +type SnippetsFilterSpec struct { |
| 39 | + // Snippets is a list of NGINX configuration snippets. |
| 40 | + // There can only be one snippet per context. |
| 41 | + // Allowed contexts: main, http, http.server, http.server.location. |
| 42 | + // +kubebuilder:validation:MinItems=1 |
| 43 | + // +kubebuilder:validation:MaxItems=4 |
| 44 | + // +kubebuilder:validation:XValidation:message="Only one snippet allowed per context",rule="self.all(s1, self.exists_one(s2, s1.context == s2.context))" |
| 45 | + //nolint:lll |
| 46 | + Snippets []Snippet `json:"snippets"` |
| 47 | +} |
| 48 | + |
| 49 | +// Snippet represents an NGINX configuration snippet. |
| 50 | +type Snippet struct { |
| 51 | + // Context is the NGINX context to insert the snippet into. |
| 52 | + Context NginxContext `json:"context"` |
| 53 | + |
| 54 | + // Value is the NGINX configuration snippet. |
| 55 | + // +kubebuilder:validation:MinLength=1 |
| 56 | + Value string `json:"value"` |
| 57 | +} |
| 58 | + |
| 59 | +// NginxContext represents the NGINX configuration context. |
| 60 | +// |
| 61 | +// +kubebuilder:validation:Enum=main;http;http.server;http.server.location |
| 62 | +type NginxContext string |
| 63 | + |
| 64 | +const ( |
| 65 | + // NginxContextMain is the main context of the NGINX configuration. |
| 66 | + NginxContextMain NginxContext = "main" |
| 67 | + |
| 68 | + // NginxContextHTTP is the http context of the NGINX configuration. |
| 69 | + // https://nginx.org/en/docs/http/ngx_http_core_module.html#http |
| 70 | + NginxContextHTTP NginxContext = "http" |
| 71 | + |
| 72 | + // NginxContextHTTPServer is the server context of the NGINX configuration. |
| 73 | + // https://nginx.org/en/docs/http/ngx_http_core_module.html#server |
| 74 | + NginxContextHTTPServer NginxContext = "http.server" |
| 75 | + |
| 76 | + // NginxContextHTTPServerLocation is the location context of the NGINX configuration. |
| 77 | + // https://nginx.org/en/docs/http/ngx_http_core_module.html#location |
| 78 | + NginxContextHTTPServerLocation NginxContext = "http.server.location" |
| 79 | +) |
| 80 | + |
| 81 | +// SnippetsFilterStatus defines the state of SnippetsFilter. |
| 82 | +type SnippetsFilterStatus struct { |
| 83 | + // Controllers is a list of Gateway API controllers that processed the SnippetsFilter |
| 84 | + // and the status of the SnippetsFilter with respect to each controller. |
| 85 | + // |
| 86 | + // +kubebuilder:validation:MaxItems=16 |
| 87 | + Controllers []ControllerStatus `json:"controllers,omitempty"` |
| 88 | +} |
| 89 | + |
| 90 | +type ControllerStatus struct { |
| 91 | + // ControllerName is a domain/path string that indicates the name of the |
| 92 | + // controller that wrote this status. This corresponds with the |
| 93 | + // controllerName field on GatewayClass. |
| 94 | + // |
| 95 | + // Example: "example.net/gateway-controller". |
| 96 | + // |
| 97 | + // The format of this field is DOMAIN "/" PATH, where DOMAIN and PATH are |
| 98 | + // valid Kubernetes names |
| 99 | + // (https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names). |
| 100 | + // |
| 101 | + // Controllers MUST populate this field when writing status. Controllers should ensure that |
| 102 | + // entries to status populated with their ControllerName are cleaned up when they are no |
| 103 | + // longer necessary. |
| 104 | + ControllerName v1.GatewayController `json:"controllerName"` |
| 105 | + |
| 106 | + // Conditions describe the status of the SnippetsFilter. |
| 107 | + // |
| 108 | + // +optional |
| 109 | + // +listType=map |
| 110 | + // +listMapKey=type |
| 111 | + // +kubebuilder:validation:MinItems=1 |
| 112 | + // +kubebuilder:validation:MaxItems=8 |
| 113 | + Conditions []metav1.Condition `json:"conditions,omitempty"` |
| 114 | +} |
| 115 | + |
| 116 | +// SnippetsFilterConditionType is a type of condition associated with SnippetsFilter. |
| 117 | +type SnippetsFilterConditionType string |
| 118 | + |
| 119 | +// SnippetsFilterConditionReason is a reason for a SnippetsFilter condition type. |
| 120 | +type SnippetsFilterConditionReason string |
| 121 | + |
| 122 | +const ( |
| 123 | + // SnippetsFilterConditionTypeAccepted indicates that the SnippetsFilter is accepted. |
| 124 | + // |
| 125 | + // Possible reasons for this condition to be True: |
| 126 | + // |
| 127 | + // * Accepted |
| 128 | + // |
| 129 | + // Possible reasons for this condition to be False: |
| 130 | + // |
| 131 | + // * Invalid. |
| 132 | + SnippetsFilterConditionTypeAccepted SnippetsFilterConditionType = "Accepted" |
| 133 | + |
| 134 | + // SnippetsFilterConditionReasonAccepted is used with the Accepted condition type when |
| 135 | + // the condition is true. |
| 136 | + SnippetsFilterConditionReasonAccepted SnippetsFilterConditionReason = "Accepted" |
| 137 | + |
| 138 | + // SnippetsFilterConditionReasonInvalid is used with the Accepted condition type when |
| 139 | + // SnippetsFilter is invalid. |
| 140 | + SnippetsFilterConditionReasonInvalid SnippetsFilterConditionReason = "Invalid" |
| 141 | +) |
0 commit comments