microsoft / fabrikate

Making GitOps with Kubernetes easier one component at a time
MIT License
37 stars 5 forks source link

Helm repository URL comparison logic does not ignore trailing slashes #303

Open haines opened 4 years ago

haines commented 4 years ago

Describe the bug:

When updating Helm chart dependencies, Fabrikate looks for existing repositories by comparing URLs using strings.EqualFold

https://github.com/microsoft/fabrikate/blob/19220cbade85c210b3edce381847d6a2c4e9d9ae/generators/helm.go#L472

This means that trailing slashes are significant, so https://kubernetes-charts.storage.googleapis.com/ is treated as a different repository to https://kubernetes-charts.storage.googleapis.com

Helm does not treat these as different repositories since 2.0.1 (https://github.com/helm/helm/pull/1603), its logic uses filepath.Clean to normalize URLs before comparison:

https://github.com/helm/helm/blob/9b42702a4bced339ff424a78ad68dd6be6e1a80a/internal/urlutil/urlutil.go#L44-L64

The knock-on impact of this is that we get sporadic failures in fab install

...
INFO requirements.yaml found at 'prometheus/helm_repos/prometheus/requirements.yaml', ensuring repositories exist on helm client 
INFO 👀  Looking for repo https://kubernetes-charts.storage.googleapis.com/ 
INFO ✏  Adding helm dependency repository 'https://kubernetes-charts.storage.googleapis.com/'
...
INFO 🚁  Updating helm chart's dependencies for chart in 'prometheus/helm_repos/prometheus' 
WARN 🚫  Updating chart dependencies failed for chart in 'prometheus/helm_repos/prometheus'; run `helm dependency update prometheus/helm_repos/prometheus` for more error details.
exit status 1: Error: repository file is out of date 

To Reproduce:

Install this component:

name: prometheus
type: helm
method: helm
source: https://kubernetes-charts.storage.googleapis.com
path: prometheus
version: 11.6.1

Expected behavior:

Fabrikate detects that the dependency uses the existing stable Helm repository, and does not add a new repository.

Desktop (please complete the following information):