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

Document example for Pull via SDK #12131

Closed
ghost opened this issue Jun 9, 2023 · 5 comments
Closed

Document example for Pull via SDK #12131

ghost opened this issue Jun 9, 2023 · 5 comments

Comments

@ghost
Copy link

ghost commented Jun 9, 2023

Summary

Can someone provide an example using the SDK to perform the equivalent of helm pull to download a .tgz chart?

Background

On the command line you can pull a chart like this:

helm pull oci://registry-1.docker.io/bitnamicharts/argo-workflows

That command will download the chart argo-workflows-5.3.4.tgz to your local directory.

What I have tried

I have tried to implement the same functionality using the SDK like so:

package main

import (
	"log"
	"path/filepath"

	"helm.sh/helm/v3/pkg/action"
)

func Pull(url string) (string, error) {
	p := action.NewPull()
	p.RepoURL = url
	p.DestDir = filepath.Join(".")
	log.Printf("%+v", p)
	return p.Run("") // chartRef probably should not be empty but I'm not sure what it should be if I have already specified the url with p.RepoURL
}

func main() {
	_, err := Pull("oci://registry-1.docker.io/bitnamicharts/argo-workflows")
	if err != nil {
		log.Fatalf("%s", err.Error())
	}
}

The program errors with the following output

2023/06/09 11:27:25 &{ChartPathOptions:{CaFile: CertFile: KeyFile: InsecureSkipTLSverify:false Keyring: Password: PassCredentialsAll:false RepoURL: Username: Verify:false Version: registryClient:<nil>} Settings:<nil> Devel:false Untar:false VerifyLater:false UntarDir: DestDir:. cfg:<nil>}
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0xe0 pc=0x1016eaaae]

goroutine 1 [running]:
helm.sh/helm/v3/pkg/getter.collectPlugins(0x0)
        /Users/.../go/pkg/mod/helm.sh/helm/[email protected]/pkg/getter/plugingetter.go:34 +0x2e
helm.sh/helm/v3/pkg/getter.All(...)
        /Users/.../go/pkg/mod/helm.sh/helm/[email protected]/pkg/getter/getter.go:190
helm.sh/helm/v3/pkg/action.(*Pull).Run(0xc00018c1c0, {0x0, 0x0})
        /Users/.../go/pkg/mod/helm.sh/helm/[email protected]/pkg/action/pull.go:87 +0x152
main.Pull({0x0, 0x0})
        /Users/.../pkg/helm/helm.go:21 +0x12b
main.main()
        /Users/.../pkg/helm/helm.go:25 +0x1d
exit status 2

What is the proper way to invoke p.Run(chartRef) for a public chart?

Output

I can update some documentation in this repo based on what I learned here if maintainers think that's a good idea

@gjenkins8
Copy link
Contributor

@gjenkins8 gjenkins8 added the docs label Aug 4, 2023
@gjenkins8
Copy link
Contributor

And, yes please, a PR to docs would be good IMHO.

I'm not sure where the best place is. A PR to create something in:
https://github.com/helm/helm-www/tree/main/content/en/docs

Then we can figure out exactly where SDK examples might go from there please.

@codeReaper2001
Copy link

Summary

Can someone provide an example using the SDK to perform the equivalent of helm pull to download a .tgz chart?

Background

On the command line you can pull a chart like this:

helm pull oci://registry-1.docker.io/bitnamicharts/argo-workflows

That command will download the chart argo-workflows-5.3.4.tgz to your local directory.

What I have tried

I have tried to implement the same functionality using the SDK like so:

package main

import (
	"log"
	"path/filepath"

	"helm.sh/helm/v3/pkg/action"
)

func Pull(url string) (string, error) {
	p := action.NewPull()
	p.RepoURL = url
	p.DestDir = filepath.Join(".")
	log.Printf("%+v", p)
	return p.Run("") // chartRef probably should not be empty but I'm not sure what it should be if I have already specified the url with p.RepoURL
}

func main() {
	_, err := Pull("oci://registry-1.docker.io/bitnamicharts/argo-workflows")
	if err != nil {
		log.Fatalf("%s", err.Error())
	}
}

The program errors with the following output

2023/06/09 11:27:25 &{ChartPathOptions:{CaFile: CertFile: KeyFile: InsecureSkipTLSverify:false Keyring: Password: PassCredentialsAll:false RepoURL: Username: Verify:false Version: registryClient:<nil>} Settings:<nil> Devel:false Untar:false VerifyLater:false UntarDir: DestDir:. cfg:<nil>}
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0xe0 pc=0x1016eaaae]

goroutine 1 [running]:
helm.sh/helm/v3/pkg/getter.collectPlugins(0x0)
        /Users/.../go/pkg/mod/helm.sh/helm/[email protected]/pkg/getter/plugingetter.go:34 +0x2e
helm.sh/helm/v3/pkg/getter.All(...)
        /Users/.../go/pkg/mod/helm.sh/helm/[email protected]/pkg/getter/getter.go:190
helm.sh/helm/v3/pkg/action.(*Pull).Run(0xc00018c1c0, {0x0, 0x0})
        /Users/.../go/pkg/mod/helm.sh/helm/[email protected]/pkg/action/pull.go:87 +0x152
main.Pull({0x0, 0x0})
        /Users/.../pkg/helm/helm.go:21 +0x12b
main.main()
        /Users/.../pkg/helm/helm.go:25 +0x1d
exit status 2

What is the proper way to invoke p.Run(chartRef) for a public chart?

Output

I can update some documentation in this repo based on what I learned here if maintainers think that's a good idea

bro, try this:

settings := cli.New()

actionConfig := new(action.Configuration)
// You can pass an empty string instead of settings.Namespace() to list
// all namespaces
if err := actionConfig.Init(settings.RESTClientGetter(), "default", os.Getenv("HELM_DRIVER"), log.Printf); err != nil {
fmt.Printf("%+v", err)
os.Exit(1)
}

client := action.NewPullWithOpts(action.WithConfig(actionConfig))
// client.RepoURL = ""
client.DestDir = "./"
client.Settings = settings

result, err := client.Run("oci://registry-1.docker.io/bitnamicharts/argo-workflows")
if err != nil {
fmt.Printf("%+v", err)
os.Exit(1)
}

fmt.Println(result)

@gjenkins8
Copy link
Contributor

working on getting some SDK examples put together helm/helm-www#1543 fyi

Copy link

This issue has been marked as stale because it has been open for 90 days with no activity. This thread will be automatically closed in 30 days if no further activity occurs.

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