Container name isn't a valid hostname

I’ve hit a bit of snag in implementing CRI for LXD. When running the validation suite more than half the tests are failing with

Container name isn't a valid hostname.

This is because the names that validation suite generates are >64 characters. Because the name isn’t really a name, but more an ID…

To quote the Kubernetes docs on that matter:

By convention, the names of Kubernetes resources should be up to maximum length of 253 characters and consist of lower case alphanumeric characters, -, and ., but certain resources have more specific restrictions.

so now i’m wondering if there’s any sensible way to do this. Especially since lxc itself does not seem to automatically set the container name as hostname.

As far as the LXD API is concerned, I know i can store the id as Config[""] — but there’s no easy way to retrieve this, which makes operations (that require reverse-mapping) such as ContainerState(<name NOT id>) tricky.

No easy way around this as the container’s name is its UTSNAME which comes with those restrictions.

Your best bet is indeed to use something like cri-UUID as the container names and then store the full id in a user config key. I’d then recommend keeping an in-memory map of the id and container name to make things faster and easier in your code. On startup, you can run GetContainers() to populate that map.

1 Like

hmmm… i’m wondering now what else i could cache in-memory on startup to make lookups faster…