Repository navigation
Description
Overview
Helm2 provided support for the Release namespace {{ .Release.Namespace }} via --namespace option if the release namespace did not exist. This functionality was considered rudimentary, and there were several requests from the community captured in #3503
Helm3 took a more opinionated approach on how to handle --namespace option w/non-existing namespaces by removing support for the release namespace creation. Irrespective of the --namespace option, the {{ .Release.Namespace }} is expected to exist before installing/upgrading any helm chart that utilizes --namespace option.
By dropping support for the Release Namespace creation via --namespace option in Helm3, we also dropped any possibility to install a Helm chart with non-existent namespace! As a result, the chart authors and chart users must rely on additional, external to Helm3 tools like kubectl to
prepare (create) Release Namespace before Helm chart installation.
It is understood that --namespace option to create namespace was sub-optimal in Helm2, which prompted requests from the helm user community similar to #3503.
Proposed Change
Rather than to remove support for the Release Namespace creation altogether, we can provide accommodations for helm chart authors to create the release namespace inline during the helm chart install by allow to define release namespace Inside as a template resource. Moreover, the helm chart authors will also be able to tailor the release namespace to the needs of the applications by including all necessary labels, annotations.
Consider following template for the Release Namespace manifest.
{{- if and .Release.Namespace (.Values.createReleaseNamespace | default false) -}}
apiVersion: v1
kind: Namespace
metadata:
name: {{ .Release.Namespace }}
annotations:
my-annoation: {{ .Values.MyAnnotation }}
labels:
release: {{ .Release.Name }}
my-other-label: other-label
{{- end -}}In the example above, we chose to emulate current Helm3 chart functionality, i.e., do not create the release namespace by default.
The chart authors can decide whether or not allow multiple instances of their application to target the same namespace. For example, removing {{- if ... end -}} lines, effectively ensure that a given chart can only be installed into a newly created namespace and no two chart instances for this application can share the same namespace.
Processing and Assumptions
While the Release Namespace resource resembles other Helm template resources very closely, the processing of this resource is different.
Helm3 can perform a "special" pre-installation check to see if the Release Namespace is defined in the templates section. If it is - Helm3 will attempt to create the release namespace before recording release history, which utilizes the release namespace.
The "special" handling of the Release Namespace hs following assumptions/implications:
- The release namespace creation will be considered as a "special" functionality, i.e., since it is processed separately from the rest of the template resources (similar to crds)
- The release namespace artifact will be defined in the
templatessection, thus will be fully rendered just like any othertemplatesresource (unlike crds) - The release namespace resource will be "immutable," i.e., Helm3 will support only "Create" and "Delete" life-cycle events, and will not support "Update."
- Installing two charts that result in the resource namespace collision will be handled just like any other collision in
templatesresources.
Input Result Matrix (Helm3 Current)
Note: here and below, Namespace is synonymous to Release Namespace.
Note: in this example for simplicity we assume that all Helm chart artifacts are installed into the Release Namespace
| # | Namespace Precondition | Namespace Option | Result | Explanation |
|---|---|---|---|---|
| 1 | Does not exist | None | Success: the helm chart is successfully installed into default namespace |
The Release Namespace is neither existed, provided nor used |
| 2 | Does exist | None | Success: the helm chart is successfully installed into default namespace |
The Release Namespace exists, however, neither provided nor used |
| 3 | Does not exist | Provided | Failure: the helm chart installation failed with "namespace not found" | The Release Namespace does not exist, and Helm3 will fail to perform all operations against this namespace |
| 4 | Does exist | Provided | Success: the helm chart is successfully installed into Provided release namespace |
As expected |
Input Result Matrix (Proposed)
Same use cases as above, but this time with proposed changed and with Helm chart that includes template definition for the Release Namespace.
| # | Namespace | Namespace Option | Create Namespace Value | Result | Explanation |
|---|---|---|---|---|---|
| 1 | Does not exist | None | False | Success: the helm chart is successfully installed into default namespace |
Same as current behavior: since the Release Namespace is provided yet it neither created nor used. |
| 2 | Does exits | None | False | Success: the helm chart is successfully installed into default namespace |
Same as current behavior |
| 3.0 | Does not exist | Provided | False | Failure: the helm chart installation failed with "namespace not found" | Same as current behavior, since CreateNamespaceValue is set to false` |
| 3.1 | Does not exist | Provided | True | Success: the helm chart is installed into newly created release namespace | This is the new/proposed behavior |
| 4.0 | Does exist | Provided | False | Success: the helm chart is successfully installed into Provided release namespace |
Same as current behavior |
| 4.1 | Does exist | Provided | True | Failure: namespace collision | Not "really a new" behavior since in this case the release namespace collision is no different than any Helm2/3 existing artifacts collision errors |
Summary
The goal of this proposal is to entertain a possibility to provide Helm chart authors with functionality to define and provide support in terms of the properties when it comes down to the Release Namespace artifact.
With this proposal: Helm chart authors can allow users to:
- Install helm chart into an existing namespace (as currently supported)
- Install helm chart into a non-existing namespace (currently not supported)
while maintaining all the current Helm3 chart behaviors when it comes to storing Helm release information.
Activity
thomastaylor312 commentedon Oct 28, 2019
@ichekrygin Thanks for the detailed proposal and POC on this! Because this is a feature add (yes, it did exist in Helm 2, but was an explicit decision to remove), I have put this into the 3.1 milestone. We will come back around to this after we get through the Helm 3.0 release in a few weeks
stevebail commentedon Oct 31, 2019
Good to know support for namespace creation during helm install might be back in v3.1. Is it possible to know the background about why it is considered "sub-optimal" in helm2? namespace creation with helm2 is working fine as far as I know.
thomastaylor312 commentedon Oct 31, 2019
Sure thing @stevebail. So the tl;dr is that we wanted
helmto follow the same lines askubectland also that some users want to modify the namespace that Helm creates. Instead of trying to force everyone to do it a specific way, we leave it up to the user. See this comment for some more details: #5753 (comment)ichekrygin commentedon Oct 31, 2019
@stevebail@thomastaylor312 I had (and still have) a hard time finding "reasonable" justifications for [--namespacecreate the release namespace] functionality removal in Helm3. I understand the decision was made, i.e., what's done is done. However, I suspect manyhelmusers will find this change to be "surprising" to say the least. Thus it is super important to have a clear and transparent explanation about the decision-making process behind this issue. Unfortunately for me, all the answers provided so far fell short of reaching that goal.Focusing specifically on #5753 (comment)
tl;dr; on (#5753 (comment)) - there are two main themes:
adminlevel permissions needed for user installing helm chart--namespacecreation.I address 2. first for being the easiest. There could be multiple ways how we could have handled such requests, for example:
Helm 3.+releasesThe main point, if we decided to use the latter two, we still would preserve the existing (Helm2) functionality.
Instead, it appears Helm3's response to this issue was more in line with "NO SOOP FOR YOU!"
I.E., remove
--namespacecreation support altogetherAs for 1., I have the following concerns.
It appears that
Helm3is trying to become "more opinionated" on what helm user RBAC permissions should be. While I can understand such a notion, I don't think I agree with it. I think Helm chart authors should decide on the installer RBAC permissions level since the author is the ultimate authority in that area. For the most part, this still holds (from Helm2->Helm3), i.e., helm chart authors can include cluster level scoped artifacts in the chart template.Moreover, when it comes to CRD support, it appears
Helm3makes a decision in the opposite direction (in terms of RBAC +--namespacecreation), and now includes support for CRD provisioning, which is excellent, but at the same time very inconsistent with the part of the rationale used for--namespacecreation functionality deprecation.Final point. I think to have
Helm3as a one-stop-shop tool is a highly desirable trait.Helm3CRD support is both a welcomed addition and a step in the right direction. However,--namespacecreation removal is a step (or a few) back, in my opinion.P.S. at the end of #5753 (comment) @bacongobbler defers to @adamreese as to the authoritative source for information behind
--namespacecreate removal, so I suspect there could be other motives not covered in the comment.stevebail commentedon Oct 31, 2019
@ichekrygin
Good info.
I am definitively not an authorize source and was definitively not involved in any decision :)
I am just trying to follow where this is going.
My personal view is:
My 2 cents.
thomastaylor312 commentedon Oct 31, 2019
I'm not sure I understand the argument here. The goal behind any of these RBAC related decisions was explicitly to not be opinionated, meaning that we have no idea what kind of permissions a user may have. I don't think we can say the same for charts either, especially for charts in the stable repo.
I think you do have a point around CRD support. Perhaps we should make CRD installation opt-in instead of opt-out and namespace creation would behave the same way, but it might be too late for that.
ichekrygin commentedon Oct 31, 2019
My bad, I copied wrong GitHub user, now it is corrected.
ichekrygin commentedon Oct 31, 2019
@thomastaylor312 perhaps it is my misinterpretation of #5753 (comment):
I think the chart author is the authoritative source on what RBAC rights installing user should have, with or without the creation of
--namespace. I.E., if the helm chart contains "cluster level scoped" artifacts, the treatment of those should be no different as--namespaceartifact and inversely, the treatment of--namespacecreation should be no different from any cluster-level chart artifacts. Thus, if users w/out propper RBAC permission attempt to install a chart with--namespacecreate option, they will get the same error when they try to install a chart with the template that contains cluster-level artifacts.thomastaylor312 commentedon Oct 31, 2019
Ok, I missed one of the issues where this has sprawled across and now have a better grasp on it.
Essentially there have been several design concerns around having the namespace auto created for you that have been documented and explained by @bacongobbler and others. What it boils down to is: The scope of the
--namespaceflag has ballooned into something we cannot sustain/write a good UX for. Also, seeing askubectlrequires the exact same steps before sending a deployment (e.g. creating the namespace beforehand), this seems like the correct decision for right now.What it comes down to is that this is a design and shipping decision that we have agreed upon, but we do understand your desire and point of view. I know there are pain points here, but I think they are something that can be addressed with a plugin or feature after 3.0 comes out, so please let us know if you have ways to work around the aforementioned design concerns. We are not against the use case in any way, but we want a way to support this in a sustainable fashion.
thomastaylor312 commentedon Oct 31, 2019
Well, I just gave in and whipped up a quick plugin for it: https://github.com/thomastaylor312/helm-namespace
stevebail commentedon Oct 31, 2019
@thomastaylor312
Very good! Let me try it...
Does it mean your plugin or something equivalent will be considered for addition to 3.1?
ichekrygin commentedon Oct 31, 2019
@thomastaylor312 I think we are on the same page in terms of the timeline of the decision making.
It is the consistency (or lack thereof) what I have the gripe with, i.e., why we chose to support CRD's one way, yet, deprecate support for
--namespacefor seemingly the opposite reasons.In that spirit, CRD's could be supported via helm plugin as well, couldn't it?
27 remaining items
bacongobbler commentedon Feb 20, 2020
#7648 implements
--create-namespaceforhelm installandhelm upgrade --install. Please feel free to try it out.bacongobbler commentedon Feb 20, 2020
...Did you actually read my previous comments?
The example I provided earlier in #7473 (comment) SPECIFICALLY creates the release namespace if it isn't present. I will post the example again for posterity.
templates/namespace.yaml:
If
lookupcannot find the.Release.Namespacein the cluster, it will go ahead and create it.In other words, it accomplishes the exact same task #6795 proposes to solve, without introducing any code to Helm.
When #7648 is merged, we will have solved both cases:
lookup)Hope that clears things up.
ichekrygin commentedon Feb 20, 2020
Yes, I did and replied on the same day - #7473 (comment)
I don't mind doing this again. There must be something embarrassingly simple that I don't see.
Maybe @bacongobbler can spot it where I go wrong:
bacongobbler commentedon Feb 20, 2020
@adamreese and I paired together and discussed the implementation of
helm install. I overlooked a design decision we intentionally made in Helm 3 which prevents my example from working. We wanted to prevent the chart from managing its own namespace (such as the proposal in #6795).Here's the code where you're seeing that error occur:
helm/pkg/action/install.go
Lines 275 to 277 in d6fad6b
Put simply, before we go ahead and create the resources that the chart declared, we create a release ledger (a secret) in the release namespace to record its status. This was intentional to prevent the chart the ability to manage its own namespace.
If we allow the chart to manage its own namespace, it brings up a huge design problem: should the chart ever decide to stop tracking the release namespace, the namespace and all its objects are removed... Including the release ledger, and any other charts installed within that namespace.
Taking #6795 as an example.
templates/namespace.yaml
Great. We now have the ability to manipulate the namespace from within the chart.
But what if we remove it?
This scenario is relatively harmless, but it exposes a problem: It's too easy for the chart author to accidentally delete their own namespace (and everything within it, including the ledger). Or, in a more dangerous case, the chart author could delete OTHER user's resources, too.
Taking that same example, let's install multiple charts in the same namespace.
Now, we remove the namespace from the chart and upgrade.
Going forward, it sounds like #7648 is the only safe option we can provide here, and we should close out #6795 as something we are not planning to support as per the above examples. #7648 would restore Helm 2's old functionality (as originally requested), without introducing any major design flaws.
ichekrygin commentedon Feb 20, 2020
Sorry, @bacongobbler, is it possible to TL;DR; the comment above?
Specifically, was I wrong in my previous comments stating that the
lookupfunction does not help with the creation of non-existent{Relese.Namespace}?ichekrygin commentedon Feb 21, 2020
I have mentioned earlier (most recently) that I am not "hard set" on having to provide
{Release.Namespace}as part of the templates manifest.The only reason such functionality exists in this POC is to show one of the possible solution addressing:
This POC can be "enhanced" to not remove
{ReleaseNamespace}once created.With that said, I am totally in favor of removing this part altogether, and possibly substituting with additional options like
--releaseNamespaceAnnotation="foo=bar"and/or `--releaseNamespaceLabels", or something like that.Moreover, I will be OK, if we add neither manifest nor flags. The bare minimum ask is to restore
Helm2{ReleaseNamespace}creation functionality. I gladly modify this POC (or create a new one) that accomplishes that in code w/out any additional flags and manifest.As for
{ReleaseNamespace}clean up, my suggestion is to leave it behind and require the user to perform any additional cleanup if needed. I.E., the same way it was inHelm2or the same we treatCRD's inHelm3ichekrygin commentedon Feb 21, 2020
@bacongobbler - we can preserve
{ReleaseNamespace}even w/out any additional changes to this POC, by leveraging:helm.sh/resource-policy: keep:)ichekrygin commentedon Feb 21, 2020
Consider this as an example of ^:
ichekrygin commentedon Feb 21, 2020
On the upside, there was quite a bit of activity here! I love it.
Quickly to sum up today's activity:
lookupfunction does not help with{ReleaseNamespace}creation as expected{ReleaseNamespace}as defined in this POC.{ReleaseNamespace}removal can be avoided by adding helm annotation serving this specific purpose:helm.sh/resource-policy: keep{ReleaseNamespace}removal prevention can be handled in code (similar to creation) if we want it.mattfarina commentedon Feb 24, 2020
@bacongobbler after a little digging... you can't use the
lookupfunction to create the release namespace. The release object (a secret by default) is stored in the release namespace just prior to uploading the manifests for the chart.The specific error is in the form:
lookupcan be used for other namespace but not the release one.bacongobbler commentedon Feb 24, 2020
Agreed. That was my mistake. I failed to remember a design decision we made in Helm 3. I tried to explain that in more depth with #6794 (comment) but I was not very clear with the messaging around that. Sorry about that.
@ichekrygin after reading your follow-up comments, it's still unclear to me how #6795 is intended to restore Helm 2's functionality.
As I understand, the goal of this ticket is to find a solution that allows a user to create the namespace on-the-fly as Helm 2 worked. Right?
When we talk about roles in Helm, we often talk about two specific roles: the chart author, and the chart operator. The author is the one who writes the chart, and the operator is the one that "consumes" the chart.
In Helm 2, the namespace was not something a chart author had to provide. The role of creating the namespace was a role for the chart operator as
helm install --namespace.However, when we look at #6795, its functionality relies on the chart author to introduce a namespace as a template into the chart. The role of creating the namespace shifts to the chart author. This is a large behavioral shift in how charts are maintained and operated, including
This is why I approached this with #7648. By creating the namespace on-the-fly with a feature flag, the roles remain the same as in Helm 2: chart authors do not have to maintain the lifecycle of the namespace, and Helm can continue to assume the lifecycle management of the namespace, including design concerns such as the one described earlier when the author fails to introduce a resource policy.
If we were to consider #6795, each and every chart would have to introduce the template to use this feature. That would mean that every chart is no longer compatible with older versions of Helm (i.e. we break backwards compatibility), and every single chart would have to be updated to introduce this functionality. If I'm understanding the proposal - to restore functionality without breaking compatibility - that would seem like a non-starter.
Do you have any other thoughts you'd like to add here?
ichekrygin commentedon Feb 24, 2020
I was able to verify #7648
--create-namespacefunctionality, it looks good.Update k8s-topgun for Helm v3
rcorre commentedon Aug 22, 2024
What was the conclusion to this? I'm trying to follow the various merged/closed PRs, and I'm unclear how this was resolved. I'm trying something like the proposed change in the OP:
However, I get
Error: INSTALLATION FAILED: create: failed to create: namespaces "test" not foundwhen runninghelm install test mychart --namespace test --set createReleaseNamespace=true.Omitting the namespace from the chart completely and passing
--create-namespaceworks, but I don't see a way to label/annotate the namespace if doing that.