0

While installing a helm chart a condition for the dependency works well as the following Chart.yaml file. But it doesn't allow to apply the condition based on the existing Kubernetes resource.

# Chart.yaml 
apiVersion: v1
name: my-chart
version: 0.3.1
appVersion: 0.4.5
description: A helm chart with dependency
dependencies:
  - name: metrics-server
    version: 2.5.0
    repository: https://artifacts.myserver.com/v1/helm
    condition: metrics-server.enabled

I did a local install of the chart (my-chart) in a namespace(default), then I try to install the same chart in another namespace(pb) I get the following error which says the resource already exists. This resource, "system:metrics-server-aggregated-reader", has been installed cluster wide as previous dependency (metrics-server). Following is the step to reproduce.

user@hostname$helm install my-chart -n default --set metrics-server.enabled=true ./my-chart
NAME: my-chart
LAST DEPLOYED: Wed Nov 25 16:22:52 2020
NAMESPACE: default
STATUS: deployed
REVISION: 1
NOTES:
My Cluster

user@hostname$helm install my-chart -n pb  --set metrics-server.enabled=true ./my-chart
Error: rendered manifests contain a resource that already exists. Unable to continue with install: ClusterRole "system:metrics-server-aggregated-reader" in namespace "" exists and cannot be imported into the current release: invalid ownership metadata; annotation validation error: key "meta.helm.sh/release-namespace" must equal "pb": current value is "default"

There is a way to modify the template inside the metrics-server chart to conditionally generate the manifest files as described in Helm Conditional Templates. In order to do this I have to modify and maintain the metrics-server chart in internal artifact which will restrict me using the most recent charts. I am looking for an approach to query the existing Kubernetes resource, "system:metrics-server-aggregated-reader", and only install the dependency chart if such resource do not exists.

  • The metrics server looks like it's cluster-level infrastructure; including it as a per-application Helm dependency might not be correct. Since things like the `ClusterRole` are global you'll need to disable it in the second installation. – David Maze Nov 21 '20 at 11:24
  • Could you provide all steps to reproduce this behavior? Your exact commands and steps. Its your local cluster or cloud environment? – PjoterS Nov 23 '20 at 11:55
  • @PjoterS The steps to reproduce the behavior has been updated and it is a local environment. – Pradeep Bista Nov 26 '20 at 00:43
  • @DavidMaze Yes the metrics server is cluster-level infrastructure. Here the goal is to avoid manual disable in the second installation if it has already been installed. Or, what would be best way to install such cluster-level infrastructure? – Pradeep Bista Nov 26 '20 at 00:49
  • Deploy it separately; don't try to include it as a dependency of an application-level chart. (What should happen if if the first installation gets uninstalled, and the second chart still needs the metrics server? If either installation gets upgraded, what should happen with the shared global component?) – David Maze Nov 26 '20 at 01:30

0 Answers0