Skip to content

Commit 7ec39e9

Browse files
authored
feat(validations): Add early range based pattern validation (GoogleCloudPlatform#5115)
2 parents ee810cb + a14c0e4 commit 7ec39e9

17 files changed

Lines changed: 551 additions & 0 deletions

File tree

community/modules/compute/gke-nodeset/metadata.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,17 @@ ghpc:
2525
vars: [slurm_cluster_name]
2626
pattern: "^[a-z](?:[a-z0-9]{0,9})$"
2727
error_message: "'slurm_cluster_name' must contain only lowercase letters and numbers, start with a letter, and be 1-10 characters long."
28+
- validator: range
29+
inputs:
30+
vars: [network_storage]
31+
min: 1
32+
max: 1
33+
length_check: true # Validates the list's length instead of its elements.
34+
error_message: "The 'network_storage' list must contain exactly one element."
35+
- validator: range
36+
inputs:
37+
vars: [filestore_id]
38+
min: 1
39+
max: 1
40+
length_check: true # Validates the list's length instead of its elements.
41+
error_message: "The 'filestore_id' list must contain exactly one element."

community/modules/compute/mig/metadata.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,10 @@ spec:
1919
- compute.googleapis.com
2020
ghpc:
2121
inject_module_id: ghpc_module_id
22+
validators:
23+
- validator: range
24+
inputs:
25+
vars: [versions]
26+
min: 1
27+
length_check: true # Validates the list's length instead of its elements.
28+
error_message: "The 'versions' list must contain at least one version."

community/modules/compute/notebook/metadata.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,10 @@ spec:
1818
services:
1919
- notebooks.googleapis.com
2020
- storage.googleapis.com
21+
ghpc:
22+
validators:
23+
- validator: regex
24+
inputs:
25+
vars: [mount_runner.args]
26+
pattern: "^[^ ]+( [^ ]+){4}$"
27+
error_message: "The 'mount_runner.args' field must contain exactly 5 elements."

community/modules/database/slurm-cloudsql-federation/metadata.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,10 @@ spec:
1919
- bigqueryconnection.googleapis.com
2020
- sqladmin.googleapis.com
2121
- servicenetworking.googleapis.com
22+
ghpc:
23+
validators:
24+
- validator: regex
25+
inputs:
26+
vars: [network_id]
27+
pattern: "^projects/[^/]+/global/networks/[^/]+$"
28+
error_message: "The network id must be provided in the following format: projects/<project_id>/global/networks/<network_name>."
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright 2026 "Google LLC"
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
---
15+
16+
ghpc:
17+
validators:
18+
- validator: range
19+
inputs:
20+
vars: [node_count_static]
21+
min: 0
22+
error_message: "The 'node_count_static' value must be at least 0."
23+
- validator: range
24+
inputs:
25+
vars: [node_count_dynamic_max]
26+
min: 0
27+
error_message: "The 'node_count_dynamic_max' value must be at least 0."

community/modules/scheduler/htcondor-access-point/metadata.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,11 @@ spec:
1818
services:
1919
- compute.googleapis.com
2020
- storage.googleapis.com
21+
ghpc:
22+
validators:
23+
- validator: range
24+
inputs:
25+
vars: [zones]
26+
max: 2
27+
length_check: true # Validates the list's length instead of its elements.
28+
error_message: "The 'zones' list must contain at most 2 zones."

community/modules/scheduler/schedmd-slurm-gcp-v6-controller/metadata.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ spec:
2121
- storage.googleapis.com
2222
ghpc:
2323
validators:
24+
- validator: range
25+
inputs:
26+
vars: [static_ips]
27+
max: 1
28+
length_check: true # Validates the list's length instead of its elements.
29+
error_message: "The Slurm modules supports 0 or 1 static IPs on controller instance."
2430
- validator: regex
2531
inputs:
2632
vars: [slurm_cluster_name]

docs/blueprint-validation.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,23 @@ ghpc:
121121
error_message: "partition_name must be lowercase alphanumeric and max 10 characters."
122122
```
123123

124+
### Range Validator
125+
The `range` validator ensures input variables either their values or lengths fall within specified numerical minimum and/or maximum bounds. It supports validating individual numeric values, lists of numeric values, and the number of elements in a list. The optional length_check field (defaulting to false) determines whether to validate the values themselves or the length of the variable.
126+
127+
**Example definition in `metadata.yaml`:**
128+
129+
```yaml
130+
ghpc:
131+
validators:
132+
- validator: range
133+
inputs:
134+
vars: [versions]
135+
min: 1
136+
max: 8
137+
length_check: true # enables validation of the list's length rather than the individual values it contains.
138+
error_message: "The 'versions' list must contain at least one version."
139+
```
140+
124141
Unlike blueprint-level validators, these are intrinsic to the module and ensure that the module receives data in the exact format required for its internal logic to function.
125142

126143
## Skipping or Disabling Validators

modules/compute/gke-node-pool/metadata.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,13 @@ ghpc:
2525
vars: [name]
2626
pattern: "^[a-z]([-a-z0-9]{0,34}[a-z0-9])?$"
2727
error_message: "'name' must start with a lowercase letter, followed by up to 34 lowercase letters, numbers, or hyphens, and cannot end with a hyphen."
28+
- validator: range
29+
inputs:
30+
vars: [local.upgrade_settings.max_surge]
31+
min: 0
32+
error_message: "'max_surge' value must be at least 0."
33+
- validator: range
34+
inputs:
35+
vars: [local.upgrade_settings.max_unavailable]
36+
min: 0
37+
error_message: "'max_unavailable' value must be at least 0."

modules/file-system/filestore/metadata.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ spec:
2020

2121
ghpc:
2222
validators:
23+
- validator: range
24+
inputs:
25+
vars: [size_gb]
26+
min: 1024
27+
error_message: "The 'size_gb' value must be at least 1024 GiB. See https://cloud.google.com/filestore/docs/service-tiers for details."
28+
29+
- validator: regex
30+
inputs:
31+
vars: [network_id]
32+
pattern: ^projects/[^/]+/global/networks/[^/]+$
33+
error_message: "The network id must be provided in the following format: projects/<project_id>/global/networks/<network_name>."
34+
2335
- validator: allowed_enum
2436
inputs:
2537
vars: [filestore_tier]

0 commit comments

Comments
 (0)