spegel-org / spegel

Stateless cluster local OCI registry mirror.
MIT License
1.1k stars 58 forks source link

Containerd hosts config are sorted and not in the specified order #549

Open vflaux opened 1 month ago

vflaux commented 1 month ago

Spegel version

v0.0.23

Kubernetes distribution

na

Kubernetes version

na

CNI

na

Describe the bug

The order of hosts in the hosts.toml files in containerd config generated by the spegel configuration command do not preserve the order of previous config nor the order in arguments. This is due to the fact that maps marshalled with the go-toml library are sorted by key. The issue is that the order of the "hosts" table is important in containerd as hosts are tried in order of apparition in the file.

All current tests pass because it seems they take this fact into account. You can try to switch the order of mirrors in input of a test without changing the expected output. The test will still pass while it shouldn't.

phillebaba commented 1 month ago

You are right it seems like the value of the key decides the ordering of the hosts, which is why the tests would pass.

phillebaba commented 2 weeks ago

@vflaux I have thought about it and I think easiest to understand solution is to us Go templates. No need to use embeddings I prefer using a static string to keep things simple. Your initial test to show the problem should be enough to verify things are working as they should. Do you want to do this or can I?

vflaux commented 2 weeks ago

I updated https://github.com/spegel-org/spegel/pull/557 and get ride of the embedded file.