Skip to content

Commit 54acfb4

Browse files
authored
Support NginxProxy at the Gateway level (#3058)
Problem: When the control plane and data planes are split, the user will need the ability to specify data plane settings on a per-Gateway basis. To allow this, we need to support NginxProxy at the Gateway level in addition the the GatewayClass level. In practice, this means a user can reference an NginxProxy resource via the spec.infrastructure.parametersRef field on the Gateway resource. We still want to support referencing an NginxProxy at the GatewayClass level. If a Gateway and its GatewayClass reference distinct NginxProxy resources, the settings must be merged. Settings specified on a Gateway NginxProxy must override those set on the GatewayClass NginxProxy. Solution: To support NginxProxy at the Gateway level several changes were made to the API. As a result, the API is now at version v1alpha2. Breaking Changes: * Change the scope of the CRD to Namespaced. The parametersRef.namespace field on the GatewayClass is now required. * Make DisableHTTP2 and Telemetry.Exporter.Endpoint optional. New fields: * Telemetry.DisabledFeatures: allows users to explicitly disable telemetry features. It is a list with one supported entry: DisableTracing. More features may be added in future releases. Other changes: * Remove the listType=Map kubebuilder annotation from the RewriteClientIP.TrustedAddresses field. This listType is incorrect since TrustedAddresses can have duplicate keys. The graph now stores NginxProxies that are referenced by the winning GatewayClass and Gateway. This will need to be updated once we support multiple Gateways. The graph is also responsible for merging the NginxProxies when necessary. The result of this is stored on the graph's Gateway object in the field EffectiveNginxProxy. The EffectiveNginxProxy on the Gateway is used to build the NGINX configuration.
1 parent f8bbcbe commit 54acfb4

40 files changed

+3592
-1980
lines changed

apis/v1alpha1/register.go

-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ func addKnownTypes(scheme *runtime.Scheme) error {
3434
scheme.AddKnownTypes(SchemeGroupVersion,
3535
&NginxGateway{},
3636
&NginxGatewayList{},
37-
&NginxProxy{},
38-
&NginxProxyList{},
3937
&ObservabilityPolicy{},
4038
&ObservabilityPolicyList{},
4139
&ClientSettingsPolicy{},

apis/v1alpha1/zz_generated.deepcopy.go

-218
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/v1alpha2/doc.go

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Package v1alpha2 contains API Schema definitions for the
2+
// gateway.nginx.org API group.
3+
//
4+
// +kubebuilder:object:generate=true
5+
// +groupName=gateway.nginx.org
6+
package v1alpha2

apis/v1alpha1/nginxproxy_types.go renamed to apis/v1alpha2/nginxproxy_types.go

+33-13
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
1-
package v1alpha1
1+
package v1alpha2
22

3-
import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3+
import (
4+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
5+
6+
"github.com/nginxinc/nginx-gateway-fabric/apis/v1alpha1"
7+
)
48

59
// +genclient
610
// +kubebuilder:object:root=true
711
// +kubebuilder:storageversion
8-
// +kubebuilder:resource:categories=nginx-gateway-fabric,scope=Cluster
12+
// +kubebuilder:resource:categories=nginx-gateway-fabric,scope=Namespaced
913
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`
1014

11-
// NginxProxy is a configuration object that is attached to a GatewayClass parametersRef. It provides a way
12-
// to configure global settings for all Gateways defined from the GatewayClass.
15+
// NginxProxy is a configuration object that can be referenced from a GatewayClass parametersRef
16+
// or a Gateway infrastructure.parametersRef. It provides a way to configure data plane settings.
17+
// If referenced from a GatewayClass, the settings apply to all Gateways attached to the GatewayClass.
18+
// If referenced from a Gateway, the settings apply to that Gateway alone. If both a Gateway and its GatewayClass
19+
// reference an NginxProxy, the settings are merged. Settings specified on the Gateway NginxProxy override those
20+
// set on the GatewayClass NginxProxy.
1321
type NginxProxy struct { //nolint:govet // standard field alignment, don't change it
1422
metav1.TypeMeta `json:",inline"`
1523
metav1.ObjectMeta `json:"metadata,omitempty"`
@@ -50,14 +58,18 @@ type NginxProxySpec struct {
5058
// +optional
5159
Logging *NginxLogging `json:"logging,omitempty"`
5260
// DisableHTTP2 defines if http2 should be disabled for all servers.
53-
// Default is false, meaning http2 will be enabled for all servers.
61+
// If not specified, or set to false, http2 will be enabled for all servers.
5462
//
5563
// +optional
56-
DisableHTTP2 bool `json:"disableHTTP2,omitempty"`
64+
DisableHTTP2 *bool `json:"disableHTTP2,omitempty"`
5765
}
5866

5967
// Telemetry specifies the OpenTelemetry configuration.
6068
type Telemetry struct {
69+
// DisabledFeatures specifies OpenTelemetry features to be disabled.
70+
//
71+
// +optional
72+
DisabledFeatures []DisableTelemetryFeature `json:"disabledFeatures,omitempty"`
6173
// Exporter specifies OpenTelemetry export parameters.
6274
//
6375
// +optional
@@ -78,7 +90,7 @@ type Telemetry struct {
7890
// +listType=map
7991
// +listMapKey=key
8092
// +kubebuilder:validation:MaxItems=64
81-
SpanAttributes []SpanAttribute `json:"spanAttributes,omitempty"`
93+
SpanAttributes []v1alpha1.SpanAttribute `json:"spanAttributes,omitempty"`
8294
}
8395

8496
// TelemetryExporter specifies OpenTelemetry export parameters.
@@ -87,7 +99,7 @@ type TelemetryExporter struct {
8799
// Default: https://nginx.org/en/docs/ngx_otel_module.html#otel_exporter
88100
//
89101
// +optional
90-
Interval *Duration `json:"interval,omitempty"`
102+
Interval *v1alpha1.Duration `json:"interval,omitempty"`
91103

92104
// BatchSize is the maximum number of spans to be sent in one batch per worker.
93105
// Default: https://nginx.org/en/docs/ngx_otel_module.html#otel_exporter
@@ -107,8 +119,9 @@ type TelemetryExporter struct {
107119
// Format: alphanumeric hostname with optional http scheme and optional port.
108120
//
109121
//nolint:lll
122+
// +optional
110123
// +kubebuilder:validation:Pattern=`^(?:http?:\/\/)?[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)*(?::\d{1,5})?$`
111-
Endpoint string `json:"endpoint"`
124+
Endpoint *string `json:"endpoint,omitempty"`
112125
}
113126

114127
// RewriteClientIP specifies the configuration for rewriting the client's IP address.
@@ -139,15 +152,12 @@ type RewriteClientIP struct {
139152
// If a request comes from a trusted address, NGINX will rewrite the client IP information,
140153
// and forward it to the backend in the X-Forwarded-For* and X-Real-IP headers.
141154
// If the request does not come from a trusted address, NGINX will not rewrite the client IP information.
142-
// TrustedAddresses only supports CIDR blocks: 192.33.21.1/24, fe80::1/64.
143155
// To trust all addresses (not recommended for production), set to 0.0.0.0/0.
144156
// If no addresses are provided, NGINX will not rewrite the client IP information.
145157
// Sets NGINX directive set_real_ip_from: https://nginx.org/en/docs/http/ngx_http_realip_module.html#set_real_ip_from
146158
// This field is required if mode is set.
147159
//
148160
// +optional
149-
// +listType=map
150-
// +listMapKey=type
151161
// +kubebuilder:validation:MaxItems=16
152162
TrustedAddresses []Address `json:"trustedAddresses,omitempty"`
153163
}
@@ -249,3 +259,13 @@ const (
249259
// NginxLogLevelEmerg is the emerg level for NGINX error logs.
250260
NginxLogLevelEmerg NginxErrorLogLevel = "emerg"
251261
)
262+
263+
// DisableTelemetryFeature is a telemetry feature that can be disabled.
264+
//
265+
// +kubebuilder:validation:Enum=DisableTracing
266+
type DisableTelemetryFeature string
267+
268+
const (
269+
// DisableTracing disables the OpenTelemetry tracing feature.
270+
DisableTracing DisableTelemetryFeature = "DisableTracing"
271+
)

0 commit comments

Comments
 (0)