diff --git a/controllers/helmchart_controller.go b/controllers/helmchart_controller.go index edb290e6..6ba99394 100644 --- a/controllers/helmchart_controller.go +++ b/controllers/helmchart_controller.go @@ -591,10 +591,8 @@ func (r *HelmChartReconciler) indexHelmRepositoryByURL(o runtime.Object) []strin if !ok { panic(fmt.Sprintf("Expected a HelmRepository, got %T", o)) } - if repo.Spec.URL != "" { - // TODO(hidde): move this to a dedicated function in the internal Helm package - // so it can be re-used for e.g. lookups. - u := strings.TrimRight(repo.Spec.URL, "/") + "/" + u := helm.NormalizeChartRepositoryURL(repo.Spec.URL) + if u != "" { return []string{u} } return nil diff --git a/internal/helm/utils.go b/internal/helm/utils.go new file mode 100644 index 00000000..884354ab --- /dev/null +++ b/internal/helm/utils.go @@ -0,0 +1,27 @@ +/* +Copyright 2020 The Flux CD contributors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package helm + +import "strings" + +// NormalizeChartRepositoryURL ensures repository urls are normalized +func NormalizeChartRepositoryURL(url string) string { + if url != "" { + return strings.TrimRight(url, "/") + "/" + } + return url +}