Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor splitDockerDomain to include more documentation
The splitDockerDomain attempts to determine whether the given name contains a domain, or should be used as a "remote-name". The logic used in doing so is based on (legacy) conventions, which have not always been properly documented. The logic used in this function was also optimized for "brevity", but not easy to ready, due to the combination of multiple boolean conditions combined on a single line, and some "double negatives". More documentation may still be needed, but let's start with documenting the logic used in this function; - Use `strings.Cut()` instead of `strings.IndexRune()`, which allows us to use descriptive variable names, and prevents use of the magic `-1` value. - Split the conditions into a switch, so that each of them can be documented separately. While this makes the code more verbose (and introduces some duplication), it should not impact performance, as only one condition would ever be met (performance may even be better, as the old code combined multiple conditions with `&&`). - Introduce a fast-path for single-element ("familiar") names. These names can be canonicalized early, without doing further handling. While working on the code, I also discovered an existing bug (or omission) where the code would not handle bare _domain names_. Ironically, the TestParseDockerRef test has a test-case name "hostname only", but which does not cover that case. THat test-case was transferred from containerd/cri, and does not describe this scenario (possibly was left as a "further exercise"); containerd/cri@25fdf72 Let keep it as a further exercise, but add a "TODO" to remind us doing so. Signed-off-by: Sebastiaan van Stijn <[email protected]>
- Loading branch information