diff --git a/apis/v1alpha1/clientsettingspolicy_types.go b/apis/v1alpha1/clientsettingspolicy_types.go index b2a783c4ec..370a6e2287 100644 --- a/apis/v1alpha1/clientsettingspolicy_types.go +++ b/apis/v1alpha1/clientsettingspolicy_types.go @@ -114,13 +114,6 @@ type ClientKeepAliveTimeout struct { Header *Duration `json:"header,omitempty"` } -// Duration is a string value representing a duration in time. -// Duration can be specified in milliseconds (ms) or seconds (s) A value without a suffix is seconds. -// Examples: 120s, 50ms. -// -// +kubebuilder:validation:Pattern=`^\d{1,4}(ms|s)?$` -type Duration string - // Size is a string value representing a size. Size can be specified in bytes, kilobytes (k), megabytes (m), // or gigabytes (g). // Examples: 1024, 8k, 1m. diff --git a/apis/v1alpha1/nginxproxy_types.go b/apis/v1alpha1/nginxproxy_types.go new file mode 100644 index 0000000000..20a870b9d8 --- /dev/null +++ b/apis/v1alpha1/nginxproxy_types.go @@ -0,0 +1,107 @@ +package v1alpha1 + +import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + +// +kubebuilder:object:root=true +// +kubebuilder:storageversion +// +kubebuilder:resource:categories=nginx-gateway-fabric,scope=Cluster +// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp` + +// NginxProxy is a configuration object that is attached to a GatewayClass parametersRef. It provides a way +// to configure global settings for all Gateways defined from the GatewayClass. +type NginxProxy struct { //nolint:govet // standard field alignment, don't change it + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + // Spec defines the desired state of the NginxProxy. + Spec NginxProxySpec `json:"spec"` +} + +// +kubebuilder:object:root=true + +// NginxProxyList contains a list of NginxProxies. +type NginxProxyList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []NginxProxy `json:"items"` +} + +// NginxProxySpec defines the desired state of the NginxProxy. +type NginxProxySpec struct { + // Telemetry specifies the OpenTelemetry configuration. + // + // +optional + Telemetry *Telemetry `json:"telemetry,omitempty"` +} + +// Telemetry specifies the OpenTelemetry configuration. +type Telemetry struct { + // Exporter specifies OpenTelemetry export parameters. + // + // +optional + Exporter *TelemetryExporter `json:"exporter,omitempty"` + + // ServiceName is the "service.name" attribute of the OpenTelemetry resource. + // Default is 'ngf::'. If a value is provided by the user, + // then the default becomes a prefix to that value. + // + // +optional + // +kubebuilder:validation:MaxLength=127 + // +kubebuilder:validation:Pattern=`^[a-zA-Z0-9_-]+$` + ServiceName *string `json:"serviceName,omitempty"` + + // SpanAttributes are custom key/value attributes that are added to each span. + // + // +optional + // +listType=map + // +listMapKey=key + // +kubebuilder:validation:MaxItems=64 + SpanAttributes []SpanAttribute `json:"spanAttributes,omitempty"` +} + +// TelemetryExporter specifies OpenTelemetry export parameters. +type TelemetryExporter struct { + // Interval is the maximum interval between two exports. + // Default: https://nginx.org/en/docs/ngx_otel_module.html#otel_exporter + // + // +optional + Interval *Duration `json:"interval,omitempty"` + + // BatchSize is the maximum number of spans to be sent in one batch per worker. + // Default: https://nginx.org/en/docs/ngx_otel_module.html#otel_exporter + // + // +optional + // +kubebuilder:validation:Minimum=0 + BatchSize *int32 `json:"batchSize,omitempty"` + + // BatchCount is the number of pending batches per worker, spans exceeding the limit are dropped. + // Default: https://nginx.org/en/docs/ngx_otel_module.html#otel_exporter + // + // +optional + // +kubebuilder:validation:Minimum=0 + BatchCount *int32 `json:"batchCount,omitempty"` + + // Endpoint is the address of OTLP/gRPC endpoint that will accept telemetry data. + // Format: alphanumeric hostname with optional http scheme and optional port. + // + //nolint:lll + // +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})?$` + Endpoint string `json:"endpoint"` +} + +// SpanAttribute is a key value pair to be added to a tracing span. +type SpanAttribute struct { + // Key is the key for a span attribute. + // + // +kubebuilder:validation:MinLength=1 + // +kubebuilder:validation:MaxLength=255 + // +kubebuilder:validation:Pattern=`^[a-zA-Z0-9_-]+$` + Key string `json:"key"` + + // Value is the value for a span attribute. + // + // +kubebuilder:validation:MinLength=1 + // +kubebuilder:validation:MaxLength=255 + // +kubebuilder:validation:Pattern=`^[a-zA-Z0-9_-]+$` + Value string `json:"value"` +} diff --git a/apis/v1alpha1/register.go b/apis/v1alpha1/register.go index 16947b8a6d..ada0bc7a06 100644 --- a/apis/v1alpha1/register.go +++ b/apis/v1alpha1/register.go @@ -34,6 +34,8 @@ func addKnownTypes(scheme *runtime.Scheme) error { scheme.AddKnownTypes(SchemeGroupVersion, &NginxGateway{}, &NginxGatewayList{}, + &NginxProxy{}, + &NginxProxyList{}, &ClientSettingsPolicy{}, &ClientSettingsPolicyList{}, ) diff --git a/apis/v1alpha1/shared_types.go b/apis/v1alpha1/shared_types.go new file mode 100644 index 0000000000..59f9d13d4d --- /dev/null +++ b/apis/v1alpha1/shared_types.go @@ -0,0 +1,8 @@ +package v1alpha1 + +// Duration is a string value representing a duration in time. +// Duration can be specified in milliseconds (ms) or seconds (s) A value without a suffix is seconds. +// Examples: 120s, 50ms. +// +// +kubebuilder:validation:Pattern=`^\d{1,4}(ms|s)?$` +type Duration string diff --git a/apis/v1alpha1/zz_generated.deepcopy.go b/apis/v1alpha1/zz_generated.deepcopy.go index 18511c38b7..2304c2941a 100644 --- a/apis/v1alpha1/zz_generated.deepcopy.go +++ b/apis/v1alpha1/zz_generated.deepcopy.go @@ -294,3 +294,156 @@ func (in *NginxGatewayStatus) DeepCopy() *NginxGatewayStatus { in.DeepCopyInto(out) return out } + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *NginxProxy) DeepCopyInto(out *NginxProxy) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NginxProxy. +func (in *NginxProxy) DeepCopy() *NginxProxy { + if in == nil { + return nil + } + out := new(NginxProxy) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *NginxProxy) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *NginxProxyList) DeepCopyInto(out *NginxProxyList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]NginxProxy, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NginxProxyList. +func (in *NginxProxyList) DeepCopy() *NginxProxyList { + if in == nil { + return nil + } + out := new(NginxProxyList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *NginxProxyList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *NginxProxySpec) DeepCopyInto(out *NginxProxySpec) { + *out = *in + if in.Telemetry != nil { + in, out := &in.Telemetry, &out.Telemetry + *out = new(Telemetry) + (*in).DeepCopyInto(*out) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NginxProxySpec. +func (in *NginxProxySpec) DeepCopy() *NginxProxySpec { + if in == nil { + return nil + } + out := new(NginxProxySpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *SpanAttribute) DeepCopyInto(out *SpanAttribute) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SpanAttribute. +func (in *SpanAttribute) DeepCopy() *SpanAttribute { + if in == nil { + return nil + } + out := new(SpanAttribute) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Telemetry) DeepCopyInto(out *Telemetry) { + *out = *in + if in.Exporter != nil { + in, out := &in.Exporter, &out.Exporter + *out = new(TelemetryExporter) + (*in).DeepCopyInto(*out) + } + if in.ServiceName != nil { + in, out := &in.ServiceName, &out.ServiceName + *out = new(string) + **out = **in + } + if in.SpanAttributes != nil { + in, out := &in.SpanAttributes, &out.SpanAttributes + *out = make([]SpanAttribute, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Telemetry. +func (in *Telemetry) DeepCopy() *Telemetry { + if in == nil { + return nil + } + out := new(Telemetry) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TelemetryExporter) DeepCopyInto(out *TelemetryExporter) { + *out = *in + if in.Interval != nil { + in, out := &in.Interval, &out.Interval + *out = new(Duration) + **out = **in + } + if in.BatchSize != nil { + in, out := &in.BatchSize, &out.BatchSize + *out = new(int32) + **out = **in + } + if in.BatchCount != nil { + in, out := &in.BatchCount, &out.BatchCount + *out = new(int32) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TelemetryExporter. +func (in *TelemetryExporter) DeepCopy() *TelemetryExporter { + if in == nil { + return nil + } + out := new(TelemetryExporter) + in.DeepCopyInto(out) + return out +} diff --git a/config/crd/bases/gateway.nginx.org_nginxproxies.yaml b/config/crd/bases/gateway.nginx.org_nginxproxies.yaml new file mode 100644 index 0000000000..6119184d92 --- /dev/null +++ b/config/crd/bases/gateway.nginx.org_nginxproxies.yaml @@ -0,0 +1,128 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.14.0 + name: nginxproxies.gateway.nginx.org +spec: + group: gateway.nginx.org + names: + categories: + - nginx-gateway-fabric + kind: NginxProxy + listKind: NginxProxyList + plural: nginxproxies + singular: nginxproxy + scope: Cluster + versions: + - additionalPrinterColumns: + - jsonPath: .metadata.creationTimestamp + name: Age + type: date + name: v1alpha1 + schema: + openAPIV3Schema: + description: |- + NginxProxy is a configuration object that is attached to a GatewayClass parametersRef. It provides a way + to configure global settings for all Gateways defined from the GatewayClass. + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + description: Spec defines the desired state of the NginxProxy. + properties: + telemetry: + description: Telemetry specifies the OpenTelemetry configuration. + properties: + exporter: + description: Exporter specifies OpenTelemetry export parameters. + properties: + batchCount: + description: |- + BatchCount is the number of pending batches per worker, spans exceeding the limit are dropped. + Default: https://nginx.org/en/docs/ngx_otel_module.html#otel_exporter + format: int32 + minimum: 0 + type: integer + batchSize: + description: |- + BatchSize is the maximum number of spans to be sent in one batch per worker. + Default: https://nginx.org/en/docs/ngx_otel_module.html#otel_exporter + format: int32 + minimum: 0 + type: integer + endpoint: + description: |- + Endpoint is the address of OTLP/gRPC endpoint that will accept telemetry data. + Format: alphanumeric hostname with optional http scheme and optional port. + 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})?$ + type: string + interval: + description: |- + Interval is the maximum interval between two exports. + Default: https://nginx.org/en/docs/ngx_otel_module.html#otel_exporter + pattern: ^\d{1,4}(ms|s)?$ + type: string + required: + - endpoint + type: object + serviceName: + description: |- + ServiceName is the "service.name" attribute of the OpenTelemetry resource. + Default is 'ngf::'. If a value is provided by the user, + then the default becomes a prefix to that value. + maxLength: 127 + pattern: ^[a-zA-Z0-9_-]+$ + type: string + spanAttributes: + description: SpanAttributes are custom key/value attributes that + are added to each span. + items: + description: SpanAttribute is a key value pair to be added to + a tracing span. + properties: + key: + description: Key is the key for a span attribute. + maxLength: 255 + minLength: 1 + pattern: ^[a-zA-Z0-9_-]+$ + type: string + value: + description: Value is the value for a span attribute. + maxLength: 255 + minLength: 1 + pattern: ^[a-zA-Z0-9_-]+$ + type: string + required: + - key + - value + type: object + maxItems: 64 + type: array + x-kubernetes-list-map-keys: + - key + x-kubernetes-list-type: map + type: object + type: object + required: + - spec + type: object + served: true + storage: true + subresources: {}