How should we wait for VM/container to be completely booted?

When I try to launch a VM and wait for cloud init to complete its thing this happens:

$ lxc launch images:debian/10/cloud --vm -p default -p kubernetes-host kubernetes-host;lxc exec kubernetes-host – systemctl is-system-running --wait;lxc exec kubernetes-host – cloud-init status --wait
Creating kubernetes-host
Starting kubernetes-host
Error: Failed to connect to lxd-agent
Error: Failed to connect to lxd-agent

The agent becomes available shortly after.

How should we wait for VM/container to be completely booted?

You can either retry your lxc exec or possibly look at lxc info to tell when the agent is responding.

LXD doesn’t get notified when the agent is available so there’s no way for LXD to wait for the agent to go online (or any guarantee that the agent is in fact ever going to be online, the VM may have failed to boot or may not contain the agent).