Use client.out for logging

Signed-off-by: Terry Howe <terrylhowe@gmail.com>
pull/30897/head
Terry Howe 4 months ago
parent 2bf6c2efbc
commit 58f72a2d19

@ -232,10 +232,10 @@ type (
// Added for backwards compatibility for Helm < 3.18.0 after moving to ORAS v2
// ref: https://github.com/helm/helm/issues/30873
// TODO: document that Helm 4 `registry login` does accept repositories
func stripRepository(host string) string {
func (c *Client) stripRepository(host string) string {
if idx := strings.Index(host, "/"); idx != -1 {
host = host[:idx]
fmt.Printf("WARNING: Invalid registry passed: registries must NOT include a repository. Use %q instead\n", host)
fmt.Fprintf(c.out, "WARNING: Invalid registry passed: registries must NOT include a repository. Use %q instead\n", host)
return host
}
return host
@ -244,7 +244,7 @@ func stripRepository(host string) string {
// Login logs into a registry
func (c *Client) Login(host string, options ...LoginOption) error {
// This is the lowest available point to strip the repository
host = stripRepository(host)
host = c.stripRepository(host)
for _, option := range options {
option(&loginOperation{host, c})

@ -17,6 +17,7 @@ limitations under the License.
package registry
import (
"io"
"testing"
"github.com/containerd/containerd/remotes"
@ -33,7 +34,11 @@ func TestNewClientResolverNotSupported(t *testing.T) {
}
func TestStripRepository(t *testing.T) {
assert.Equal(t, "127.0.0.1:15000", stripRepository("127.0.0.1:15000/asdf"))
assert.Equal(t, "127.0.0.1:15000", stripRepository("127.0.0.1:15000/asdf/asdf"))
assert.Equal(t, "127.0.0.1:15000", stripRepository("127.0.0.1:15000"))
client := &Client{
out: io.Discard,
}
assert.Equal(t, "127.0.0.1:15000", client.stripRepository("127.0.0.1:15000/asdf"))
assert.Equal(t, "127.0.0.1:15000", client.stripRepository("127.0.0.1:15000/asdf/asdf"))
assert.Equal(t, "127.0.0.1:15000", client.stripRepository("127.0.0.1:15000"))
}

Loading…
Cancel
Save