Sebastiaan van Stijn 89ee7ec63e 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");
https://github.com/containerd/cri/commit/25fdf726923b607d0155550c5e85a911bb04bad1

Let keep it as a further exercise, but add a "TODO" to remind us doing so.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-09-02 12:48:32 +02:00
2023-08-02 18:16:54 +01:00
2023-08-31 10:34:21 +01:00
2021-06-15 13:29:58 -07:00
2023-08-31 10:34:21 +01:00
2014-12-22 15:49:26 -08:00
2023-08-31 13:59:39 +02:00
2022-12-22 14:50:50 -08:00
2023-08-31 10:34:21 +01:00

Distribution reference

Go library to handle references to container images.

Build Status GoDoc License: Apache-2.0 codecov FOSSA Status

This repository contains a library for handling refrences to container images held in container registries. Please see godoc for details.

Contribution

Please see CONTRIBUTING.md for details on how to contribute issues, fixes, and patches to this project.

Communication

For async communication and long running discussions please use issues and pull requests on the github repo. This will be the best place to discuss design and implementation.

For sync communication we have a #distribution channel in the CNCF Slack that everyone is welcome to join and chat about development.

Licenses

The distribution codebase is released under the Apache 2.0 license.

Languages
Go 99.2%
Makefile 0.8%