|
| 1 | +package v1alpha1 |
| 2 | + |
| 3 | +import ( |
| 4 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 5 | + gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2" |
| 6 | +) |
| 7 | + |
| 8 | +// +kubebuilder:object:root=true |
| 9 | +// +kubebuilder:storageversion |
| 10 | +// +kubebuilder:subresource:status |
| 11 | +// +kubebuilder:resource:categories=nginx-gateway-fabric,shortName=cspolicy |
| 12 | +// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp` |
| 13 | +// +kubebuilder:metadata:labels="gateway.networking.k8s.io/policy=inherited" |
| 14 | + |
| 15 | +// ClientSettingsPolicy is an Inherited Attached Policy. It provides a way to configure the behavior of the connection |
| 16 | +// between the client and NGINX Gateway Fabric. |
| 17 | +type ClientSettingsPolicy struct { |
| 18 | + metav1.TypeMeta `json:",inline"` |
| 19 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 20 | + |
| 21 | + // Spec defines the desired state of the ClientSettingsPolicy. |
| 22 | + Spec ClientSettingsPolicySpec `json:"spec"` |
| 23 | + |
| 24 | + // Status defines the state of the ClientSettingsPolicy. |
| 25 | + Status ClientSettingsPolicyStatus `json:"status,omitempty"` |
| 26 | +} |
| 27 | + |
| 28 | +// +kubebuilder:object:root=true |
| 29 | + |
| 30 | +// ClientSettingsPolicyList contains a list of ClientSettingsPolicies. |
| 31 | +type ClientSettingsPolicyList struct { |
| 32 | + metav1.TypeMeta `json:",inline"` |
| 33 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 34 | + Items []ClientSettingsPolicy `json:"items"` |
| 35 | +} |
| 36 | + |
| 37 | +// ClientSettingsPolicySpec defines the desired state of ClientSettingsPolicy. |
| 38 | +type ClientSettingsPolicySpec struct { |
| 39 | + // TargetRef identifies an API object to apply the policy to. |
| 40 | + // Object must be in the same namespace as the policy. |
| 41 | + // |
| 42 | + // Support: Gateway |
| 43 | + TargetRef gatewayv1alpha2.PolicyTargetReference `json:"targetRef"` |
| 44 | + |
| 45 | + // Default defines default policy configuration for the targeted resource. |
| 46 | + // |
| 47 | + // +optional |
| 48 | + Default *ClientSettingsPolicyConfig `json:"default,omitempty"` |
| 49 | +} |
| 50 | + |
| 51 | +// ClientSettingsPolicyStatus defines the current state of ClientSettingsPolicy. |
| 52 | +type ClientSettingsPolicyStatus struct { |
| 53 | + // Conditions describe the current conditions of the ClientSettingsPolicy. |
| 54 | + // |
| 55 | + // +listType=map |
| 56 | + // +listMapKey=type |
| 57 | + // +kubebuilder:validation:MinItems=1 |
| 58 | + // +kubebuilder:validation:MaxItems=8 |
| 59 | + Conditions []metav1.Condition `json:"conditions,omitempty"` |
| 60 | +} |
| 61 | + |
| 62 | +// ClientSettingsPolicyConfig contains client settings policy configuration. |
| 63 | +type ClientSettingsPolicyConfig struct { |
| 64 | + // Body defines the client request body settings. |
| 65 | + // |
| 66 | + // +optional |
| 67 | + Body *ClientBody `json:"body,omitempty"` |
| 68 | + |
| 69 | + // KeepAlive defines the keep-alive settings. |
| 70 | + // |
| 71 | + // +optional |
| 72 | + KeepAlive *ClientKeepAlive `json:"keepAlive,omitempty"` |
| 73 | +} |
| 74 | + |
| 75 | +// ClientBody contains the settings for the client request body. |
| 76 | +type ClientBody struct { |
| 77 | + // MaxSize sets the maximum allowed size of the client request body. |
| 78 | + // If the size in a request exceeds the configured value, |
| 79 | + // the 413 (Request Entity Too Large) error is returned to the client. |
| 80 | + // Setting size to 0 disables checking of client request body size. |
| 81 | + // Default: 1m. |
| 82 | + // |
| 83 | + // +optional |
| 84 | + MaxSize *Size `json:"maxSize,omitempty"` |
| 85 | + |
| 86 | + // Timeout defines a timeout for reading client request body. The timeout is set only for a period between |
| 87 | + // two successive read operations, not for the transmission of the whole request body. |
| 88 | + // If a client does not transmit anything within this time, the request is terminated with the |
| 89 | + // 408 (Request Time-out) error. |
| 90 | + // Default: 60s. |
| 91 | + // |
| 92 | + // +optional |
| 93 | + Timeout *Duration `json:"timeout,omitempty"` |
| 94 | +} |
| 95 | + |
| 96 | +// ClientKeepAlive defines the keep-alive settings for clients. |
| 97 | +type ClientKeepAlive struct { |
| 98 | + // Requests sets the maximum number of requests that can be served through one keep-alive connection. |
| 99 | + // After the maximum number of requests are made, the connection is closed. Closing connections periodically |
| 100 | + // is necessary to free per-connection memory allocations. Therefore, using too high maximum number of requests |
| 101 | + // is not recommended as it can lead to excessive memory usage. |
| 102 | + // Default: 1000. |
| 103 | + // |
| 104 | + // +optional |
| 105 | + // +kubebuilder:validation:Minimum=0 |
| 106 | + Requests *int32 `json:"requests,omitempty"` |
| 107 | + |
| 108 | + // Time defines the maximum time during which requests can be processed through one keep-alive connection. |
| 109 | + // After this time is reached, the connection is closed following the subsequent request processing. |
| 110 | + // Default: 1h. |
| 111 | + // |
| 112 | + // +optional |
| 113 | + Time *Duration `json:"time,omitempty"` |
| 114 | + |
| 115 | + // Timeout defines the keep-alive timeouts for clients. |
| 116 | + // |
| 117 | + // +optional |
| 118 | + Timeout *ClientKeepAliveTimeout `json:"timeout,omitempty"` |
| 119 | +} |
| 120 | + |
| 121 | +// ClientKeepAliveTimeout defines the timeouts related to keep-alive client connections. |
| 122 | +type ClientKeepAliveTimeout struct { |
| 123 | + // Server sets the timeout during which a keep-alive client connection will stay open on the server side. |
| 124 | + // Setting this value to 0 disables keep-alive client connections. |
| 125 | + // Default: 75s. |
| 126 | + // |
| 127 | + // +optional |
| 128 | + Server *Duration `json:"server,omitempty"` |
| 129 | + |
| 130 | + // Header sets the timeout in the "Keep-Alive: timeout=time" response header field. |
| 131 | + // |
| 132 | + // +optional |
| 133 | + Header *Duration `json:"header,omitempty"` |
| 134 | +} |
| 135 | + |
| 136 | +// Duration is a string value representing a duration in time. |
| 137 | +// Duration can be specified in milliseconds (ms), seconds (s), minutes (m), hours (h), |
| 138 | +// or days (d). A value without a suffix is seconds. |
| 139 | +// Examples: 300d, 20h, 12m, 45s, 150ms. |
| 140 | +// |
| 141 | +// +kubebuilder:validation:Pattern=`^\d+(ms|s|m|h|d)?$` |
| 142 | +type Duration string |
| 143 | + |
| 144 | +// Size is a string value representing a size. Size can be specified in bytes, kilobytes (k), megabytes (m), |
| 145 | +// or gigabytes (g). |
| 146 | +// Examples: 1024, 8k, 1m. |
| 147 | +// |
| 148 | +// +kubebuilder:validation:Pattern=`^\d+(k|m|g)?$` |
| 149 | +type Size string |
0 commit comments