Skip to content

Commit 8971517

Browse files
committed
Update api version for observability policy
1 parent 3327afe commit 8971517

File tree

12 files changed

+1655
-12
lines changed

12 files changed

+1655
-12
lines changed

apis/v1alpha1/observabilitypolicy_types.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import (
77

88
// +genclient
99
// +kubebuilder:object:root=true
10-
// +kubebuilder:storageversion
10+
// +kubebuilder:deprecatedversion:warning="The 'v1alpha1' version of ObservabilityPolicy API is deprecated, please migrate to 'v1alpha2'."
1111
// +kubebuilder:subresource:status
1212
// +kubebuilder:resource:categories=nginx-gateway-fabric,scope=Namespaced
1313
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`
1414
// +kubebuilder:metadata:labels="gateway.networking.k8s.io/policy=direct"
15+
//nolint:lll
1516

1617
// ObservabilityPolicy is a Direct Attached Policy. It provides a way to configure observability settings for
1718
// the NGINX Gateway Fabric data plane. Used in conjunction with the NginxProxy CRD that is attached to the
@@ -47,14 +48,10 @@ type ObservabilityPolicySpec struct {
4748
// Objects must be in the same namespace as the policy.
4849
// Support: HTTPRoute, GRPCRoute.
4950
//
50-
// TargetRefs must be _distinct_. This means that the multi-part key defined by `kind` and `name` must
51-
// be unique across all targetRef entries in the ObservabilityPolicy.
52-
//
5351
// +kubebuilder:validation:MinItems=1
5452
// +kubebuilder:validation:MaxItems=16
5553
// +kubebuilder:validation:XValidation:message="TargetRef Kind must be: HTTPRoute or GRPCRoute",rule="(self.exists(t, t.kind=='HTTPRoute') || self.exists(t, t.kind=='GRPCRoute'))"
5654
// +kubebuilder:validation:XValidation:message="TargetRef Group must be gateway.networking.k8s.io",rule="self.all(t, t.group=='gateway.networking.k8s.io')"
57-
// +kubebuilder:validation:XValidation:message="TargetRef Kind and Name combination must be unique",rule="self.all(p1, self.exists_one(p2, (p1.name == p2.name) && (p1.kind == p2.kind)))"
5855
//nolint:lll
5956
TargetRefs []gatewayv1alpha2.LocalPolicyTargetReference `json:"targetRefs"`
6057
}

apis/v1alpha2/doc.go

Lines changed: 6 additions & 0 deletions
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
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
package v1alpha2
2+
3+
import (
4+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
5+
gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
6+
)
7+
8+
// +genclient
9+
// +kubebuilder:object:root=true
10+
// +kubebuilder:storageversion
11+
// +kubebuilder:subresource:status
12+
// +kubebuilder:resource:categories=nginx-gateway-fabric,scope=Namespaced
13+
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`
14+
// +kubebuilder:metadata:labels="gateway.networking.k8s.io/policy=direct"
15+
16+
// ObservabilityPolicy is a Direct Attached Policy. It provides a way to configure observability settings for
17+
// the NGINX Gateway Fabric data plane. Used in conjunction with the NginxProxy CRD that is attached to the
18+
// GatewayClass parametersRef.
19+
type ObservabilityPolicy struct {
20+
metav1.TypeMeta `json:",inline"`
21+
metav1.ObjectMeta `json:"metadata,omitempty"`
22+
23+
// Spec defines the desired state of the ObservabilityPolicy.
24+
Spec ObservabilityPolicySpec `json:"spec"`
25+
26+
// Status defines the state of the ObservabilityPolicy.
27+
Status gatewayv1alpha2.PolicyStatus `json:"status,omitempty"`
28+
}
29+
30+
// +kubebuilder:object:root=true
31+
32+
// ObservabilityPolicyList contains a list of ObservabilityPolicies.
33+
type ObservabilityPolicyList struct {
34+
metav1.TypeMeta `json:",inline"`
35+
metav1.ListMeta `json:"metadata,omitempty"`
36+
Items []ObservabilityPolicy `json:"items"`
37+
}
38+
39+
// ObservabilityPolicySpec defines the desired state of the ObservabilityPolicy.
40+
type ObservabilityPolicySpec struct {
41+
// Tracing allows for enabling and configuring tracing.
42+
//
43+
// +optional
44+
Tracing *Tracing `json:"tracing,omitempty"`
45+
46+
// TargetRefs identifies the API object(s) to apply the policy to.
47+
// Objects must be in the same namespace as the policy.
48+
// Support: HTTPRoute, GRPCRoute.
49+
//
50+
// TargetRefs must be _distinct_. This means that the multi-part key defined by `kind` and `name` must
51+
// be unique across all targetRef entries in the ObservabilityPolicy.
52+
//
53+
// +kubebuilder:validation:MinItems=1
54+
// +kubebuilder:validation:MaxItems=16
55+
// +kubebuilder:validation:XValidation:message="TargetRef Kind must be: HTTPRoute or GRPCRoute",rule="(self.exists(t, t.kind=='HTTPRoute') || self.exists(t, t.kind=='GRPCRoute'))"
56+
// +kubebuilder:validation:XValidation:message="TargetRef Group must be gateway.networking.k8s.io",rule="self.all(t, t.group=='gateway.networking.k8s.io')"
57+
// +kubebuilder:validation:XValidation:message="TargetRef Kind and Name combination must be unique",rule="self.all(p1, self.exists_one(p2, (p1.name == p2.name) && (p1.kind == p2.kind)))"
58+
//nolint:lll
59+
TargetRefs []gatewayv1alpha2.LocalPolicyTargetReference `json:"targetRefs"`
60+
}
61+
62+
// Tracing allows for enabling and configuring OpenTelemetry tracing.
63+
//
64+
// +kubebuilder:validation:XValidation:message="ratio can only be specified if strategy is of type ratio",rule="!(has(self.ratio) && self.strategy != 'ratio')"
65+
//
66+
//nolint:lll
67+
type Tracing struct {
68+
// Strategy defines if tracing is ratio-based or parent-based.
69+
Strategy TraceStrategy `json:"strategy"`
70+
71+
// Ratio is the percentage of traffic that should be sampled. Integer from 0 to 100.
72+
// By default, 100% of http requests are traced. Not applicable for parent-based tracing.
73+
// If ratio is set to 0, tracing is disabled.
74+
//
75+
// +optional
76+
// +kubebuilder:validation:Minimum=0
77+
// +kubebuilder:validation:Maximum=100
78+
Ratio *int32 `json:"ratio,omitempty"`
79+
80+
// Context specifies how to propagate traceparent/tracestate headers.
81+
// Default: https://nginx.org/en/docs/ngx_otel_module.html#otel_trace_context
82+
//
83+
// +optional
84+
Context *TraceContext `json:"context,omitempty"`
85+
86+
// SpanName defines the name of the Otel span. By default is the name of the location for a request.
87+
// If specified, applies to all locations that are created for a route.
88+
// Format: must have all '"' escaped and must not contain any '$' or end with an unescaped '\'
89+
// Examples of invalid names: some-$value, quoted-"value"-name, unescaped\
90+
//
91+
// +optional
92+
// +kubebuilder:validation:MinLength=1
93+
// +kubebuilder:validation:MaxLength=255
94+
// +kubebuilder:validation:Pattern=`^([^"$\\]|\\[^$])*$`
95+
SpanName *string `json:"spanName,omitempty"`
96+
97+
// SpanAttributes are custom key/value attributes that are added to each span.
98+
//
99+
// +optional
100+
// +listType=map
101+
// +listMapKey=key
102+
// +kubebuilder:validation:MaxItems=64
103+
SpanAttributes []SpanAttribute `json:"spanAttributes,omitempty"`
104+
}
105+
106+
// TraceStrategy defines the tracing strategy.
107+
//
108+
// +kubebuilder:validation:Enum=ratio;parent
109+
type TraceStrategy string
110+
111+
const (
112+
// TraceStrategyRatio enables ratio-based tracing, defaulting to 100% sampling rate.
113+
TraceStrategyRatio TraceStrategy = "ratio"
114+
115+
// TraceStrategyParent enables tracing and only records spans if the parent span was sampled.
116+
TraceStrategyParent TraceStrategy = "parent"
117+
)
118+
119+
// TraceContext specifies how to propagate traceparent/tracestate headers.
120+
//
121+
// +kubebuilder:validation:Enum=extract;inject;propagate;ignore
122+
type TraceContext string
123+
124+
const (
125+
// TraceContextExtract uses an existing trace context from the request, so that the identifiers
126+
// of a trace and the parent span are inherited from the incoming request.
127+
TraceContextExtract TraceContext = "extract"
128+
129+
// TraceContextInject adds a new context to the request, overwriting existing headers, if any.
130+
TraceContextInject TraceContext = "inject"
131+
132+
// TraceContextPropagate updates the existing context (combines extract and inject).
133+
TraceContextPropagate TraceContext = "propagate"
134+
135+
// TraceContextIgnore skips context headers processing.
136+
TraceContextIgnore TraceContext = "ignore"
137+
)

apis/v1alpha2/register.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package v1alpha2
2+
3+
import (
4+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
5+
"k8s.io/apimachinery/pkg/runtime"
6+
"k8s.io/apimachinery/pkg/runtime/schema"
7+
)
8+
9+
// GroupName specifies the group name used to register the objects.
10+
const GroupName = "gateway.nginx.org"
11+
12+
// SchemeGroupVersion is group version used to register these objects.
13+
var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1alpha2"}
14+
15+
// Resource takes an unqualified resource and returns a Group qualified GroupResource.
16+
func Resource(resource string) schema.GroupResource {
17+
return SchemeGroupVersion.WithResource(resource).GroupResource()
18+
}
19+
20+
var (
21+
// SchemeBuilder collects functions that add things to a scheme. It's to allow
22+
// code to compile without explicitly referencing generated types. You should
23+
// declare one in each package that will have generated deep copy or conversion
24+
// functions.
25+
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
26+
27+
// AddToScheme applies all the stored functions to the scheme. A non-nil error
28+
// indicates that one function failed and the attempt was abandoned.
29+
AddToScheme = SchemeBuilder.AddToScheme
30+
)
31+
32+
// Adds the list of known types to Scheme.
33+
func addKnownTypes(scheme *runtime.Scheme) error {
34+
scheme.AddKnownTypes(SchemeGroupVersion,
35+
&ObservabilityPolicy{},
36+
&ObservabilityPolicyList{},
37+
)
38+
// AddToGroupVersion allows the serialization of client types like ListOptions.
39+
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
40+
41+
return nil
42+
}

apis/v1alpha2/shared_types.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package v1alpha2
2+
3+
// Duration is a string value representing a duration in time.
4+
// Duration can be specified in milliseconds (ms), seconds (s), minutes (m), hours (h).
5+
// A value without a suffix is seconds.
6+
// Examples: 120s, 50ms, 5m, 1h.
7+
//
8+
// +kubebuilder:validation:Pattern=`^[0-9]{1,4}(ms|s|m|h)?$`
9+
type Duration string
10+
11+
// SpanAttribute is a key value pair to be added to a tracing span.
12+
type SpanAttribute struct {
13+
// Key is the key for a span attribute.
14+
// Format: must have all '"' escaped and must not contain any '$' or end with an unescaped '\'
15+
//
16+
// +kubebuilder:validation:MinLength=1
17+
// +kubebuilder:validation:MaxLength=255
18+
// +kubebuilder:validation:Pattern=`^([^"$\\]|\\[^$])*$`
19+
Key string `json:"key"`
20+
21+
// Value is the value for a span attribute.
22+
// Format: must have all '"' escaped and must not contain any '$' or end with an unescaped '\'
23+
//
24+
// +kubebuilder:validation:MinLength=1
25+
// +kubebuilder:validation:MaxLength=255
26+
// +kubebuilder:validation:Pattern=`^([^"$\\]|\\[^$])*$`
27+
Value string `json:"value"`
28+
}

apis/v1alpha2/zz_generated.deepcopy.go

Lines changed: 144 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)