OpenNebula / one-apps

Toolchain to build OpenNebula appliances
Apache License 2.0
12 stars 13 forks source link

Add basic cloud-init userdata primitives to one-context #129

Closed sk4zuzu closed 1 week ago

sk4zuzu commented 1 month ago

Because of the cluster-api implementation for OpenNebula we found ourselves in a need to parse cloud-init compatible user-data structure in one-context (linux).

For now the requirement is to support basic yaml structure like the following:

#cloud-config
write_files:
-   path: /run/cluster-api/placeholder
    owner: root:root
    permissions: '0640'
    content: "This placeholder file is used to create the /run/cluster-api sub directory in a way that is compatible with both Linux and Windows (mkdir -p /run/cluster-api does not work with Windows)"
runcmd:
  - 'kubeadm init --config /run/kubeadm/kubeadm.yaml  && echo success > /run/cluster-api/bootstrap-success.complete'
  - "set -e; if test -d /etc/kubernetes/super-admin.conf; then\n\n   mv /etc/kubernetes/manifests/kube-vip.yaml /var/tmp/;\n   sleep 1;\n   rmdir /etc/kubernetes/super-admin.conf/ || true;\n   kubeadm init phase kubeconfig super-admin || true;\n   mv /var/tmp/kube-vip.yaml /etc/kubernetes/manifests/; fi"
  1. Fully implemented write_files: and runcmd: is something we need to progress with cluster API, one-context (linux) has to decode and parse the userdata, then create files and run commands.
  2. This solution https://github.com/canonical/cloud-init/blob/197409efda9e7f6feec1d6a85f7a6b2ad7ad1ec5/cloudinit/sources/DataSourceOpenNebula.py#L465-L480 for passing the yaml userdata in the VM context seems reasonable.
  3. An example config in a running VM in OpenNebula would look like:
    CONTEXT = [
      USER_DATA = "<some base64 string here>",
      USER_DATA_ENCODING = "base64"
    ]
  4. For parsing the yaml itself ruby can be used as it's assumed to be available.