Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add helm OCI repo fail "URL should include hostname and port only" #21374

Open
SvenGuthe opened this issue Jan 4, 2025 Discussed in #15876 · 1 comment
Open

add helm OCI repo fail "URL should include hostname and port only" #21374

SvenGuthe opened this issue Jan 4, 2025 Discussed in #15876 · 1 comment

Comments

@SvenGuthe
Copy link

Discussed in #15876

Originally posted by lovesharepc October 9, 2023
my registry server is harbor with port 1843

when use command

argocd repo add 192.168.100.150:1843  --type helm --name helm-charts --enable-oci --username admin --password Harbor12345  --insecure-skip-server-verification

get error message

FATA[0000] rpc error: code = Unknown desc = error testing repository connectivity: OCI Helm repository URL should include hostname and port only

how do I solve this ?

@SvenGuthe
Copy link
Author

I now found the line where the error is thrown:

return errors.New("OCI Helm repository URL should include hostname and port only")

argo-cd/util/helm/client.go

Lines 396 to 403 in 1a9f226

func IsHelmOciRepo(repoURL string) bool {
if repoURL == "" {
return false
}
parsed, err := url.Parse(repoURL)
// the URL parser treat hostname as either path or opaque if scheme is not specified, so hostname must be empty
return err == nil && parsed.Host == ""
}

I wrote myself a little test:

package main

import (
	"fmt"
	"net/url"
)

func IsHelmOciRepo(repoURL string) bool {
	if repoURL == "" {
		return false
	}
	parsed, err := url.Parse(repoURL)

	// the URL parser treat hostname as either path or opaque if scheme is not specified, so hostname must be empty
	return err == nil && parsed.Host == ""
}

func main() {
	fmt.Println(IsHelmOciRepo("192.168.100.150:1843"))
}

The result is false.

We should add a condition which allows pure IPs with optional Ports like

func IsHelmOciRepo(repoURL string) bool {
	if net.ParseIP(repoURL) != nil {
		return true
	}

	host, port, err := net.SplitHostPort(repoURL)

	if net.ParseIP(host) != nil {
		if p, err := strconv.Atoi(port); err == nil && p > 0 && p < 65536 {
			return true
		}
	}

	if repoURL == "" {
		return false
	}
	parsed, err := url.Parse(repoURL)

	// the URL parser treat hostname as either path or opaque if scheme is not specified, so hostname must be empty
	return err == nil && parsed.Host == ""
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants