fix(detect.go): check default location only after distro-specific #264
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Describe your changes
This PR was created to address the following issue:
Context
There may be scenarios where both a default containerd file exists (eg at
/etc/containerd/config.toml
) as well as a K8s-distro specific location (eg at/etc/k0s/containerd.toml
for K0s). A common example case is installing a specific K8s distro directly on to a host (VM or otherwise) that already has the system containerd installed.Issue
In the original distro detection logic, a map is used to see if a containerd config exists at a known/supported location; if it does, the distro is determined accordingly. However, maps in Golang are unordered. This means the default config may be returned prior to recognizing that there is a distro-specific config also on the host (eg K0s, MicroK8s, etc).
Proposed solution
In this PR, I've split out the default location into its own const, leaving the map to contain only distro-specific locations. We perform a lookup in this distro-specific map and if we fail to find a config with these choices, we finally try the default location.
Alternate
I'm open to alternate approaches. Use of a third-party ordered map didn't look as nice (more code/setup). We could also iterate over a slice, which is ordered/deterministic, but again would require a bit more code (at least another data structure).
Issue ticket number and link
Checklist before requesting a review