From cd6c5a9f108f8a7b6f564b51f432cac173b55157 Mon Sep 17 00:00:00 2001 From: Qian Deng Date: Mon, 6 May 2019 18:36:33 +0800 Subject: [PATCH 1/3] Enable absolute url in helm chart assign public_url to chart-url remove namespace merge in index.yaml Signed-off-by: Qian Deng --- .../prepare/templates/chartserver/env.jinja | 2 +- make/photon/prepare/utils/chart.py | 6 ++++-- src/chartserver/handler_repo.go | 5 ++++- src/chartserver/handler_utility.go | 20 +++++++++++++++---- src/core/api/chart_repository.go | 7 ++++++- 5 files changed, 31 insertions(+), 9 deletions(-) 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) + + } } From 3022b617f2a3ed1b5ac5bfc155dd46a5db22b5d2 Mon Sep 17 00:00:00 2001 From: Qian Deng Date: Wed, 8 May 2019 12:59:44 +0800 Subject: [PATCH 2/3] Add chart absolute url item in config Add a config item to enable and disalbe chart_url Signed-off-by: Qian Deng --- make/harbor.yml | 3 +++ make/photon/prepare/templates/chartserver/env.jinja | 4 ++++ make/photon/prepare/utils/chart.py | 3 ++- make/photon/prepare/utils/configs.py | 4 ++++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/make/harbor.yml b/make/harbor.yml index 3d41187b4..36181fe07 100644 --- a/make/harbor.yml +++ b/make/harbor.yml @@ -64,6 +64,9 @@ jobservice: # Maximum number of job workers in job service max_job_workers: 10 +chart: + absolute_url: disabled + # Log configurations log: # options are debug, info, warn, error diff --git a/make/photon/prepare/templates/chartserver/env.jinja b/make/photon/prepare/templates/chartserver/env.jinja index d2a5fb9dd..e9d7f98b1 100644 --- a/make/photon/prepare/templates/chartserver/env.jinja +++ b/make/photon/prepare/templates/chartserver/env.jinja @@ -28,7 +28,11 @@ DISABLE_METRICS=false DISABLE_API=false DISABLE_STATEFILES=false ALLOW_OVERWRITE=true +{% if chart_absolute_url %} CHART_URL={{public_url}}/chartrepo +{% else %} +CHART_URL= +{% endif %} 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 f0c07c469..942cb7b35 100644 --- a/make/photon/prepare/utils/chart.py +++ b/make/photon/prepare/utils/chart.py @@ -100,4 +100,5 @@ def prepare_chartmuseum(config_dict): core_secret=config_dict['core_secret'], storage_driver=storage_driver, all_storage_driver_configs=all_storage_provider_configs, - public_url=config_dict['public_url']) \ No newline at end of file + public_url=config_dict['public_url'], + chart_absolute_url=config_dict['chart_absolute_url']) \ No newline at end of file diff --git a/make/photon/prepare/utils/configs.py b/make/photon/prepare/utils/configs.py index c0b849300..48ca7e6a8 100644 --- a/make/photon/prepare/utils/configs.py +++ b/make/photon/prepare/utils/configs.py @@ -170,6 +170,10 @@ def parse_yaml_config(config_file_path): config_dict['clair_https_proxy'] = clair_configs.get('https_proxy') or '' config_dict['clair_no_proxy'] = clair_configs.get('no_proxy') or '127.0.0.1,localhost,core,registry' + # Chart configs + chart_configs = configs.get("chart") or {} + config_dict['chart_absolute_url'] = chart_configs.get('absolute_url') or '' + # jobservice config js_config = configs.get('jobservice') or {} config_dict['max_job_workers'] = js_config["max_job_workers"] From f607c5177dc06b08c83be1d96fa4f6f44a97a35e Mon Sep 17 00:00:00 2001 From: Qian Deng Date: Wed, 8 May 2019 13:58:17 +0800 Subject: [PATCH 3/3] Fix frontend failure caused by absolute path Fix failures because front downlowd chart using relative path Signed-off-by: Qian Deng --- make/harbor.yml | 1 + make/photon/prepare/utils/chart.py | 1 - src/chartserver/handler_utility.go | 2 -- src/core/api/chart_repository.go | 6 ++---- .../src/app/project/helm-chart/helm-chart.service.ts | 10 +++++++++- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/make/harbor.yml b/make/harbor.yml index 36181fe07..a931fe783 100644 --- a/make/harbor.yml +++ b/make/harbor.yml @@ -65,6 +65,7 @@ jobservice: max_job_workers: 10 chart: + # Harbor Default will using relative url in chart, if you want using absolute url you should enable it by change the following value to disabled absolute_url: disabled # Log configurations diff --git a/make/photon/prepare/utils/chart.py b/make/photon/prepare/utils/chart.py index 942cb7b35..076b620b4 100644 --- a/make/photon/prepare/utils/chart.py +++ b/make/photon/prepare/utils/chart.py @@ -12,7 +12,6 @@ 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'] diff --git a/src/chartserver/handler_utility.go b/src/chartserver/handler_utility.go index 07aa93409..71e45ea47 100644 --- a/src/chartserver/handler_utility.go +++ b/src/chartserver/handler_utility.go @@ -218,7 +218,6 @@ 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) { - hlog.Infof("namespace: %v, subpath: %v", namespace, subPath) var url string if strings.HasPrefix(subPath, "http") { extEndpoint, err := config.ExtEndpoint() @@ -226,7 +225,6 @@ func (c *Controller) getChartVersionContent(namespace string, subPath string) ([ 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) } diff --git a/src/core/api/chart_repository.go b/src/core/api/chart_repository.go index 0712fb386..e44f65174 100644 --- a/src/core/api/chart_repository.go +++ b/src/core/api/chart_repository.go @@ -545,9 +545,7 @@ func isMultipartFormData(req *http.Request) bool { // Return the chart full name func chartFullName(namespace, chartName, version string) string { if strings.HasPrefix(chartName, "http") { - return fmt.Sprintf("%s:%s", namespace, chartName, version) - } else { - return fmt.Sprintf("%s/%s:%s", namespace, chartName, version) - + return fmt.Sprintf("%s:%s", chartName, version) } + return fmt.Sprintf("%s/%s:%s", namespace, chartName, version) } diff --git a/src/portal/src/app/project/helm-chart/helm-chart.service.ts b/src/portal/src/app/project/helm-chart/helm-chart.service.ts index 21176fbd0..572f6357b 100644 --- a/src/portal/src/app/project/helm-chart/helm-chart.service.ts +++ b/src/portal/src/app/project/helm-chart/helm-chart.service.ts @@ -178,7 +178,15 @@ export class HelmChartDefaultService extends HelmChartService { projectName: string, filename: string, ): Observable { - return this.http.get(`${this.config.downloadChartEndpoint}/${projectName}/${filename}`, { + let url: string; + let chartFileRegexPattern = new RegExp('^http.*/chartrepo/(.*)'); + if (chartFileRegexPattern.test(filename)) { + let match = filename.match('^http.*/chartrepo/(.*)'); + url = `${this.config.downloadChartEndpoint}/${match[1]}`; + } else { + url = `${this.config.downloadChartEndpoint}/${projectName}/${filename}`; + } + return this.http.get(url, { responseType: ResponseContentType.Blob, }) .pipe(map(response => {