kapicorp / kapitan

Generic templated configuration management for Kubernetes, Terraform and other things
https://kapitan.dev
Apache License 2.0
1.8k stars 197 forks source link

`kapitan init` generates a project which does not compile #402

Closed jperville closed 4 years ago

jperville commented 4 years ago

Describe the bug/feature

kapitan init generates a project which does not compile.

To Reproduce Steps to reproduce the behavior:

$ mkdir xxx

$ cd xxx

$ docker run --rm -ti -u `id -u`:`id -g` -v $PWD:/src:delegated deepmind/kapitan:0.25 init   
Populated . with:
.
./inventory
./inventory/targets
     my_target.yml
./templates
./templates/scripts
     my_script.sh

$ docker run --rm -ti -u `id -u`:`id -g` -v $PWD:/src:delegated deepmind/kapitan:0.25 compile
Unknown (Non-Kapitan) Error occured
multiprocessing.pool.RemoteTraceback: 
"""
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/multiprocessing/pool.py", line 121, in worker
    result = (True, func(*args, **kwds))
  File "/opt/venv/lib/python3.7/site-packages/kapitan/targets.py", line 383, in compile_target
    input_compiler.compile_obj(comp_obj, ext_vars, **kwargs)
  File "/opt/venv/lib/python3.7/site-packages/kapitan/inputs/base.py", line 47, in compile_obj
    self.compile_input_path(input_path, comp_obj, ext_vars, **kwargs)
  File "/opt/venv/lib/python3.7/site-packages/kapitan/inputs/base.py", line 67, in compile_input_path
    target_name=target_name, **kwargs)
  File "/opt/venv/lib/python3.7/site-packages/kapitan/inputs/jsonnet.py", line 72, in compile_file
    fp.write_yaml(item_value)
  File "/opt/venv/lib/python3.7/site-packages/kapitan/inputs/base.py", line 119, in write_yaml
    yaml.dump_all(obj, stream=self.fp, indent=indent, Dumper=PrettyDumper, default_flow_style=False)
  File "/opt/venv/lib/python3.7/site-packages/yaml/__init__.py", line 277, in dump_all
    for data in documents:
TypeError: 'bool' object is not iterable
"""

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/venv/lib/python3.7/site-packages/kapitan/targets.py", line 94, in compile_targets
    [p.get() for p in pool.imap_unordered(worker, target_objs) if p]
  File "/opt/venv/lib/python3.7/site-packages/kapitan/targets.py", line 94, in <listcomp>
    [p.get() for p in pool.imap_unordered(worker, target_objs) if p]
  File "/usr/local/lib/python3.7/multiprocessing/pool.py", line 748, in next
    raise value
TypeError: 'bool' object is not iterable

'bool' object is not iterable

Expected behavior

The generated project should run kapitan compile without exception.

If it's a bug (please complete the following information):

Additional context

The error is due to kapitan init generating the components/my_component/my_component.jsonnet file with the following contents:

local kap = import "lib/kapitan.libjsonnet";
local inventory = kap.inventory();

{
  example: inventory.parameters.your_component.some_parameter
}

In the generated inventory, inventory.parameters.your_component.some_parameter has a value of true, which is not iterable indeed.

To make the compilation work, the components/my_component/my_component.jsonnet file should have contents that looks like this instead:

local kap = import "lib/kapitan.libjsonnet";
local inventory = kap.inventory();

{
  example: {
    test: inventory.parameters.your_component.some_parameter
  }
}

I prepare a PR to fix this.

ramaro commented 4 years ago

Thanks for reporting! This means that we also need test coverage for init..

uberspot commented 4 years ago

Initial fix merged. Leaving this ticket open to also add compiling to the init tests.

uberspot commented 4 years ago

Test also added here https://github.com/deepmind/kapitan/pull/420 Closing issue :)