cloudfoundry-attic / bosh-init

bosh-init is a tool used to create and update the Director VM
Apache License 2.0
31 stars 33 forks source link

Template Rendering fails if `jobs.X.properties` is empty #71

Open geofffranks opened 8 years ago

geofffranks commented 8 years ago

If jobs.X.properties is empty, and properties are specified as global properties at properties, all templates fail to render, with the error

/Users/gfranks/.bosh_init/installations/75405607-60e3-4374-5184-d210368f0c72/tmp/erb-renderer806083022/erb-render.rb:11:in `merge!': no implicit conversion of nil into Hash (TypeError)
    from /Users/gfranks/.bosh_init/installations/75405607-60e3-4374-5184-d210368f0c72/tmp/erb-renderer806083022/erb-render.rb:11:in `recursive_merge!'
    from /Users/gfranks/.bosh_init/installations/75405607-60e3-4374-5184-d210368f0c72/tmp/erb-renderer806083022/erb-render.rb:31:in `initialize'
    from /Users/gfranks/.bosh_init/installations/75405607-60e3-4374-5184-d210368f0c72/tmp/erb-renderer806083022/erb-render.rb:188:in `new'
    from /Users/gfranks/.bosh_init/installations/75405607-60e3-4374-5184-d210368f0c72/tmp/erb-renderer806083022/erb-render.rb:188:in `<main>'

Adding an empty map to the job-specific properties key resolves this. This key is not required for traditional bosh deploys, so it feels like this should be allowed in bosh-init as well.

Failing manifest excerpt:

jobs:
- instances: 1
  name: bosh
  networks:
  - name: default
    static_ips:
    - 10.10.10.10
  persistent_disk_pool: bosh
  resource_pool: bosh
  templates:
  - name: postgres
    release: bosh
  - name: nats
    release: bosh
  - name: redis
    release: bosh
  - name: blobstore
    release: bosh
  - name: director
    release: bosh
  - name: health_monitor
    release: bosh
  - name: vsphere_cpi
    release: bosh-vsphere-cpi
properties:
  agent:
    mbus: nats://nats:nats-password@10.10.10.10:4222
  ... (remaining properties omitted for brevity)

Working manifest excerpt:

jobs:
- instances: 1
  name: bosh
  networks:
  - name: default
    static_ips:
    - 10.10.10.10
  persistent_disk_pool: bosh
  resource_pool: bosh
  templates:
  - name: postgres
    release: bosh
  - name: nats
    release: bosh
  - name: redis
    release: bosh
  - name: blobstore
    release: bosh
  - name: director
    release: bosh
  - name: health_monitor
    release: bosh
  - name: vsphere_cpi
    release: bosh-vsphere-cpi
  properties: {}
properties:
  agent:
    mbus: nats://nats:nats-password@10.10.10.10:4222
  ... (remaining properties omitted for brevity)
dpb587 commented 7 years ago

Just ran into this when trying to use bosh create-env to deploy a NAT box.

Also recently came up on slack, although didn't fully diagnose it to this exact issue.

voelzmo commented 7 years ago

Also ran into the same problem recently. Problem seems to be a very restrictive check in erb rendering: https://github.com/cloudfoundry/bosh-init/blob/a26a88ad318c816ac42cc63368f7ea0bc7ea40b6/templatescompiler/erbrenderer/template_evaluation_context_rb.go#L33-L37