英文:
Helm SDK download chart from extenanl repository
问题
我需要下载位于外部 OCI 存储库中的图表。当我点击图表链接并提供版本、用户名和密码进行下载时,它可以正常工作。但是使用以下代码时就不行了,我尝试了以下代码并出现了错误:
无法下载 "https://fdr.cdn.repositories.amp/artifactory/control-1.0.0.tgz" 版本为 "1.0.0" 的图表(提示:运行 helm repo update
可能会有帮助)。如果我在上面的链接上点击,它会在浏览器中要求输入用户名和密码,当我提供了用户名和密码(与代码中相同)后,图表就会被下载。有任何想法为什么代码不起作用吗?
这是我尝试的代码:
package main
import (
"fmt"
"os"
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/cli"
"helm.sh/helm/v3/pkg/repo"
)
var config *cli.EnvSettings
func main() {
config = cli.New()
re := repo.Entry{
Name: "control",
URL: "https://fdr.cdn.repositories.amp/artifactory/control",
Username: "myuser",
Password: "mypass",
}
file, err := repo.LoadFile(config.RepositoryConfig)
if err != nil {
fmt.Println(err.Error())
}
file.Update(&re)
file.WriteFile(config.RepositoryConfig, os.ModeAppend)
co := action.ChartPathOptions{
InsecureSkipTLSverify: false,
RepoURL: "https://fdr.cdn.repositories.amp/artifactory/control",
Username: "myuser",
Password: "mypass",
Version: "1.0.0",
}
fp, err := co.LocateChart("control", config)
if err != nil {
fmt.Println(err.Error())
}
fmt.Println(fp)
}
在调试代码时,我发现错误来自于 https://github.com/helm/helm/blob/release-3.6/pkg/downloader/chart_downloader.go#L352,它试图查找一些在我的笔记本电脑上不存在的缓存。我该如何禁用它或找到其他解决方案使其工作?
英文:
I need to download chart which is located external OCI repository, when I download it using click on the link of the chart and version and provide user and password it works but not with the following code, this is what I tried and get an error
failed to download "https://fdr.cdn.repositories.amp/artifactory/control-1.0.0.tgz" at version "1.0.0" (hint: running helm repo update
may help) , if I click on the above link it asks for user and pass (in the browser) and when I provide it (the same in the code) the chart is downloaded, any idea why with the code its not working?
This is what I tried
package main
import (
"fmt"
"os"
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/cli"
"helm.sh/helm/v3/pkg/repo"
)
var config *cli.EnvSettings
func main() {
config = cli.New()
re := repo.Entry{
Name: "control",
URL: "https://fdr.cdn.repositories.amp/artifactory/control",
Username: "myuser",
Password: "mypass",
}
file, err := repo.LoadFile(config.RepositoryConfig)
if err != nil {
fmt.Println(err.Error())
}
file.Update(&re)
file.WriteFile(config.RepositoryConfig, os.ModeAppend)
co := action.ChartPathOptions{
InsecureSkipTLSverify: false,
RepoURL: "https://fdr.cdn.repositories.amp/artifactory/control",
Username: "myuser",
Password: "mypass",
Version: "1.0.0",
}
fp, err := co.LocateChart("control", config)
if err != nil {
fmt.Println(err.Error())
}
fmt.Println(fp)
}
While debug the code I found where the error is coming from https://github.com/helm/helm/blob/release-3.6/pkg/downloader/chart_downloader.go#L352
it trying to find some cache which doesn't exist in my laptop, how could I disable it or some other solution to make it work?
答案1
得分: 1
我认为在定位图表之前,你需要更新你的代码库。
这个链接是CLI用来更新代码库的代码。
而这个链接是执行代码库更新的函数。
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论