Is this a BUG REPORT or FEATURE REQUEST? (choose one):
FEATURE REQUEST
I'd like to be able to depend on charts in the stable repository without having to inspect the charts' defined templates each version.
In the Helm documentation's Chart Best Practices, there is this to say about names of defined templates:
Defined templates (templates created inside a
{{ define }}directive) are globally accessible. That means that a chart and all of its subcharts will have access to all of the templates created with{{ define }}.For that reason, _all defined template names should be namespaced._
Most of the charts in the stable and incubator repositories do not follow this best practice.
As PR's are submitted and merged, I will update this issue to track progress.
Which chart:
All of them except the below 6
What happened:
What you expected to happen:
How to reproduce it (as minimally and precisely as possible):
Anything else we need to know:
-- Questions for the chart maintainers:
Are there any charts which should not be updated in this way?
Does this change break the chart's API?
Helper scripts here:
https://gist.github.com/kevinschumacher/a10162f18be905b62a02ed65d36ab2cf
cc @dhilipkumars
This is really just some grunt work, and I'm about 90% to automating it already just from doing those 4 PRs earlier. I'm willing to take on the effort as long as no one objects.
cc: @kubernetes/charts-maintainers
Thanks for the issue @kevinschumacher, if you could make your tool such that, it can be run against any chart (future PRs) to check if the definition is template "<workload>.fullname".?
I think it would be useful to add that as a port of ci job.
@kevinschumacher Thanks thats a lot of work.
Once you create a PR link that here with that entry, once the PR is merged 'check' the box.
That way it will be easier to track.
@dhilipkumars thanks for the issue formatting help.
re: running check in CI -- great idea. Will post gist later.
Just a question of logistics --
One PR per chart is preferred, right?
Do you mind if all PRs get created at once, or would you rather see them spread out over a week?
All the PRs created at once is totally okay, we could get them in all quickly,
But yes one PR per chart is safer, if you combine all the changes in one PR, then the PR might take a long time to get it.
How can a parent chart reference a dependent child chart that has the updated namespace templates?
For instance, my chart declares redis as a dependency. I want to set an environment variable in my parent chart to the redis URL with the redis hostname.
- name: REDIS_URL
value: "redis://{{ template "redis.fullname" . }}:6379/0"
This worked previously to the change but no longer does. I tried {{ template "redis.redis.fullname" . }} but that is also undefined. What is the proper syntax to reference nested templates?
@ravishivt thanks for chiming in.
https://gist.github.com/kevinschumacher/952c8e656f29a85121fd89e80c14c182
I'm using redis 0.7.1 there (which uses "fullname" and "name" templates) and your example actually fails for me.
What version of helm are you using? Perhaps it is a behavior change in the application and not the change to the redis chart?
edit: clarity
I am seeing some behavior that I didn't expect actually, but, with the redis 0.9.0 chart, you can definitely reference the subchart's defined templates named as they are (the names are global).
In here, I reference "redis.fullname" in my parent chart's NOTES.txt
https://gist.github.com/kevinschumacher/d82507ba67624b761e65c96ca2c21191
However, it seems that the variables referenced in the defined template are bound to the values of the template that's being currently rendered. If I call "redis.fullname" in my parent chart's deployment (or, NOTES.txt), I still get release-parent even though I passed in a redis.nameOverride
This is with helm 2.5.1
Yes, I believe this doesn't work quite as is expected, as the template is rendered in the context of the chart it's being called from. This means that if the template uses .Chart.Name or other such values redis.fullname would give you the same result as parent.fullname/fullname in the parent chart. This is the reason we currently define redis.fullname in the parent chart (https://github.com/kubernetes/charts/blob/master/stable/sensu/templates/_helpers.tpl#L14). Note that this helper doesn't rely on .Chart.Name and instead hardcodes the name to "redis". It isn't ideal, but this is currently how we get around this.
So, I sort of come away with this thinking a few different things.
namespacing all the defined templates doesn't really have the desired effect; it just makes it so that a subchart's defnition for a "fullname" template doesn't (silently) conflict with a parent chart's definition of a "fullname" template; but because the defined template functions are _functions, whose values are bound based on the current template/chart_ and not simply evaluated once, I can't use a subchart's defined template function as a shared value or identifier.
I can't use the nameOverride flag for what I want, either. In fact, I'm not really sure what it's for. Might be worth a docs edit. To me, it seems like I might as well just change the subchart's defined "name" template, or make my own template (as @prydonius mentioned in the sensu chart), because, I can't actually pass a subchart.nameOverride and use it in a parent template. But I think I just don't understand what it's for.
I'm now wondering if I should submit PRs reverting the changes. @dhilipkumars, @prydonius what do you guys think?
(edited: clarity)
Closed inadvertently, but above comment relevant.
@kevinschumacher IMHO reverting your changes to old way is not a good solution especially if template functions have global scope. Please see this discussion.
This might be slightly disruptive now but _(as it has been mentioned in the issue)_ we have to first fix helm create to generate proper default namespaced template functions (so that future charts are created properly)
I added the helper utils for this effort to a gist (also now linked in description)
https://gist.github.com/kevinschumacher/a10162f18be905b62a02ed65d36ab2cf
@dhilipkumars the "find_non_namespaced_template.py" script prints names of defined templates that do not start with the chart's name (uses the folder name as the chart name; it doesn't inspect the Chart.yaml file)
Can we reopen this? I don't think @unguiculus closed this intentionally.
@kevinschumacher Apologies for the delay in merging the PRs. Had i done in time you wouldnt have to re-base some of them.
I was waiting for our Helm PR to get merged. I have no idea why it is taking this much time.
In some of the charts you have updated the major and in most of them, you have updated the minor. We should be consistent. It would be great if you could update the minor version for those charts which major version was incremented.
and needless to say awesome work so far. We really appreciate your effort.
Was this inadvertently closed when #2503 was merged? That PR looks like it fixes the zetcd chart only.
Anyway, I think we potentially need three kinds of name/fullname templates::
name/fullname work now, but as noted by others above, namespacing them almost seems superfluous if they aren't defined differently. (This is good anytime you just need a name and it need not be either unique or consistently rendered.)toplevel, either as toplevel.{name,fullname}, or without the separator dot. This can be done right now by mangling .Template.BasePath in the template. (This is good when you need two references in different charts to render the same.)name/fullname-style templates. I propose sourcename as the name for this, as in foochart.sourcename.Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.
If this issue is safe to close now please do so with /close.
Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale
Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.
If this issue is safe to close now please do so with /close.
Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle rotten
/remove-lifecycle stale
Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.
Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close