diff --git a/make/photon/prepare/templates/chartserver/env.jinja b/make/photon/prepare/templates/chartserver/env.jinja index 1fdf2cb24..d2a5fb9dd 100644 --- a/make/photon/prepare/templates/chartserver/env.jinja +++ b/make/photon/prepare/templates/chartserver/env.jinja @@ -28,7 +28,7 @@ DISABLE_METRICS=false DISABLE_API=false DISABLE_STATEFILES=false ALLOW_OVERWRITE=true -CHART_URL= +CHART_URL={{public_url}}/chartrepo AUTH_ANONYMOUS_GET=false TLS_CERT= TLS_KEY= diff --git a/make/photon/prepare/utils/chart.py b/make/photon/prepare/utils/chart.py index 5e76b8f3c..f0c07c469 100644 --- a/make/photon/prepare/utils/chart.py +++ b/make/photon/prepare/utils/chart.py @@ -12,6 +12,7 @@ chartm_env = os.path.join(config_dir, "chartserver", "env") def prepare_chartmuseum(config_dict): core_secret = config_dict['core_secret'] + registry_custom_ca_bundle_path = config_dict['registry_custom_ca_bundle_path'] redis_host = config_dict['redis_host'] redis_port = config_dict['redis_port'] redis_password = config_dict['redis_password'] @@ -96,6 +97,7 @@ def prepare_chartmuseum(config_dict): cache_redis_addr=cache_redis_addr, cache_redis_password=cache_redis_password, cache_redis_db_index=cache_redis_db_index, - core_secret=core_secret, + core_secret=config_dict['core_secret'], storage_driver=storage_driver, - all_storage_driver_configs=all_storage_provider_configs) \ No newline at end of file + all_storage_driver_configs=all_storage_provider_configs, + public_url=config_dict['public_url']) \ No newline at end of file diff --git a/src/chartserver/handler_repo.go b/src/chartserver/handler_repo.go index 13ea46a40..390330c89 100644 --- a/src/chartserver/handler_repo.go +++ b/src/chartserver/handler_repo.go @@ -3,6 +3,7 @@ package chartserver import ( "fmt" "path" + "strings" "sync" "time" @@ -190,7 +191,9 @@ func (c *Controller) mergeIndexFile(namespace string, version.Name = nameWithNS // Currently there is only one url for index, url := range version.URLs { - version.URLs[index] = path.Join(namespace, url) + if !strings.HasPrefix(url, "http") { + version.URLs[index] = path.Join(namespace, url) + } } } diff --git a/src/chartserver/handler_utility.go b/src/chartserver/handler_utility.go index 1fa1b89a2..07aa93409 100644 --- a/src/chartserver/handler_utility.go +++ b/src/chartserver/handler_utility.go @@ -1,14 +1,16 @@ package chartserver import ( - "errors" "fmt" "path" "strings" "sync" - hlog "github.com/goharbor/harbor/src/common/utils/log" + "github.com/pkg/errors" "k8s.io/helm/cmd/helm/search" + + hlog "github.com/goharbor/harbor/src/common/utils/log" + "github.com/goharbor/harbor/src/core/config" ) const ( @@ -216,8 +218,18 @@ func (c *Controller) SearchChart(q string, namespaces []string) ([]*search.Resul // Get the content bytes of the chart version func (c *Controller) getChartVersionContent(namespace string, subPath string) ([]byte, error) { - url := path.Join(namespace, subPath) + hlog.Infof("namespace: %v, subpath: %v", namespace, subPath) + var url string + if strings.HasPrefix(subPath, "http") { + extEndpoint, err := config.ExtEndpoint() + if err != nil { + return nil, errors.Wrap(err, "can not get ext endpoint") + } + url = strings.TrimPrefix(subPath, fmt.Sprintf("%s/%s", extEndpoint, "chartrepo/")) + hlog.Infof("extendpoint: %v, trim head: %v result url: %v", extEndpoint, fmt.Sprintf("%s/%s", extEndpoint, "chartrepo"), url) + } else { + url = path.Join(namespace, subPath) + } url = fmt.Sprintf("%s/%s", c.backendServerAddress.String(), url) - return c.apiClient.GetContent(url) } diff --git a/src/core/api/chart_repository.go b/src/core/api/chart_repository.go index a3d0e522f..0712fb386 100644 --- a/src/core/api/chart_repository.go +++ b/src/core/api/chart_repository.go @@ -544,5 +544,10 @@ func isMultipartFormData(req *http.Request) bool { // Return the chart full name func chartFullName(namespace, chartName, version string) string { - return fmt.Sprintf("%s/%s:%s", namespace, chartName, version) + if strings.HasPrefix(chartName, "http") { + return fmt.Sprintf("%s:%s", namespace, chartName, version) + } else { + return fmt.Sprintf("%s/%s:%s", namespace, chartName, version) + + } }