Helps keep yaml file schemas aligned
python yaml-validator/main.py -v yamls/example-values.yaml -r yamls/example-rules.yaml
required: // field must exist and type must match
env: str
enabled: bool
replicas: int
db:
name: str
test1:
user: str
optional: // if field exists type must match
disk: str
metrics: bool
network:
service:
port: 8060
enabled: true
image:
app: my-app:build
replicas: 1
env: dev
disk: local
db:
name: "my_db"
app:
user:
vault:
enabled: "true"
test1:
user: "user2"
password: "abc"
resources:
requests:
memory: "300M"
limits:
memory: "400M"
Example output:
---Checking required fields---
SUCCESS: Field env exists and is correct type
SUCCESS: Field enabled exists and is correct type
SUCCESS: Field replicas exists and is correct type
SUCCESS: Field db.name exists and is correct type
SUCCESS: Field db.test1.user exists and is correct type
---Checking optional fields---
SUCCESS: Field disk exists and is correct type
Field metrics does not exist -- optional
Enforcing yaml structure - fields cannot exist if it doesn't have a rule:
# add enforce flag -e
python yaml-validator/main.py -v yamls/example-values.yaml -r yamls/example-rules.yaml -e
Example output:
---Checking fields exist---
FAILED: Rule for field network doesn't exist
SUCCESS: Rule for field enabled exists
FAILED: Rule for field image doesn't exist
SUCCESS: Rule for field replicas exists
SUCCESS: Rule for field env exists
SUCCESS: Rule for field disk exists
SUCCESS: Rule for field db.name exists
FAILED: Rule for field db.app doesn't exist
SUCCESS: Rule for field db.test1.user exists
FAILED: Rule for field db.test1.password doesn't exist
FAILED: Rule for field resources doesn't exist