bitnami / charts-syncer

Tool for synchronizing Helm Chart repositories.
https://bitnami.com
Apache License 2.0
174 stars 31 forks source link

Sync chart failed of target repo type is chartmuseum #173

Closed yidaqiang closed 1 year ago

yidaqiang commented 1 year ago

When I sync chart from chartmuseum to chartmuseum, Problems encountered.

log is:

Using config file: "config.yaml"
There are no charts out of sync!

I found the place where the bug occurred

https://github.com/bitnami-labs/charts-syncer/blob/6d18fc98aab230beb0aa7870b36412ee971923ba/pkg/client/repo/chartmuseum/chartmuseum.go#L59

// GetUploadURL returns the URL to upload a chart
func (r *Repo) GetUploadURL() string {
    u := *r.url
    u.Path = "/api/charts"
    return u.String()
}

Target repo url is https://chart.exmaple.com/myrepo, After execution u.Path = "/api/charts", u.Path is /api/charts, Not expected /myrepo/api/charts

So The correct code is

// GetUploadURL returns the URL to upload a chart
func (r *Repo) GetUploadURL() string {
    u := *r.url
    u.Path += "/api/charts"
    return u.String()
}

Is this appropriate, Do I need to create PR ?

jiparis commented 1 year ago

Hi @yidaqiang, thanks for reporting the issue. According to Chartmuseum docs, Charts API is exposed under /api/charts. Do you have your deployment behind a proxy or virtual host? In that case, it would make sense to prepend the virtual host name, not the whole URL.

Can you post here the relevant part of your config.yaml file?

yidaqiang commented 1 year ago

Hi @jiparis ,Thanks for your response.

Here is my config.yaml

relocateContainerImages: false
source:
  repo:
    kind: CHARTMUSEUM
    url: https://chartmuseum.server.com/serverrepo
target:
  repoName: backuprepo
  repo:
    kind: CHARTMUSEUM
    url: https://chartmuseum.backup.com/backuprepo
    auth:
      username: user
      password: password
  #containerRegistry: docker.io
  #containerRepository: yishuida
skipCharts:
 - common
 - chart-test

In Chartmuseum docs, Here is a sample command:

curl --data-binary "@mychart-0.1.0.tgz" http://localhost:8080/api/charts

But in fact, The following commands are used

curl -u username:password --data-binary "@mychart-0.1.0.tgz" http://localhost:8080/mysql-repo/api/charts
# or 
curl -u username:password --data-binary "@mychart-0.1.0.tgz" http://localhost:8080/api/mysql-repo/charts

Only use /api/charts without myrepo, chartmuseum returen { "error": "not found" }

See the link below for detailed logic

https://github.com/helm/chartmuseum/blob/a3629ef8521b1c6149c885482a87272f9b8c6b78/pkg/chartmuseum/router/match.go#L128

I fixed the problem,and rebuild docker image yishuida/charts-syncer:v0.19.0. Everything works fine when I use this image.

PS: Using your methods deploy to k8s

jiparis commented 1 year ago

Hi @yidaqiang, sorry for the late response. Yes, you are right, it looks like your approach would fix the issue. Can you please create a PR for the team to review?

Thank you for your contribution!

yidaqiang commented 1 year ago

I created PR 174, Please review it.