helm上传charts模板404问题
故障现象
通过helm push xxx 到harbor中的时候,报错404
#helm push aaaa-www https://harbor-ceshi.aaaa.com/api/chartrepo/helm-test --username admin --password xxxx
Error: 404: <!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
...
Error: plugin "push" exited with error
故障排查
- 查看helm push文档
https://github.com/imroc/helm-push
# helm push -h
Helm plugin to push chart package to TencentHub
Examples:
$ helm push mychart-0.1.0.tgz myhubrepo # push .tgz from "helm package"
$ helm push . myhubrepo # package and push chart directory
$ helm push . --version="1.2.3" myhubrepo # override version in Chart.yaml
$ helm push . https://hub.tencentyun.com/charts/myhubrepo # push directly to chart repo URL
Usage:
helm push [flags]
Flags:
-h, --help help for helm
-p, --password string Override HTTP basic auth password [$HELM_REPO_PASSWORD]
-u, --username string Override HTTP basic auth username [$HELM_REPO_USERNAME]
-v, --version string Override chart version pre-push
helm的使用很简单。
#helm repo list
#helm push 文件或者目录 仓库名称即可
- 从上面来看,harbor里面的url请求有问题。url没有访问到。查看core的源代码,查看route源码.
https://github.com/goharbor/harbor/blob/master/src/core/router.go
可以看到chart的相关配置
// APIs for chart repository
if config.WithChartMuseum() {
// Charts are controlled under projects
chartRepositoryAPIType := &api.ChartRepositoryAPI{}
beego.Router("/api/chartrepo/health", chartRepositoryAPIType, "get:GetHealthStatus")
beego.Router("/api/chartrepo/:repo/charts", chartRepositoryAPIType, "get:ListCharts")
beego.Router("/api/chartrepo/:repo/charts/:name", chartRepositoryAPIType, "get:ListChartVersions")
beego.Router("/api/chartrepo/:repo/charts/:name", chartRepositoryAPIType, "delete:DeleteChart")
beego.Router("/api/chartrepo/:repo/charts/:name/:version", chartRepositoryAPIType, "get:GetChartVersion")
beego.Router("/api/chartrepo/:repo/charts/:name/:version", chartRepositoryAPIType, "delete:DeleteChartVersion")
beego.Router("/api/chartrepo/:repo/charts", chartRepositoryAPIType, "post:UploadChartVersion")
beego.Router("/api/chartrepo/:repo/prov", chartRepositoryAPIType, "post:UploadChartProvFile")
beego.Router("/api/chartrepo/charts", chartRepositoryAPIType, "post:UploadChartVersion")
// Repository services
beego.Router("/chartrepo/:repo/index.yaml", chartRepositoryAPIType, "get:GetIndexByRepo")
beego.Router("/chartrepo/index.yaml", chartRepositoryAPIType, "get:GetIndex")
beego.Router("/chartrepo/:repo/charts/:filename", chartRepositoryAPIType, "get:DownloadChart")
// Labels for chart
chartLabelAPIType := &api.ChartLabelAPI{}
beego.Router("/api/chartrepo/:repo/charts/:name/:version/labels", chartLabelAPIType, "get:GetLabels;post:MarkLabel")
beego.Router("/api/chartrepo/:repo/charts/:name/:version/labels/:id([0-9]+)", chartLabelAPIType, "delete:RemoveLabel")
}
确认harbor是否开启了WithChartMuseum
# docker ps | grep chartmuseum 260262d76c2d goharbor/chartmuseum-photon:v0.8.1-v1.8.1 "/docker-entrypoint.…" 2 months ago Up 2 months (healthy) 9999/tcp
查看api
这里通过源码来看我们采用repo进行push上传,不能采用/chartrepo/helm-test接口来上传。查看route,发现我们上传的接口
beego.Router("/api/chartrepo/:repo/charts", chartRepositoryAPIType, "post:UploadChartVersion")
beego.Router("/api/chartrepo/charts", chartRepositoryAPIType, "post:UploadChartVersion")
这2个接口的区别
/api/chartrepo/charts: 上传默认的charts仓库library中
/api/chartrepo/:repo/charts:上传到自定义的charts仓库中
解决
修改仓库的地址
#helm push aaaa-www https://harbor-ceshi.aaaa.com/api/chartrepo/helm-test --username admin --password xxxx
# helm push aaaa-www https://harbor-ceshi.aaaa.com/api/chartrepo/helm-test/charts --username admin --password xxxx
Pushing aaaa-www-0.1.0.tgz to https://harbor-ceshi.aaaa.com/api/chartrepo/helm-test/charts...
Done.