Skip to content

Commit b18c496

Browse files
kate-osbornsjberman
authored andcommitted
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 4273ec3 commit b18c496

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+3764
-2237
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

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

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

+35-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/nginx/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"`
@@ -54,8 +62,10 @@ type NginxProxySpec struct {
5462
// +optional
5563
NginxPlus *NginxPlus `json:"nginxPlus,omitempty"`
5664
// DisableHTTP2 defines if http2 should be disabled for all servers.
57-
// Default is false, meaning http2 will be enabled for all servers.
58-
DisableHTTP2 bool `json:"disableHTTP2,omitempty"`
65+
// If not specified, or set to false, http2 will be enabled for all servers.
66+
//
67+
// +optional
68+
DisableHTTP2 *bool `json:"disableHTTP2,omitempty"`
5969
}
6070

6171
// NginxPlus specifies NGINX Plus additional settings. These will only be applied if NGINX Plus is being used.
@@ -68,6 +78,10 @@ type NginxPlus struct {
6878

6979
// Telemetry specifies the OpenTelemetry configuration.
7080
type Telemetry struct {
81+
// DisabledFeatures specifies OpenTelemetry features to be disabled.
82+
//
83+
// +optional
84+
DisabledFeatures []DisableTelemetryFeature `json:"disabledFeatures,omitempty"`
7185
// Exporter specifies OpenTelemetry export parameters.
7286
//
7387
// +optional
@@ -88,7 +102,7 @@ type Telemetry struct {
88102
// +listType=map
89103
// +listMapKey=key
90104
// +kubebuilder:validation:MaxItems=64
91-
SpanAttributes []SpanAttribute `json:"spanAttributes,omitempty"`
105+
SpanAttributes []v1alpha1.SpanAttribute `json:"spanAttributes,omitempty"`
92106
}
93107

94108
// TelemetryExporter specifies OpenTelemetry export parameters.
@@ -97,7 +111,7 @@ type TelemetryExporter struct {
97111
// Default: https://nginx.org/en/docs/ngx_otel_module.html#otel_exporter
98112
//
99113
// +optional
100-
Interval *Duration `json:"interval,omitempty"`
114+
Interval *v1alpha1.Duration `json:"interval,omitempty"`
101115

102116
// BatchSize is the maximum number of spans to be sent in one batch per worker.
103117
// Default: https://nginx.org/en/docs/ngx_otel_module.html#otel_exporter
@@ -117,8 +131,9 @@ type TelemetryExporter struct {
117131
// Format: alphanumeric hostname with optional http scheme and optional port.
118132
//
119133
//nolint:lll
134+
// +optional
120135
// +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})?$`
121-
Endpoint string `json:"endpoint"`
136+
Endpoint *string `json:"endpoint,omitempty"`
122137
}
123138

124139
// RewriteClientIP specifies the configuration for rewriting the client's IP address.
@@ -149,15 +164,12 @@ type RewriteClientIP struct {
149164
// If a request comes from a trusted address, NGINX will rewrite the client IP information,
150165
// and forward it to the backend in the X-Forwarded-For* and X-Real-IP headers.
151166
// If the request does not come from a trusted address, NGINX will not rewrite the client IP information.
152-
// TrustedAddresses only supports CIDR blocks: 192.33.21.1/24, fe80::1/64.
153167
// To trust all addresses (not recommended for production), set to 0.0.0.0/0.
154168
// If no addresses are provided, NGINX will not rewrite the client IP information.
155169
// Sets NGINX directive set_real_ip_from: https://nginx.org/en/docs/http/ngx_http_realip_module.html#set_real_ip_from
156170
// This field is required if mode is set.
157171
//
158172
// +optional
159-
// +listType=map
160-
// +listMapKey=type
161173
// +kubebuilder:validation:MaxItems=16
162174
TrustedAddresses []RewriteClientIPAddress `json:"trustedAddresses,omitempty"`
163175
}
@@ -280,3 +292,13 @@ const (
280292
// NginxLogLevelEmerg is the emerg level for NGINX error logs.
281293
NginxLogLevelEmerg NginxErrorLogLevel = "emerg"
282294
)
295+
296+
// DisableTelemetryFeature is a telemetry feature that can be disabled.
297+
//
298+
// +kubebuilder:validation:Enum=DisableTracing
299+
type DisableTelemetryFeature string
300+
301+
const (
302+
// DisableTracing disables the OpenTelemetry tracing feature.
303+
DisableTracing DisableTelemetryFeature = "DisableTracing"
304+
)

0 commit comments

Comments
 (0)