In this article, we will find the various cases where Helm Charts are not getting cached and their solutions.
Causes for not caching helm charts
- Helm Charts are directly fetched using the Remote repository instead of virtual.
- Virtual repository is used, but the base URL where index.yaml is stored and download URL where Charts are stored are different. And the “Chart Base URL” is not set to the download URL path.
- Chart Base URL is set, but there are multiple download URLs
Solutions
For case 1: In order for Artifactory to properly cache Helm charts, resolve the charts only through a virtual repository. That means, if we directly pull via the remote repository, it will not be cached for helm type. We need to pull via virtual repository in which the above remote repository is added. Whenever a remote repository is added to a virtual repository, it will either rewrite the URL or Charts Base URL (if specified). Hence, the index.yaml generated under virtual repository will have the download URL pointing to the Artifactory URL. Thus, when a Chart is fetched, request goes through the Artifactory and caches there.
For case 2:
While configuring a Helm remote repository, it is important to note the below:
- The repository URL should point to the root path where the index.yaml is found.
- The "Chart Base URL" should point to the path where the charts are stored.
Artifactory by default rewrites the upstream “URL” specified while generating the metadata for virtual repository. However, when the Charts are stored in a different path, and no Chart Base URL is specified, metadata won’t rewrite the download path with the Artifactory URL. Thus, Charts are fetched directly from the upstream, not via Artifactory, and hence Charts won’t get cached.
For case 3:
The issue mainly occurs when charts from the provider have more than one download URLs for its Charts. The Artifactory will either rewrite the URL or Charts Base URL (if specified). It won’t support rewriting multiple URLs. For this reason, the Charts stored in the path other than the one specified as the Charts Base URL, will not get cached.
However, in order to support such Charts, Artifactory provides a work around. You can enable external dependency in the remote Repository, and then all the dependency package requests will go through the Artifactory URL. Thus it solves the problem with the caching as well.
Sample Case
Chart: opensearch-operator
Repo : https://opster.github.io/opensearch-k8s-operator-chart/
Index.yaml : https://opensearch-project.github.io/opensearch-k8s-operator/index.yaml
From the index.yaml, you will see that Charts are stored in two different locations. The versions of the opensearch-operator from 2.1.1 are located at https://github.com/opensearch-project/opensearch-k8s-operator/ . And all the previous versions are at the location "https://github.com/opensearch-project/opensearch-k8s-operator/releases/download/".
Hence, the Helm repository should be configured as follows in the Artifactory.
URL : https://opensearch-project.github.io/opensearch-k8s-operator/ Chart Base URL : https://opensearch-project.github.io/opensearch-k8s-operator/
2. Add the new remote repository to a virtual repository, here ‘helm-release’
3. Go to UI → Application → Artifacts → <helm virtual repo name> → download index.yaml and verify whether all the external URLs are rewritten by the Artifactory URLs
4. Add the Virtual repository to the Helm client
helm repo add helm-release https://localhost:443/artifactory/api/helm/helm-release --username <username> --password <encoded_password>
helm repo update helm search repo helm-release --versions helm fetch helm-release/opensearch-operator helm fetch helm-release/opensearch-operator --version 1.0.3 (if you want to download a specific version)
Configuration Snippets Remote Repo configuration:
Index.yaml snippet:
Cached Artifacts:
Reference:
https://jfrog.com/help/r/jfrog-artifactory-documentation/kubernetes-helm-chart-repositories