23andMe / Yamale

A schema and validator for YAML.
MIT License
680 stars 89 forks source link

Unable to validate list of values #56

Closed sunilkum84 closed 5 years ago

sunilkum84 commented 5 years ago

Hi,

We trying to validate list of values of spec.initContainers.resources but we are getting following error while validating list of values

Error:

root@devenv:/media/sf_test_devenv# yamale -s schema.yaml data.yaml
Validating /media/sf_test_devenv/data.yaml...

Error!
Schema: schema.yaml
Data file: /media/sf_test_devenv/data.yaml
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/yamale/command_line.py", line 29, in _validate
    yamale.validate(schema, data)
  File "/usr/local/lib/python2.7/dist-packages/yamale/yamale.py", line 39, in validate
    schema.validate(d)
  File "/usr/local/lib/python2.7/dist-packages/yamale/schema/schema.py", line 56, in validate
    raise ValueError(error_str)
ValueError:
Error validating data /media/sf_test_devenv/data.yaml with schema schema.yaml
        spec.template.spec.initContainers.0.resources.requests.cpu: Required field missing
        spec.template.spec.initContainers.0.resources.requests.memory: Required field missing
        spec.template.spec.initContainers.0.resources.limits.memory: Required field missing
        spec.template.spec.initContainers.0.resources.limits.cpu: Required field missing
        spec.template.spec.initContainers.1.resources.requests.cpu: Required field missing
        spec.template.spec.initContainers.1.resources.requests.memory: Required field missing
        spec.template.spec.initContainers.1.resources.limits.memory: Required field missing
        spec.template.spec.initContainers.1.resources.limits.cpu: Required field missing

Traceback (most recent call last):
  File "/usr/local/bin/yamale", line 11, in <module>
    load_entry_point('yamale==1.10.0', 'console_scripts', 'yamale')()
  File "/usr/local/lib/python2.7/dist-packages/yamale/command_line.py", line 112, in main
    _router(args.path, args.schema, args.cpu_num, args.parser)
  File "/usr/local/lib/python2.7/dist-packages/yamale/command_line.py", line 96, in _router
    _validate_single(root, schema_name, parser)
  File "/usr/local/lib/python2.7/dist-packages/yamale/command_line.py", line 68, in _validate_single
    _validate(s, yaml_path, parser)
  File "/usr/local/lib/python2.7/dist-packages/yamale/command_line.py", line 36, in _validate
    raise ValueError('Validation failed!')
ValueError: Validation failed!
root@devenv:/media/sf_test_devenv#

Data.yaml


##---
# Source: SampleApp/templates/deployment.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: SampleApp
  labels:
    app: SampleApp
    chart: SampleApp-0.0.0-snapshot
spec:
  replicas: 2
  selector:
    matchLabels:
      app: SampleApp
      release: RELEASE-NAME
  template:
    metadata:
      labels:
        app: SampleApp
        release: RELEASE-NAME
    spec:
      initContainers:
      - name: SampleApp-create-db
        image: "${DOCKER_NAME}/service-db-maria:0.0.18"
        imagePullPolicy: IfNotPresent
        resources:
            limits:
              cpu: 1
              memory: 512Mi
            requests:
              cpu: 50m
              memory: 128Mi

      - name: SampleApp-migrate-db
        image: "${DOCKER_REGISTRY}/SampleApp-migrate:${BUILD_VERSION}"
        resources:
            limits:
              cpu: 1
              memory: 512Mi
            requests:
              cpu: 50m
              memory: 128Mi
      containers:
        - name: SampleApp
          image: "${DOCKER_REGISTRY}/SampleApp:0.0.0-snapshot"
          imagePullPolicy: IfNotPresent
          env:
          - name: LOGGING_LEVEL
            value: "info"
          ports:
            - containerPort: 80
            - containerPort: 6060
          resources:
            limits:
              cpu: 1
              memory: 512Mi
            requests:
              cpu: 50m
              memory: 128Mi

Schema.yaml

spec: 
  template:
    spec: 
      initContainers: list(include('resourcesDefinition'))
---
resourcesDefinition:
  resources: 
    limits:
      memory: any(str(), int())
      cpu: any(str(), int())
    requests:
      cpu: any(str(), int())
      memory: any(str(), int())
mildebrandt commented 5 years ago

Thanks for the bug report. I've recreated it with a simpler example:

level1: list(include('nested_map'))
---
nested_map:
  level2:
    level3: str()
level1:
  - level2:
      level3: one
  - level2:
      level3: two