diff --git a/pkg/registry/client.go b/pkg/registry/client.go index de7e636e1..a27559e4d 100644 --- a/pkg/registry/client.go +++ b/pkg/registry/client.go @@ -229,8 +229,23 @@ 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 { + 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) + return host + } + return host +} + // 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) + for _, option := range options { option(&loginOperation{host, c}) } diff --git a/pkg/registry/client_test.go b/pkg/registry/client_test.go index 4c5a78849..5765134ba 100644 --- a/pkg/registry/client_test.go +++ b/pkg/registry/client_test.go @@ -31,3 +31,9 @@ func TestNewClientResolverNotSupported(t *testing.T) { require.Equal(t, err, errDeprecatedRemote) assert.Nil(t, client) } + +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")) +}