Skip to content

Commit e324a7f

Browse files
committed
Added more validation rules
1 parent 703bd61 commit e324a7f

8 files changed

+275
-73
lines changed

apis/v1beta1/opentelemetrycollector_types.go

+26-7
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,17 @@ type OpenTelemetryCollectorSpec struct {
9090
// +optional
9191
TargetAllocator TargetAllocatorEmbedded `json:"targetAllocator,omitempty"`
9292
// Mode represents how the collector should be deployed (deployment, daemonset, statefulset or sidecar)
93-
// +kubebuilder:validation:Enum=ModeDeployment;ModeDaemonSet;ModeStatefulSet;ModeSidecar
93+
// +kubebuilder:default=deployment
94+
// +kubebuilder:validation:Enum=deployment;daemonset;statefulset;sidecar
9495
Mode Mode `json:"mode,omitempty"`
9596
// UpgradeStrategy represents how the operator will handle upgrades to the CR when a newer version of the operator is deployed
96-
// +kubebuilder:validation:Enum=UpgradeStrategyAutomatic
97+
// +kubebuilder:default=automatic
98+
// +kubebuilder:validation:Enum=automatic;manual
9799
UpgradeStrategy UpgradeStrategy `json:"upgradeStrategy"`
98100
// Config is the raw JSON to be used as the collector's configuration. Refer to the OpenTelemetry Collector documentation for details.
99101
// The empty objects e.g. batch: should be written as batch: {} otherwise they won't work with kustomize or kubectl edit.
100102
// +required
103+
// +kubebuilder:validation:required
101104
// +kubebuilder:pruning:PreserveUnknownFields
102105
Config Config `json:"config"`
103106
// ConfigVersions defines the number versions to keep for the collector config. Each config version is stored in a separate ConfigMap.
@@ -110,17 +113,15 @@ type OpenTelemetryCollectorSpec struct {
110113
// functionality is only available if one of the valid modes is set.
111114
// Valid modes are: deployment, daemonset and statefulset.
112115
// +optional
113-
// +kubebuilder:validation:Enum=ModeDeployment;ModeDaemonSet;ModeStatefulSet;
116+
// +kubebuilder:validation:Enum=deployment;daemonSet;statefulSet;
114117
Ingress Ingress `json:"ingress,omitempty"`
115118
// Liveness config for the OpenTelemetry Collector except the probe handler which is auto generated from the health extension of the collector.
116119
// It is only effective when healthcheckextension is configured in the OpenTelemetry Collector pipeline.
117120
// +optional
118-
// +kubebuilder:validation:Required
119121
LivenessProbe *Probe `json:"livenessProbe,omitempty"`
120122
// Readiness config for the OpenTelemetry Collector except the probe handler which is auto generated from the health extension of the collector.
121123
// It is only effective when healthcheckextension is configured in the OpenTelemetry Collector pipeline.
122124
// +optional
123-
// +kubebuilder:validation:Required
124125
ReadinessProbe *Probe `json:"readinessProbe,omitempty"`
125126

126127
// ObservabilitySpec defines how telemetry data gets handled.
@@ -138,13 +139,13 @@ type OpenTelemetryCollectorSpec struct {
138139
// https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/daemon-set-v1/#DaemonSetSpec
139140
// This is only applicable to Daemonset mode.
140141
// +optional
141-
// +kubebuilder:validation:Enum=ModeDaemonset
142+
// +kubebuilder:validation:Enum=daemonset
142143
DaemonSetUpdateStrategy appsv1.DaemonSetUpdateStrategy `json:"daemonSetUpdateStrategy,omitempty"`
143144
// UpdateStrategy represents the strategy the operator will take replacing existing Deployment pods with new pods
144145
// https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/deployment-v1/#DeploymentSpec
145146
// This is only applicable to Deployment mode.
146147
// +optional
147-
// +kubebuilder:validation:Enum=ModeDeployment
148+
// +kubebuilder:validation:Enum=deployment
148149
DeploymentUpdateStrategy appsv1.DeploymentStrategy `json:"deploymentUpdateStrategy,omitempty"`
149150
}
150151

@@ -155,6 +156,7 @@ type TargetAllocatorEmbedded struct {
155156
// other than 1 if a strategy that allows for high availability is chosen. Currently, the only allocation strategy
156157
// that can be run in a high availability mode is consistent-hashing.
157158
// +optional
159+
// +kubebuilder:validation:Minimum=1
158160
Replicas *int32 `json:"replicas,omitempty"`
159161
// NodeSelector to schedule OpenTelemetry TargetAllocator pods.
160162
// +optional
@@ -168,12 +170,14 @@ type TargetAllocatorEmbedded struct {
168170
// WARNING: The per-node strategy currently ignores targets without a Node, like control plane components.
169171
// +optional
170172
// +kubebuilder:default:=consistent-hashing
173+
// +kubebuilder:validation:Enum=consistent-hashing;least-weighted;per-node
171174
AllocationStrategy TargetAllocatorAllocationStrategy `json:"allocationStrategy,omitempty"`
172175
// FilterStrategy determines how to filter targets before allocating them among the collectors.
173176
// The only current option is relabel-config (drops targets based on prom relabel_config).
174177
// The default is relabel-config.
175178
// +optional
176179
// +kubebuilder:default:=relabel-config
180+
// +kubebuilder:validation:Enum=relabel-config
177181
FilterStrategy TargetAllocatorFilterStrategy `json:"filterStrategy,omitempty"`
178182
// ServiceAccount indicates the name of an existing service account to use with this instance. When set,
179183
// the operator will not automatically create a ServiceAccount for the TargetAllocator.
@@ -234,23 +238,33 @@ type Probe struct {
234238
// Defaults to 0 seconds. Minimum value is 0.
235239
// More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
236240
// +optional
241+
// +kubebuilder:default=0
242+
// +kubebuilder:validation:Minimum=0
237243
InitialDelaySeconds *int32 `json:"initialDelaySeconds,omitempty"`
238244
// Number of seconds after which the probe times out.
239245
// Defaults to 1 second. Minimum value is 1.
240246
// More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
241247
// +optional
248+
// // +kubebuilder:default=1
249+
// +kubebuilder:validation:Minimum=1
242250
TimeoutSeconds *int32 `json:"timeoutSeconds,omitempty"`
243251
// How often (in seconds) to perform the probe.
244252
// Default to 10 seconds. Minimum value is 1.
245253
// +optional
254+
// +kubebuilder:default=10
255+
// +kubebuilder:validation:Minimum=1
246256
PeriodSeconds *int32 `json:"periodSeconds,omitempty"`
247257
// Minimum consecutive successes for the probe to be considered successful after having failed.
248258
// Defaults to 1. Must be 1 for liveness and startup. Minimum value is 1.
249259
// +optional
260+
// +kubebuilder:default=1
261+
// +kubebuilder:validation:Minimum=1
250262
SuccessThreshold *int32 `json:"successThreshold,omitempty"`
251263
// Minimum consecutive failures for the probe to be considered failed after having succeeded.
252264
// Defaults to 3. Minimum value is 1.
253265
// +optional
266+
// +kubebuilder:default=3
267+
// +kubebuilder:validation:Minimum=1
254268
FailureThreshold *int32 `json:"failureThreshold,omitempty"`
255269
// Optional duration in seconds the pod needs to terminate gracefully upon probe failure.
256270
// The grace period is the duration in seconds after the processes running in the pod are sent
@@ -263,6 +277,7 @@ type Probe struct {
263277
// This is a beta field and requires enabling ProbeTerminationGracePeriod feature gate.
264278
// Minimum value is 1. spec.terminationGracePeriodSeconds is used if unset.
265279
// +optional
280+
// +kubebuilder:validation:Minimum=1
266281
TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty"`
267282
}
268283

@@ -299,11 +314,13 @@ type ScaleSubresourceStatus struct {
299314
// The selector used to match the OpenTelemetryCollector's
300315
// deployment or statefulSet pods.
301316
// +optional
317+
// +kubebuilder:validation:Enum=deployment;statefulset
302318
Selector string `json:"selector,omitempty"`
303319

304320
// The total number non-terminated pods targeted by this
305321
// OpenTelemetryCollector's deployment or statefulSet.
306322
// +optional
323+
// +kubebuilder:validation:Minimum=0
307324
Replicas int32 `json:"replicas,omitempty"`
308325

309326
// StatusReplicas is the number of pods targeted by this OpenTelemetryCollector's with a Ready Condition /
@@ -315,6 +332,8 @@ type ScaleSubresourceStatus struct {
315332

316333
type ConfigMapsSpec struct {
317334
// Configmap defines name and path where the configMaps should be mounted.
335+
// +kubebuilder:validation:Required
336+
// +kubebuilder:validation:MinLength=3
318337
Name string `json:"name"`
319338
MountPath string `json:"mountpath"`
320339
}

bundle/community/manifests/opentelemetry-operator.clusterserviceversion.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ metadata:
9999
categories: Logging & Tracing,Monitoring
100100
certified: "false"
101101
containerImage: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator
102-
createdAt: "2024-09-19T17:15:52Z"
102+
createdAt: "2024-10-06T07:35:12Z"
103103
description: Provides the OpenTelemetry components, including the Collector
104104
operators.operatorframework.io/builder: operator-sdk-v1.29.0
105105
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
@@ -479,7 +479,7 @@ spec:
479479
valueFrom:
480480
fieldRef:
481481
fieldPath: spec.serviceAccountName
482-
image: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator:0.109.0
482+
image: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator:0.109.0-14-g703bd614
483483
livenessProbe:
484484
httpGet:
485485
path: /healthz

bundle/community/manifests/opentelemetry.io_opentelemetrycollectors.yaml

+65-15
Original file line numberDiff line numberDiff line change
@@ -5930,6 +5930,8 @@ spec:
59305930
type: object
59315931
type: array
59325932
daemonSetUpdateStrategy:
5933+
enum:
5934+
- daemonset
59335935
properties:
59345936
rollingUpdate:
59355937
properties:
@@ -5948,6 +5950,8 @@ spec:
59485950
type: string
59495951
type: object
59505952
deploymentUpdateStrategy:
5953+
enum:
5954+
- deployment
59515955
properties:
59525956
rollingUpdate:
59535957
properties:
@@ -6063,6 +6067,10 @@ spec:
60636067
imagePullPolicy:
60646068
type: string
60656069
ingress:
6070+
enum:
6071+
- deployment
6072+
- daemonSet
6073+
- statefulSet
60666074
properties:
60676075
annotations:
60686076
additionalProperties:
@@ -6918,22 +6926,32 @@ spec:
69186926
livenessProbe:
69196927
properties:
69206928
failureThreshold:
6929+
default: 3
69216930
format: int32
6931+
minimum: 1
69226932
type: integer
69236933
initialDelaySeconds:
6934+
default: 0
69246935
format: int32
6936+
minimum: 0
69256937
type: integer
69266938
periodSeconds:
6939+
default: 10
69276940
format: int32
6941+
minimum: 1
69286942
type: integer
69296943
successThreshold:
6944+
default: 1
69306945
format: int32
6946+
minimum: 1
69316947
type: integer
69326948
terminationGracePeriodSeconds:
69336949
format: int64
6950+
minimum: 1
69346951
type: integer
69356952
timeoutSeconds:
69366953
format: int32
6954+
minimum: 1
69376955
type: integer
69386956
type: object
69396957
managementState:
@@ -6943,11 +6961,18 @@ spec:
69436961
- unmanaged
69446962
type: string
69456963
mode:
6946-
enum:
6947-
- daemonset
6948-
- deployment
6949-
- sidecar
6950-
- statefulset
6964+
allOf:
6965+
- enum:
6966+
- daemonset
6967+
- deployment
6968+
- sidecar
6969+
- statefulset
6970+
- enum:
6971+
- deployment
6972+
- daemonset
6973+
- statefulset
6974+
- sidecar
6975+
default: deployment
69516976
type: string
69526977
nodeSelector:
69536978
additionalProperties:
@@ -7114,22 +7139,32 @@ spec:
71147139
readinessProbe:
71157140
properties:
71167141
failureThreshold:
7142+
default: 3
71177143
format: int32
7144+
minimum: 1
71187145
type: integer
71197146
initialDelaySeconds:
7147+
default: 0
71207148
format: int32
7149+
minimum: 0
71217150
type: integer
71227151
periodSeconds:
7152+
default: 10
71237153
format: int32
7154+
minimum: 1
71247155
type: integer
71257156
successThreshold:
7157+
default: 1
71267158
format: int32
7159+
minimum: 1
71277160
type: integer
71287161
terminationGracePeriodSeconds:
71297162
format: int64
7163+
minimum: 1
71307164
type: integer
71317165
timeoutSeconds:
71327166
format: int32
7167+
minimum: 1
71337168
type: integer
71347169
type: object
71357170
replicas:
@@ -7686,11 +7721,16 @@ spec:
76867721
type: object
76877722
type: object
76887723
allocationStrategy:
7724+
allOf:
7725+
- enum:
7726+
- least-weighted
7727+
- consistent-hashing
7728+
- per-node
7729+
- enum:
7730+
- consistent-hashing
7731+
- least-weighted
7732+
- per-node
76897733
default: consistent-hashing
7690-
enum:
7691-
- least-weighted
7692-
- consistent-hashing
7693-
- per-node
76947734
type: string
76957735
enabled:
76967736
type: boolean
@@ -7761,10 +7801,13 @@ spec:
77617801
type: object
77627802
type: array
77637803
filterStrategy:
7804+
allOf:
7805+
- enum:
7806+
- ""
7807+
- relabel-config
7808+
- enum:
7809+
- relabel-config
77647810
default: relabel-config
7765-
enum:
7766-
- ""
7767-
- relabel-config
77687811
type: string
77697812
image:
77707813
type: string
@@ -7935,6 +7978,7 @@ spec:
79357978
type: object
79367979
replicas:
79377980
format: int32
7981+
minimum: 1
79387982
type: integer
79397983
resources:
79407984
properties:
@@ -8188,9 +8232,14 @@ spec:
81888232
type: object
81898233
type: array
81908234
upgradeStrategy:
8191-
enum:
8192-
- automatic
8193-
- none
8235+
allOf:
8236+
- enum:
8237+
- automatic
8238+
- none
8239+
- enum:
8240+
- automatic
8241+
- manual
8242+
default: automatic
81948243
type: string
81958244
volumeClaimTemplates:
81968245
items:
@@ -9201,6 +9250,7 @@ spec:
92019250
required:
92029251
- config
92039252
- managementState
9253+
- upgradeStrategy
92049254
type: object
92059255
status:
92069256
properties:

bundle/openshift/manifests/opentelemetry-operator.clusterserviceversion.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ metadata:
9999
categories: Logging & Tracing,Monitoring
100100
certified: "false"
101101
containerImage: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator
102-
createdAt: "2024-09-19T17:16:12Z"
102+
createdAt: "2024-10-06T07:35:23Z"
103103
description: Provides the OpenTelemetry components, including the Collector
104104
operators.operatorframework.io/builder: operator-sdk-v1.29.0
105105
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
@@ -483,7 +483,7 @@ spec:
483483
valueFrom:
484484
fieldRef:
485485
fieldPath: spec.serviceAccountName
486-
image: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator:0.109.0
486+
image: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator:0.109.0-14-g703bd614
487487
livenessProbe:
488488
httpGet:
489489
path: /healthz

0 commit comments

Comments
 (0)