Skip to content

Commit 32ed855

Browse files
committed
test: add fuzzing of operatorconfig validation
1 parent e637796 commit 32ed855

21 files changed

Lines changed: 465 additions & 100 deletions

charts/operator/crds/monitoring.googleapis.com_operatorconfigs.yaml

Lines changed: 31 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ spec:
4646
compression:
4747
description: Compression enables compression of metrics collection
4848
data
49-
enum:
50-
- none
51-
- gzip
5249
type: string
5350
credentials:
5451
description: |-
@@ -79,8 +76,8 @@ spec:
7976
type: object
8077
x-kubernetes-map-type: atomic
8178
x-kubernetes-validations:
82-
- rule: has(self.name) && self.name.matches('^[a-z0-9]([-a-z0-9.]*[a-z0-9])?$')
83-
&& size(self.name) <= 253
79+
- message: missing secret key selector name
80+
rule: has(self.name) && self.name != ''
8481
externalLabels:
8582
additionalProperties:
8683
type: string
@@ -89,9 +86,6 @@ spec:
8986
data before being written to Google Cloud Monitoring or any other additional exports
9087
specified in the OperatorConfig. The precedence behavior matches that of Prometheus.
9188
type: object
92-
x-kubernetes-validations:
93-
- message: Invalid label key
94-
rule: self.all(key, key.matches('^[a-zA-Z_][a-zA-Z0-9_]*$'))
9589
filter:
9690
description: Filter limits which metric data is sent to Cloud Monitoring
9791
(it doesn't apply to additional exports).
@@ -142,6 +136,7 @@ spec:
142136
properties:
143137
interval:
144138
description: The interval at which the metric endpoints are scraped.
139+
format: duration
145140
type: string
146141
tlsInsecureSkipVerify:
147142
description: |-
@@ -162,13 +157,14 @@ spec:
162157
url:
163158
description: The URL of the endpoint that supports Prometheus Remote
164159
Write to export samples to.
160+
format: uri
165161
type: string
166162
x-kubernetes-validations:
167-
- rule: self == '' || isURL(self)
163+
- message: url must be a valid URL
164+
rule: self == '' || isURL(self)
168165
required:
169166
- url
170167
type: object
171-
maxItems: 10
172168
type: array
173169
features:
174170
description: Features holds configuration for optional managed-collection
@@ -182,9 +178,6 @@ spec:
182178
Compression enables compression of the config data propagated by the operator to collectors
183179
and the rule-evaluator. It is recommended to use the gzip option when using a large number of
184180
ClusterPodMonitoring, PodMonitoring, GlobalRules, ClusterRules, and/or Rules.
185-
enum:
186-
- none
187-
- gzip
188181
type: string
189182
type: object
190183
targetStatus:
@@ -237,8 +230,8 @@ spec:
237230
type: object
238231
x-kubernetes-map-type: atomic
239232
x-kubernetes-validations:
240-
- rule: has(self.name) && self.name.matches('^[a-z0-9]([-a-z0-9.]*[a-z0-9])?$')
241-
&& size(self.name) <= 253
233+
- message: missing secret key selector name
234+
rule: has(self.name) && self.name != ''
242235
externalURL:
243236
description: |-
244237
ExternalURL is the URL under which Alertmanager is externally reachable (for example, if
@@ -248,9 +241,11 @@ spec:
248241
be derived automatically.
249242
250243
If no URL is provided, Alertmanager will point to the Google Cloud Metric Explorer page.
244+
format: uri
251245
type: string
252246
x-kubernetes-validations:
253-
- rule: self == '' || isURL(self)
247+
- message: externalURL must be a valid URL
248+
rule: self == '' || isURL(self)
254249
type: object
255250
metadata:
256251
type: object
@@ -303,8 +298,8 @@ spec:
303298
type: object
304299
x-kubernetes-map-type: atomic
305300
x-kubernetes-validations:
306-
- rule: has(self.name) && self.name.matches('^[a-z0-9]([-a-z0-9.]*[a-z0-9])?$')
307-
&& size(self.name) <= 253
301+
- message: missing secret key selector name
302+
rule: has(self.name) && self.name != ''
308303
type:
309304
description: |-
310305
Set the authentication type. Defaults to Bearer, Basic will cause an
@@ -313,13 +308,9 @@ spec:
313308
type: object
314309
name:
315310
description: Name of Endpoints object in Namespace.
316-
maxLength: 63
317-
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
318311
type: string
319312
namespace:
320313
description: Namespace of Endpoints object.
321-
maxLength: 63
322-
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
323314
type: string
324315
pathPrefix:
325316
description: Prefix for the HTTP path alerts are pushed
@@ -333,13 +324,11 @@ spec:
333324
x-kubernetes-int-or-string: true
334325
scheme:
335326
description: Scheme to use when firing alerts.
336-
enum:
337-
- http
338-
- https
339327
type: string
340328
timeout:
341329
description: Timeout is a per-target Alertmanager timeout
342330
when pushing alerts.
331+
format: duration
343332
type: string
344333
tls:
345334
description: TLS Config to use for alertmanager connection.
@@ -398,9 +387,12 @@ spec:
398387
type: object
399388
x-kubernetes-map-type: atomic
400389
x-kubernetes-validations:
401-
- rule: has(self.name) && self.name.matches('^[a-z0-9]([-a-z0-9.]*[a-z0-9])?$')
402-
&& size(self.name) <= 253
390+
- message: missing secret key selector name
391+
rule: has(self.name) && self.name != ''
403392
type: object
393+
x-kubernetes-validations:
394+
- message: SecretOrConfigMap fields are mutually exclusive
395+
rule: '!(has(self.secret) && has(self.configMap))'
404396
cert:
405397
description: Struct containing the client cert file
406398
for the targets.
@@ -455,9 +447,12 @@ spec:
455447
type: object
456448
x-kubernetes-map-type: atomic
457449
x-kubernetes-validations:
458-
- rule: has(self.name) && self.name.matches('^[a-z0-9]([-a-z0-9.]*[a-z0-9])?$')
459-
&& size(self.name) <= 253
450+
- message: missing secret key selector name
451+
rule: has(self.name) && self.name != ''
460452
type: object
453+
x-kubernetes-validations:
454+
- message: SecretOrConfigMap fields are mutually exclusive
455+
rule: '!(has(self.secret) && has(self.configMap))'
461456
insecureSkipVerify:
462457
description: Disable target certificate validation.
463458
type: boolean
@@ -487,8 +482,8 @@ spec:
487482
type: object
488483
x-kubernetes-map-type: atomic
489484
x-kubernetes-validations:
490-
- rule: has(self.name) && self.name.matches('^[a-z0-9]([-a-z0-9.]*[a-z0-9])?$')
491-
&& size(self.name) <= 253
485+
- message: missing secret key selector name
486+
rule: has(self.name) && self.name != ''
492487
maxVersion:
493488
description: |-
494489
Maximum TLS version. Accepted values: TLS10 (TLS 1.0), TLS11 (TLS 1.1), TLS12 (TLS 1.2), TLS13 (TLS 1.3).
@@ -510,7 +505,6 @@ spec:
510505
- namespace
511506
- port
512507
type: object
513-
maxItems: 3
514508
type: array
515509
type: object
516510
credentials:
@@ -543,8 +537,8 @@ spec:
543537
type: object
544538
x-kubernetes-map-type: atomic
545539
x-kubernetes-validations:
546-
- rule: has(self.name) && self.name.matches('^[a-z0-9]([-a-z0-9.]*[a-z0-9])?$')
547-
&& size(self.name) <= 253
540+
- message: missing secret key selector name
541+
rule: has(self.name) && self.name != ''
548542
externalLabels:
549543
additionalProperties:
550544
type: string
@@ -553,26 +547,21 @@ spec:
553547
results and alerts produced by rules. The precedence behavior matches that
554548
of Prometheus.
555549
type: object
556-
x-kubernetes-validations:
557-
- message: Invalid label key
558-
rule: self.all(key, key.matches('^[a-zA-Z_][a-zA-Z0-9_]*$'))
559550
generatorUrl:
560551
description: |-
561552
The base URL used for the generator URL in the alert notification payload.
562553
Should point to an instance of a query frontend that gives access to queryProjectID.
554+
format: uri
563555
type: string
564556
x-kubernetes-validations:
565-
- rule: self == '' || isURL(self)
557+
- message: generatorUrl must be a valid URL
558+
rule: self == '' || isURL(self)
566559
queryProjectID:
567560
description: |-
568561
QueryProjectID is the GCP project ID to evaluate rules against.
569562
If left blank, the rule-evaluator will try attempt to infer the Project ID
570563
from the environment.
571564
type: string
572-
x-kubernetes-validations:
573-
- message: Invalid GCP project ID
574-
rule: self == '' || (self.matches('^[a-z][a-z0-9-]*[a-z0-9]$') &&
575-
size(self) >= 6 && size(self) <= 30)
576565
type: object
577566
scaling:
578567
description: Scaling contains configuration options for scaling GMP.

go.mod

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ require (
4444
sigs.k8s.io/controller-runtime v0.18.7
4545
)
4646

47-
require github.com/efficientgo/e2e v0.14.1-0.20230710114240-c316eb95ae5b
47+
require (
48+
github.com/efficientgo/e2e v0.14.1-0.20230710114240-c316eb95ae5b
49+
k8s.io/apiserver v0.30.14
50+
)
4851

4952
require (
5053
cloud.google.com/go/auth v0.16.5 // indirect
@@ -55,6 +58,7 @@ require (
5558
github.com/AzureAD/microsoft-authentication-library-for-go v1.4.2 // indirect
5659
github.com/Microsoft/go-winio v0.6.2 // indirect
5760
github.com/alecthomas/units v0.0.0-20240927000941-0f3dac36c52b // indirect
61+
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230305170008-8188dc5388df // indirect
5862
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
5963
github.com/aws/aws-sdk-go v1.55.8 // indirect
6064
github.com/aws/aws-sdk-go-v2 v1.38.1 // indirect
@@ -72,6 +76,7 @@ require (
7276
github.com/aws/smithy-go v1.22.5 // indirect
7377
github.com/bboreham/go-loser v0.0.0-20230920113527-fcc2c21820a3 // indirect
7478
github.com/beorn7/perks v1.0.1 // indirect
79+
github.com/blang/semver/v4 v4.0.0 // indirect
7580
github.com/cespare/xxhash/v2 v2.3.0 // indirect
7681
github.com/containerd/errdefs v1.0.0 // indirect
7782
github.com/containerd/errdefs/pkg v0.3.0 // indirect
@@ -105,6 +110,7 @@ require (
105110
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
106111
github.com/golang/protobuf v1.5.4 // indirect
107112
github.com/golang/snappy v1.0.0 // indirect
113+
github.com/google/cel-go v0.17.8 // indirect
108114
github.com/google/gnostic-models v0.7.0 // indirect
109115
github.com/google/gofuzz v1.2.0 // indirect
110116
github.com/google/pprof v0.0.0-20250820193118-f64d9cf942d6 // indirect
@@ -144,6 +150,7 @@ require (
144150
github.com/prometheus/procfs v0.17.0 // indirect
145151
github.com/prometheus/sigv4 v0.2.1 // indirect
146152
github.com/spf13/pflag v1.0.10 // indirect
153+
github.com/stoewer/go-strcase v1.2.0 // indirect
147154
github.com/xhit/go-str2duration/v2 v2.1.0 // indirect
148155
go.mongodb.org/mongo-driver v1.17.7 // indirect
149156
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
@@ -171,6 +178,7 @@ require (
171178
google.golang.org/genproto v0.0.0-20250825161204-c5933d9347a5 // indirect
172179
google.golang.org/genproto/googleapis/rpc v0.0.0-20251202230838-ff82c1b0f217 // indirect
173180
gopkg.in/inf.v0 v0.9.1 // indirect
181+
k8s.io/component-base v0.30.14 // indirect
174182
k8s.io/klog/v2 v2.130.1 // indirect
175183
k8s.io/kube-openapi v0.0.0-20250701173324-9bd5c66d9911 // indirect
176184
sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730 // indirect

0 commit comments

Comments
 (0)