Skip to content

Commit 514748f

Browse files
committed
update api to have minimum one target refs
1 parent fb9cad3 commit 514748f

File tree

8 files changed

+1625
-1
lines changed

8 files changed

+1625
-1
lines changed

apis/v1alpha1/observabilitypolicy_types.go

Lines changed: 2 additions & 1 deletion
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

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: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
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+
// +kubebuilder:validation:MinItems=1
51+
// +kubebuilder:validation:MaxItems=16
52+
// +kubebuilder:validation:XValidation:message="TargetRef Kind must be: HTTPRoute or GRPCRoute",rule="(self.exists(t, t.kind=='HTTPRoute') || self.exists(t, t.kind=='GRPCRoute'))"
53+
// +kubebuilder:validation:XValidation:message="TargetRef Group must be gateway.networking.k8s.io.",rule="self.all(t, t.group=='gateway.networking.k8s.io')"
54+
//nolint:lll
55+
TargetRefs []gatewayv1alpha2.LocalPolicyTargetReference `json:"targetRefs"`
56+
}
57+
58+
// Tracing allows for enabling and configuring OpenTelemetry tracing.
59+
//
60+
// +kubebuilder:validation:XValidation:message="ratio can only be specified if strategy is of type ratio",rule="!(has(self.ratio) && self.strategy != 'ratio')"
61+
//
62+
//nolint:lll
63+
type Tracing struct {
64+
// Strategy defines if tracing is ratio-based or parent-based.
65+
Strategy TraceStrategy `json:"strategy"`
66+
67+
// Ratio is the percentage of traffic that should be sampled. Integer from 0 to 100.
68+
// By default, 100% of http requests are traced. Not applicable for parent-based tracing.
69+
// If ratio is set to 0, tracing is disabled.
70+
//
71+
// +optional
72+
// +kubebuilder:validation:Minimum=0
73+
// +kubebuilder:validation:Maximum=100
74+
Ratio *int32 `json:"ratio,omitempty"`
75+
76+
// Context specifies how to propagate traceparent/tracestate headers.
77+
// Default: https://nginx.org/en/docs/ngx_otel_module.html#otel_trace_context
78+
//
79+
// +optional
80+
Context *TraceContext `json:"context,omitempty"`
81+
82+
// SpanName defines the name of the Otel span. By default is the name of the location for a request.
83+
// If specified, applies to all locations that are created for a route.
84+
// Format: must have all '"' escaped and must not contain any '$' or end with an unescaped '\'
85+
// Examples of invalid names: some-$value, quoted-"value"-name, unescaped\
86+
//
87+
// +optional
88+
// +kubebuilder:validation:MinLength=1
89+
// +kubebuilder:validation:MaxLength=255
90+
// +kubebuilder:validation:Pattern=`^([^"$\\]|\\[^$])*$`
91+
SpanName *string `json:"spanName,omitempty"`
92+
93+
// SpanAttributes are custom key/value attributes that are added to each span.
94+
//
95+
// +optional
96+
// +listType=map
97+
// +listMapKey=key
98+
// +kubebuilder:validation:MaxItems=64
99+
SpanAttributes []SpanAttribute `json:"spanAttributes,omitempty"`
100+
}
101+
102+
// SpanAttribute is a key value pair to be added to a tracing span.
103+
type SpanAttribute struct {
104+
// Key is the key for a span attribute.
105+
// Format: must have all '"' escaped and must not contain any '$' or end with an unescaped '\'
106+
//
107+
// +kubebuilder:validation:MinLength=1
108+
// +kubebuilder:validation:MaxLength=255
109+
// +kubebuilder:validation:Pattern=`^([^"$\\]|\\[^$])*$`
110+
Key string `json:"key"`
111+
112+
// Value is the value for a span attribute.
113+
// Format: must have all '"' escaped and must not contain any '$' or end with an unescaped '\'
114+
//
115+
// +kubebuilder:validation:MinLength=1
116+
// +kubebuilder:validation:MaxLength=255
117+
// +kubebuilder:validation:Pattern=`^([^"$\\]|\\[^$])*$`
118+
Value string `json:"value"`
119+
}
120+
121+
// TraceStrategy defines the tracing strategy.
122+
//
123+
// +kubebuilder:validation:Enum=ratio;parent
124+
type TraceStrategy string
125+
126+
const (
127+
// TraceStrategyRatio enables ratio-based tracing, defaulting to 100% sampling rate.
128+
TraceStrategyRatio TraceStrategy = "ratio"
129+
130+
// TraceStrategyParent enables tracing and only records spans if the parent span was sampled.
131+
TraceStrategyParent TraceStrategy = "parent"
132+
)
133+
134+
// TraceContext specifies how to propagate traceparent/tracestate headers.
135+
//
136+
// +kubebuilder:validation:Enum=extract;inject;propagate;ignore
137+
type TraceContext string
138+
139+
const (
140+
// TraceContextExtract uses an existing trace context from the request, so that the identifiers
141+
// of a trace and the parent span are inherited from the incoming request.
142+
TraceContextExtract TraceContext = "extract"
143+
144+
// TraceContextInject adds a new context to the request, overwriting existing headers, if any.
145+
TraceContextInject TraceContext = "inject"
146+
147+
// TraceContextPropagate updates the existing context (combines extract and inject).
148+
TraceContextPropagate TraceContext = "propagate"
149+
150+
// TraceContextIgnore skips context headers processing.
151+
TraceContextIgnore TraceContext = "ignore"
152+
)

apis/v1alpha2/register.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
return nil
41+
}

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)