karmab / kcli

Management tool for libvirt/aws/gcp/kubevirt/openstack/ovirt/vsphere/packet
https://kcli.readthedocs.io/en/latest/
Apache License 2.0
471 stars 133 forks source link

Cannot create dns entries for a VM with the same name than the VM in a plan #696

Closed palonsoro closed 2 days ago

palonsoro commented 6 days ago

Use case:

Problem:

Possible solutions:

karmab commented 5 days ago

I think I actually fixed it in https://github.com/karmab/kcli/commit/663f26dea122e15e0aee42ca86a7fcdb2a384fd4 when realizing today that it was legit to reserve a dns entry for a non started vm as long as an ip was provided

karmab commented 5 days ago

regarding the way a plan is handled, I dont have a good solution for that, it's just the way yaml is parsed and I think any "hack" would make the plan more complex to understand

palonsoro commented 5 days ago

Why not just adding an alt_name field that overrides the name of the created plan item?

karmab commented 4 days ago

it's not possible because the behaviour or pyyaml with duplicate keys is to override the corresponding entry with the last key. furthermore, yaml spec indicates that keys shouldnt be duplicated in a yaml file so I m thinking that instead I should throw an error with duplicates

palonsoro commented 4 days ago

I don't mean that.

For example, let's have a look at this snippet:

myvm-vm:
  alt_name: myvm # This parameter causes the VM to have "myvm" name and the key is ignored
  cpus: 2
  memory: 8192
  ...

myvm-dns:
  type: dns
  alt_name: myvm # This parameter causes the VM to have "myvm" name and the key is ignored
  ip: 192.168.192.34

The idea is to introduce an alt_name parameter that defines the name of the item to be created and makes the key to be ignored, such that in the snippet above, both the VM and the DNS entry have myvm name and the myvm-vm and myvm-dns keys are ignored (they just need to be different to avoid the collision, but they can be anything because name is defined in alt_name and not in the key).

To ensure backwards compatibility, alt_name should be optional and fail back to the key if absent (i.e. to the current behavior)

karmab commented 4 days ago

I need to do a bit of testing but I believe https://github.com/karmab/kcli/pull/698 should address this. It will:

palonsoro commented 2 days ago

Ok, so basically when #698 is merged, having more than one key equal of different type would be acceptable, right? I just hope it is not problematic with the YAML parser...

karmab commented 2 days ago

It's merged already and works as expected but I hope you can confirm

palonsoro commented 2 days ago

Confirmed that it works now as expected even when using jinja templating. Thanks!