operator-sdk failes to Initialize a new project when parent helm chart contains dependent charts
Closed this issue · 12 comments
Bug Report
While initializing a new project using a helm chart, which contains dependent charts: It fails.
Sample helm operator demonstrating the problem: https://github.com/r4rajat/operator-sdk-bug
What did you do?
Trying to initialize a New Project using operator-sdk init
on the repository mentioned above.
The Parent Helm Chart has Dependency on Grafana, which is stored in charts folder locally.
.
└── helm/
└── hello-world/
├── charts/
│ └── grafana/
│ ├── ci/
│ ├── dashboards/
│ ├── templates/
│ ├── .helmignore
│ ├── Chart.yaml
│ ├── README.md
│ └── values.yaml
├── templates/
│ ├── _helpers.tpl
│ └── deployment.yaml
├── .helmignore
├── Chart.yaml
└── values.yaml
cat ./helm/hello-world/Chart.yaml
apiVersion: v2
name: hello-world
description: A Helm chart for Kubernetes
version: 0.1.0
appVersion: "latest"
dependencies:
- name: grafana
version: 6.59.0
repository: "file://./charts/grafana"
operator-sdk init \
--project-name=hello-world-operator --plugins=helm --domain=dev \
--helm-chart=./helm/hello-world
What did you expect to see?
Successfull execution of the command
What did you see instead? Under which circumstances?
Writing kustomize manifests for you to edit...
Creating the API:
$ operator-sdk create api --helm-chart ./helm/hello-world
Writing kustomize manifests for you to edit...
Error: failed to create API: unable to scaffold with "base.helm.sdk.operatorframework.io/v1": failed to fetch chart dependencies: directory /home/user/Projects/operator-sdk-bug/helm-charts/hello-world/charts/grafana not found
...
...
...
...
FATA[0000] failed to initialize project: unable to run post-scaffold tasks of "base.helm.sdk.operatorframework.io/v1": exit status 1
Environment
Operator type:
/language helm
Kubernetes cluster type:
The type of cluster used for testing/deployment: OpenShift v4.12.25
$ operator-sdk version
operator-sdk version: "v1.31.0", commit: "e67da35ef4fff3e471a208904b2a142b27ae32b1", kubernetes version: "1.26.0", go version: "go1.19.11", GOOS: "linux", GOARCH: "amd64"
$ go version
(if language is Go)
go version go1.20.6 linux/amd64
$ kubectl version
Client Version: v1.28.0
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Server Version: v1.25.11+1485cc9
WARNING: version difference between client (1.28) and server (1.25) exceeds the supported minor version skew of +/-1
Possible Solution
Additional context
This issue was raised earlier but not resolved - #6184
Tagging others who faced the same problem (as mentioned on the other issue) - @homily707 @efiacor
Seems like a duplicate of #2942, which we triaged and found to be an issue with upstream helm libraries (that remains unresolved). Apparently, it's not that widespread.
Regardless there are a few workarounds proposed there. Do any of those work for you?
@joelanford , one of the workarounds includes using https
repository instead of local sub-charts
. But I have some customizations I've done in local sub-charts
. If I use https
repository, it over-writes my customizations
Can you do both of the following?
- Commit whatever chart dependencies you have directly into the
charts
folder of the parent chart - Do not list those dependencies at all in
Chart.yaml
@joelanford Yeah I've tried it. Now there is a different issue with this approach. If we remove the dependencies from parent chart, than the customizations we've made in sub-charts doesn't work.
I think it's meant to be working like this: https://github.com/helm/helm/blob/3a31588ad33fe3b89af5a2a54ee1d25bfe6eaa5e/pkg/chartutil/dependencies.go#L119C1-L121
the customizations we've made in sub-charts doesn't work
Can you be more specific? What kinds of customizations are being made? And what doesn't work?
@joelanford If you look at this example: https://github.com/r4rajat/operator-sdk-bug-2
we can see we don't have any dependencies in parent chart. And we have one sub chart prometheus
which has 4 other child charts alertmanager
, kube-state-metrics
, premetheus-node-exporter
and prometheus-pushgateway
. Which we could enable or disable from prometheus
's value.yaml, Which for now let's say is disabled.
If we remove the prometheus
's dependency from our hello-world
's Chart.yaml
. These modifications won't work and the child charts which we have disabled, would be installed.
You've actually run this and tested it out? In your root CR, you should be able to set spec.alertmanager.*
for the alertmanager chart's values. Not 100% positive, but I don't think templating is affected by whether the parent Chart.yaml
has dependencies explicitly listed or not.
Yes, If you try helm package helm/hello-world/
and than running helm install hello-world-0.1.0.tgz --generate-name
, it installs even disabled child charts
Perhaps the original context of this issue has run its course? It seems like leaving sub-chart directories within the parent chart's chart
directory and then removing them from the Chart.yaml
dependency list solves the issue described in the title of this issue.
Now it sounds like you may have a separate issue about how sub-charts are incorrectly enabled? Can we close this and start a new issue about that?
Sure @joelanford , I'll close this one and raise another issue.
@joelanford, I've created another issue: #6575