Add schema validation error message
This change updates the json_to_dhall task to provides a better failure message. This change also refactors the CR spec transformation using jinja combinaison filter to be able to use the raw spec directly. Finally this change removes a copy of the spec from the local playbook by using the flat cr_spec file directly. Change-Id: I6ed5c6746f01a8a277d50bdef317e56dfde5f66d
This commit is contained in:
parent
119090208b
commit
80394811f0
@ -9,23 +9,7 @@
|
||||
meta:
|
||||
name: zuul
|
||||
namespace: default
|
||||
spec:
|
||||
executor:
|
||||
count: 1
|
||||
ssh_key:
|
||||
secretName: executor-ssh-key
|
||||
merger:
|
||||
count: 1
|
||||
scheduler:
|
||||
config:
|
||||
secretName: zuul-yaml-conf
|
||||
launcher:
|
||||
config:
|
||||
secretName: nodepool-yaml-conf
|
||||
connections:
|
||||
gits:
|
||||
- baseurl: https://opendev.org
|
||||
name: opendev.org
|
||||
spec: "{{ lookup('file', './cr_spec.yaml') | from_yaml }}"
|
||||
pre_tasks:
|
||||
- name: "Create necessary secrets"
|
||||
k8s:
|
||||
|
@ -6,3 +6,8 @@ zuul_app_path: "/opt/ansible/conf/zuul"
|
||||
# Here we use zuul_spec to get un-modified cr
|
||||
# see: https://github.com/operator-framework/operator-sdk/issues/1770
|
||||
raw_spec: "{{ vars['_operator_zuul-ci_org_zuul_spec'] | default(spec) }}"
|
||||
|
||||
# Provide sensible default for non optional attributes:
|
||||
spec_defaults:
|
||||
web: {}
|
||||
externalConfig: {}
|
||||
|
@ -24,7 +24,7 @@ def pread(args: List[str], stdin: str) -> str:
|
||||
proc = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
stdout, stderr = proc.communicate(stdin.encode('utf-8'))
|
||||
if stderr:
|
||||
raise RuntimeError("Command failed: " + stderr.decode('utf-8'))
|
||||
raise RuntimeError(stderr.decode('utf-8'))
|
||||
return stdout.decode('utf-8')
|
||||
|
||||
|
||||
@ -43,7 +43,7 @@ def ansible_main():
|
||||
try:
|
||||
module.exit_json(changed=True, result=run(p['schema'], p['json']))
|
||||
except Exception as e:
|
||||
module.fail_json(msg="Dhall expression failed:" + str(e))
|
||||
module.fail_json(msg="Dhall expression failed", error=str(e))
|
||||
|
||||
|
||||
def cli_main():
|
||||
|
@ -9,18 +9,21 @@
|
||||
schema: "({{ zuul_app_path }}/input.dhall).Input.Type"
|
||||
json: "{{ rspec | to_json }}"
|
||||
vars:
|
||||
rspec:
|
||||
name: "{{ zuul_name }}"
|
||||
merger: "{{ raw_spec['merger'] | default({}) }}"
|
||||
executor: "{{ raw_spec['executor'] | default({}) }}"
|
||||
web: "{{ raw_spec['web'] | default({}) }}"
|
||||
scheduler: "{{ raw_spec['scheduler'] | default({}) }}"
|
||||
launcher: "{{ raw_spec['launcher'] | default({}) }}"
|
||||
jobVolumes: "{{ raw_spec['jobVolumes'] | default([]) }}"
|
||||
externalConfig: "{{ raw_spec['externalConfig'] | default({}) }}"
|
||||
connections: "{{ raw_spec['connections'] | default({}) }}"
|
||||
rspec: "{{ spec_defaults | combine(raw_spec) | combine({'name': zuul_name}) }}"
|
||||
failed_when: false
|
||||
register: _cr_input
|
||||
|
||||
- name: Explain schema conversion issue
|
||||
when: _cr_input.error is defined
|
||||
fail:
|
||||
msg: |
|
||||
The provided Zuul spec is incorrect:
|
||||
|
||||
{{ _cr_input.error }}
|
||||
|
||||
Attributes starting with a `-` are expected.
|
||||
Attributes starting with a `+` were provided but not expected.
|
||||
|
||||
- name: Convert expression to kubernetes objects
|
||||
dhall_to_json:
|
||||
expression: "{{ zuul_app_path }}/resources.dhall {{ _cr_input.result }}"
|
||||
|
Loading…
x
Reference in New Issue
Block a user