bcgov / cas-pipeline

A collection of make functions used to compose pipelines
Apache License 2.0
0 stars 0 forks source link

oc_validate should error if a parameter that is used is not defined in the parameters array #4

Open matthieu-foucault opened 5 years ago

matthieu-foucault commented 5 years ago

For instance, the following template currently passes oc_validate, but it should fail as the ${FOO} parameter is undefined:

apiVersion: template.openshift.io/v1
kind: Template

objects:
- apiVersion: image.openshift.io/v1
  kind: ImageStream
  metadata:
    name: ${FOO}
  spec:
    lookupPolicy:
      local: true
wenzowski commented 5 years ago

It sounds like we should add a check to the lint macro that does something along the lines of an array equality check between

oc process --parameters -f template.yml | awk 'NR>1 { print $1 }' | sort | uniq

and

awk 'match($0, /\$\{.+\}/) { print substr($0, RSTART+2, RLENGTH-3) }' template.yml | sort | uniq

since the oc cli doesn't actually check if templates are well-formed, and since we are currently validating the configured templates for schema conformance after interpolation so we don't discover template errors like this.

wenzowski commented 5 years ago

We could also consider adding yamllint as a preflight check to see if the template file is well-formed, though that wouldn't directly solve for this specific use case.