canonical / juju-lint

Run checks against a juju model
GNU General Public License v3.0
0 stars 4 forks source link

juju-lint does not appear compatible with container models #285

Open Vultaire opened 6 months ago

Vultaire commented 6 months ago

Simple example. Let's say you have a model export that looks like this:

bundle: kubernetes
applications:
  metallb:
    charm: metallb
    channel: latest/stable
    revision: 16
    scale: 1
    options:
      image-registry: rocks.canonical.com:443/cdk
      iprange: 10.42.1.16-10.42.1.19
      metallb-release: v0.13.10
      namespace: metallb-system
    constraints: arch=amd64
    trust: true

This fails as follows:

2024-04-30 17:48:20 [INFO] [./metallb-system-bundle.yaml] Linting manual file...
Traceback (most recent call last):
  File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/ubuntu/juju-lint/jujulint/cli.py", line 249, in <module>
    main()
  File "/home/ubuntu/juju-lint/jujulint/cli.py", line 241, in main
    cli.audit_file(cli.manual_file, cloud_type=cli.cloud_type)
  File "/home/ubuntu/juju-lint/jujulint/cli.py", line 157, in audit_file
    linter.lint_yaml_file(filename)
  File "/home/ubuntu/juju-lint/jujulint/lint.py", line 1396, in lint_yaml_file
    return self.do_lint(parsed_yaml)
  File "/home/ubuntu/juju-lint/jujulint/lint.py", line 1405, in do_lint
    input_file = input_handler(parsed_yaml, applications)
  File "/home/ubuntu/juju-lint/jujulint/model_input.py", line 395, in input_handler
    machines_data=parsed_yaml["machines"],
KeyError: 'machines'

The same appears true for "juju status" output from container models; if I point juju-lint at juju status output for the same model, I get this error instead:

2024-04-30 17:48:21 [INFO] [./juju-status-metallb-system.yaml] Linting manual file...
Traceback (most recent call last):
  File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/ubuntu/juju-lint/jujulint/cli.py", line 249, in <module>
    main()
  File "/home/ubuntu/juju-lint/jujulint/cli.py", line 241, in main
    cli.audit_file(cli.manual_file, cloud_type=cli.cloud_type)
  File "/home/ubuntu/juju-lint/jujulint/cli.py", line 157, in audit_file
    linter.lint_yaml_file(filename)
  File "/home/ubuntu/juju-lint/jujulint/lint.py", line 1396, in lint_yaml_file
    return self.do_lint(parsed_yaml)
  File "/home/ubuntu/juju-lint/jujulint/lint.py", line 1422, in do_lint
    self.process_subordinates(parsed_yaml[applications][app], app)
  File "/home/ubuntu/juju-lint/jujulint/lint.py", line 206, in process_subordinates
    machine = app_d["units"][unit]["machine"]
KeyError: 'machine'