Skip to content

Commit a53bf82

Browse files
authored
Adopt CRD native validation (#2951)
* Adopt CRD native validation: WasmPlugin * fix banner * Hide confusing errors
1 parent 6d61c89 commit a53bf82

File tree

15 files changed

+1004
-149
lines changed

15 files changed

+1004
-149
lines changed

Makefile.core.mk

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,16 @@ local-lint-protos:
109109
lint: lint-dockerfiles lint-scripts lint-yaml lint-helm lint-copyright-banner lint-go lint-python lint-markdown lint-sass lint-typescript lint-licenses local-lint-protos
110110
@$(htmlproofer) . --url-swap "istio.io:preliminary.istio.io" --assume-extension --check-html --check-external-hash --check-opengraph --timeframe 2d --storage-dir $(repo_dir)/.htmlproofer --url-ignore "/localhost/"
111111

112+
test:
113+
(pushd tests && go test -v ./...)
114+
112115
fmt: format-python
113116

114117
#####################
115118
# CI System
116119
#####################
117120

118-
presubmit: proto-commit lint
121+
presubmit: proto-commit lint test
119122
postsubmit: presubmit
120123

121124
#####################

extensions/v1alpha1/wasm.pb.go

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

extensions/v1alpha1/wasm.pb.html

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

extensions/v1alpha1/wasm.proto

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ syntax = "proto3";
1717
import "google/protobuf/wrappers.proto";
1818
import "google/protobuf/struct.proto";
1919
import "type/v1beta1/selector.proto";
20+
import "google/api/field_behavior.proto";
2021

2122
// $schema: istio.extensions.v1alpha1.WasmPlugin
2223
// $title: Wasm Plugin
@@ -218,6 +219,7 @@ option go_package="istio.io/api/extensions/v1alpha1";
218219
// +cue-gen:WasmPlugin:annotations:helm.sh/resource-policy=keep
219220
// +cue-gen:WasmPlugin:labels:app=istio-pilot,chart=istio,heritage=Tiller,release=istio
220221
// +cue-gen:WasmPlugin:subresource:status
222+
// +cue-gen:WasmPlugin:spec:required
221223
// +cue-gen:WasmPlugin:scope:Namespaced
222224
// +cue-gen:WasmPlugin:resource:categories=istio-io,extensions-istio-io
223225
// +cue-gen:WasmPlugin:preserveUnknownFields:pluginConfig
@@ -261,13 +263,16 @@ message WasmPlugin {
261263
// are `file://` for referencing .wasm module files present locally
262264
// within the proxy container, and `http[s]://` for .wasm module files
263265
// hosted remotely.
264-
string url = 2;
266+
// +kubebuilder:validation:MinLength=1
267+
// +kubebuilder:validation:XValidation:message="url must have schema one of [http, https, file, oci]",rule="isURL(self) ? (url(self).getScheme() in ['', 'http', 'https', 'oci', 'file']) : (isURL('http://' + self) && url('http://' +self).getScheme() in ['', 'http', 'https', 'oci', 'file'])"
268+
string url = 2 [(google.api.field_behavior) = REQUIRED];
265269

266270
// SHA256 checksum that will be used to verify Wasm module or OCI container.
267271
// If the `url` field already references a SHA256 (using the `@sha256:`
268272
// notation), it must match the value of this field. If an OCI image is
269273
// referenced by tag and this field is set, its checksum will be verified
270274
// against the contents of this field after pulling.
275+
// +kubebuilder:validation:Pattern="(^$|^[a-f0-9]{64}$)"
271276
string sha256 = 3;
272277

273278
// The pull behaviour to be applied when fetching Wasm module by either
@@ -282,6 +287,8 @@ message WasmPlugin {
282287
// Name of a K8s Secret in the same namespace as the `WasmPlugin` that
283288
// contains a docker pull secret which is to be used to authenticate
284289
// against the registry when pulling the image.
290+
// +kubebuilder:validation:MinLength=1
291+
// +kubebuilder:validation:MaxLength=253
285292
string image_pull_secret = 5;
286293

287294
// $hide_from_docs
@@ -312,6 +319,8 @@ message WasmPlugin {
312319
// The plugin name to be used in the Envoy configuration (used to be called
313320
// `rootID`). Some .wasm modules might require this value to select the Wasm
314321
// plugin to execute.
322+
// +kubebuilder:validation:MaxLength=256
323+
// +kubebuilder:validation:MinLength=1
315324
string plugin_name = 8;
316325

317326
// Determines where in the filter chain this `WasmPlugin` is to be injected.
@@ -351,6 +360,8 @@ message WasmPlugin {
351360
//
352361
// If one of the given `ports` is matched, this condition is evaluated to true.
353362
// If not specified, this condition is evaluated to true for any port.
363+
// +listType=map
364+
// +listMapKey=number
354365
repeated istio.type.v1beta1.PortSelector ports = 2;
355366
}
356367

@@ -427,21 +438,27 @@ enum PullPolicy {
427438
message VmConfig {
428439
// Specifies environment variables to be injected to this VM.
429440
// Note that if a key does not exist, it will be ignored.
441+
// +kubebuilder:validation:MaxItems=256
442+
// +listType=map
443+
// +listMapKey=name
430444
repeated EnvVar env = 1;
431445
}
432446

447+
// +kubebuilder:validation:XValidation:message="value may only be set when valueFrom is INLINE",rule="(has(self.valueFrom) ? self.valueFrom : '') != 'HOST' || !has(self.value)"
433448
message EnvVar {
434-
// Required
435-
// Name of the environment variable. Must be a C_IDENTIFIER.
436-
string name = 1;
449+
// Name of the environment variable.
450+
// Must be a C_IDENTIFIER.
451+
// +kubebuilder:validation:MaxLength=256
452+
// +kubebuilder:validation:MinLength=1
453+
string name = 1 [(google.api.field_behavior) = REQUIRED];
437454

438-
// Required
439455
// Source for the environment variable's value.
440456
EnvValueSource value_from = 3;
441457

442458
// Value for the environment variable.
443-
// Note that if `value_from` is `HOST`, it will be ignored.
459+
// Only applicable if `valueFrom` is `HOST`.
444460
// Defaults to "".
461+
// +kubebuilder:validation:MaxLength=2048
445462
string value = 2;
446463
}
447464

kubernetes/customresourcedefinitions.gen.yaml

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

proto.lock

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36547,7 +36547,13 @@
3654736547
{
3654836548
"id": 2,
3654936549
"name": "url",
36550-
"type": "string"
36550+
"type": "string",
36551+
"options": [
36552+
{
36553+
"name": "(google.api.field_behavior)",
36554+
"value": "REQUIRED"
36555+
}
36556+
]
3655136557
},
3655236558
{
3655336559
"id": 3,
@@ -36647,7 +36653,13 @@
3664736653
{
3664836654
"id": 1,
3664936655
"name": "name",
36650-
"type": "string"
36656+
"type": "string",
36657+
"options": [
36658+
{
36659+
"name": "(google.api.field_behavior)",
36660+
"value": "REQUIRED"
36661+
}
36662+
]
3665136663
},
3665236664
{
3665336665
"id": 3,
@@ -36671,6 +36683,9 @@
3667136683
},
3667236684
{
3667336685
"path": "type/v1beta1/selector.proto"
36686+
},
36687+
{
36688+
"path": "google/api/field_behavior.proto"
3667436689
}
3667536690
],
3667636691
"package": {
@@ -48247,7 +48262,13 @@
4824748262
{
4824848263
"id": 1,
4824948264
"name": "number",
48250-
"type": "uint32"
48265+
"type": "uint32",
48266+
"options": [
48267+
{
48268+
"name": "(google.api.field_behavior)",
48269+
"value": "REQUIRED"
48270+
}
48271+
]
4825148272
}
4825248273
]
4825348274
},
@@ -48277,6 +48298,11 @@
4827748298
]
4827848299
}
4827948300
],
48301+
"imports": [
48302+
{
48303+
"path": "google/api/field_behavior.proto"
48304+
}
48305+
],
4828048306
"package": {
4828148307
"name": "istio.type.v1beta1"
4828248308
},

0 commit comments

Comments
 (0)