Repository navigation
Description
EDIT: This has been superseded by another idea
Problem
Many users want to be able to "adopt" currently running pods, services, etc. into a new or existing chart. One example of this is self-hosted Kubernetes control plane components (apiserver, DNS, etc.) after they have been bootstrapped by something like bootkube.
Proposed solution
I propose we add a new commandeer (to stick with a naval theme, we can go with adopt if people find it too confusing) subcommand to Helm. The reason behind this is we don't want to add additional complexity and flags to an already large flag set on install, update, and rollback. The command would take a defined chart (e.g. helm commandeer <chart_name>) with matching manifests and use these to "commandeer" the objects into a chart manifest. Future iterations of the feature could add the ability to pass specific names of resources you want to commandeer.
Behavior
The passed chart would be rendered like a normal install or upgrade before moving on to a "capture" step. The "capture" step would use the object GroupVersionKind, namespace, and name to find a match in the already existing objects. For safety sake, if any of the rendered manifests do not exactly match a resource, the "capture" step will fail. There will also be an --override flag and an --ignore-match flag to help configure this behavior. The --override flag will make it so as long as the Kind and name match, it will accept the match. The --ignore-match flag will drop any non-matching manifest from the final chart.
The last step will be a merge patch of the new manifest with the existing one. Once these are merged and sent to the API, the new chart will be saved into storage. So the tl;dr is below
- Render chart
- Capture resources using
GroupVersionKind, namespace, and name - Merge manifests
- Save new chart
The --into flag
We also want to have the ability to adopt resources into a currently installed chart (e.g. bringing resources into an umbrella chart). This will be done with the --into flag, which will take a release name as an argument. All of the same steps will be followed to adopt resources with the exception that existing resource will remain the same. This is a purely additive operation
Open questions
- Should the
--overrideflag force resources in the chart that don't have a match to be created anyway? - Is
--ignore-matchsomething people will actually use? - Do we need something like a
--replaceflag where the new manifest completely replaces the existing one? - Is this too complex for a first pass and should we just stick with specifying resource names to commandeer?
Other notes
I will update this proposal with suggestions from the comments so as to not have multiple proposal versions clogging up the issue
Activity
nebril commentedon Jul 27, 2017
How will
commandeerknow which resources it would group? E.g. I have wordpress deployed, in the way the chart would deploy it - mariadb and wordpress deployments with some pvcs. I also have other mariadb deployments in a cluster. How willcommandeerknow which mariadb to put in a release?seh commentedon Jul 27, 2017
When you say "exactly match a resource," we need to be careful to distinguish between facets not specified in the chart, and those the chart mandates not be present. For example, most manifests won't specify any "status"-related details, nor various annotations contributed by system facilities. I assume that you want to match the following on most objects:
You'd want to ignore most of them not mentioned in the chart, right?
Beyond that, would you tolerate whatever happens to be there on an existing object?
technosophos commentedon Jul 27, 2017
First off, I think this is a great feature, and I personally love the name "commandeer" (though maybe "adopt" is a little more consistent and easier for people like me to spell).
I am duty bound to ask the question I am notorious for: Should this be a plugin? 😄
Okay, with that out of the way....
Here's a different way we could approach the same issue. What if we generated the chart from the existing resources? I imagine it would work something like this:
(syntax above could definitely be improved)
From there, the user would have a
myNewChartchart to work with to manage that resource, and also a release record for the current chart. Going forward, the user could:myNewChart/templatesand turn them into templateshelm upgradeto fully transform the releaseI think this idea is sorta backwards from yours, so maybe it's too far off. I'm trying to figure out what the user's use-case looks like. Is it that they already have a chart that describes the existing stuff? Or is it that they want to take an existing thing and helmify it?
@devth , who once proposed doing something like this, might also have some ideas.
In any event, I like the proposal, and I know there are many who would benefit from this. So I'd be in favor of it.
thomastaylor312 commentedon Jul 27, 2017
@technosophos That was actually the other way I was thinking of doing it but I didn't write it all out. I should of, because now that I have seen it written out, it makes it seem like a better idea. I think it would be more simple to implement and less cognitive burden on the user.
I did think about the plugin way of going about this, but I have heard lots of different people mentioned this from time to time, so it would probably be valuable to have in core.
So anyway, let me rework the initial proposal over the weekend to incorporate your idea @technosophos and we can continue discussion. I'll try to see if we can get some other helm power users to comment on this
sstarcher commentedon Jul 28, 2017
For my use case either of the 2 options would work as long as with the second option I don't have to use the chart generated. I'm mainly interested in bootstrapping kubernetes with something like https://github.com/kubernetes-incubator/bootkube for a self-hosted cluster, but being able to upgrade the manifests with a
helm upgradeSo in my case I would have a handful of manifests that are written to disk somewhere, but I could like to be able to
helm commander kube-configandhelm upgrade kube-configto upgrade my controller-manager, api server, proxy etc.jascott1 commentedon Jul 28, 2017
There might be some learnings to be taken from here
https://github.com/appscode/chartify
thomastaylor312 commentedon Aug 13, 2017
Proposal take 2
Given the feedback thus far, I propose the following functionality:
Command line design
There will be two ways to select resources to commandeer:
<kind>:<name>(e.g.Deployment:www-frontend)kubectl(e.g.app in (foo, bar))The default method will be using the
<kind>:<name>syntax and the label query will be exposed by command line flag (--labelor-l). Users will be able to specify a combination of the two to select multiple resources.The default behavior will be strict matching. For the label syntax this will be that it must match at least one resource. For
<kind>:<name>, each resource listed must match an existing resource.Additional Flags
--ignore-missing: This will allow for "non-strict" matching. Meaning as long as the label selectors or<kind>:<name>list match at least one existing resource, it will create a release.--dry-run: Same as on other commands--debug: Similar to other commands. Will print out the created manifests to STDOUT--name: The name of the new chart/release--output: The file path to output the new chart toHow it will work
Tiller will look for matching resources and turn them into YAML manifests. It will also create a release with those objects. Once the release is complete, Helm will output the new chart into the current working directory or the one specified with
--output. It will create one file per resource it commandeers.Then, as stated by @technosophos:
Important note
Given past experience with other features (cough...cough
--wait), this feature will be marked as alpha on initial release to allow for more testing across the various use cases. It will graduate to beta after that testing. It will not be marked as fully ready until Helm 3.0 or it is decided by the core maintainers (obviously with feedback from community testing) that it is ready, whichever comes firstLet me know if this looks like the best path forward
seh commentedon Aug 13, 2017
Do you intend to save all of the objects' current state, or will you filter it, per my earlier comment?
thomastaylor312 commentedon Aug 14, 2017
@seh I would definitely drop the current status and probably some of the annotations that contain the last version of the object. When we create a PR, we can make sure all of those cases are covered
thomastaylor312 commentedon Aug 17, 2017
After talking in the developer meeting, the choice was made to develop this as a plugin.
thomastaylor312 commentedon Aug 19, 2017
I will be developing the plugin here. Feel free to follow along while I work on it
jamorales-bsft commentedon Sep 8, 2017
@thomastaylor312 How complete is your plugin?
27 remaining items
HamzaZo commentedon May 18, 2021
Hello @bacongobbler
I've been inspired by the proposal and I created a helm v3 plugin called
adoptto help users to adopt existing k8s resources into a new generated helm chart. see helm-adopt repomarcosdiez commentedon Sep 15, 2021
Sorry, but this sounds too complicated. How about proposal 3:
add a new flag to
upgradeandinstallcalled--auto-adopt-exiting-resourcesthat does that and just prints a warning:warning: importing existing resource XXXX, which was not being managed by helmor
warning: importing existing resource YYYYY, which was previously being managed by chart ZZZZZjonnylangefeld commentedon Nov 19, 2022
I agree with the last comment. Why not even just call the flag
--adopt. When set a resource that already exists on the cluster just gets the helm annotations and doesn't have to be deleted and recreated, which could mean downtime for production services.The flag expresses intentionality and the current behavior would be untouched and there would be no braking changes to helm users of the current version.
Ultimately I think this might even help adoption of helm if we make onboarding of existing deployments easier.
andrewdinunzio commentedon Feb 14, 2023
Agreed with the comment above as well, as it's more declarative. Any imperative statements that would need to be run manually for adopting resources makes it a pain for pipelines. #7649 seems like a perfectly fine option to declare what is in a release and anything else is not.
gjenkins8 commentedon Jan 5, 2024
If there is still interest here, I suspect the ideas would best be incorporated into a HIP?
trashhalo commentedon Mar 5, 2024
I found this blog post from a team that was able to migrate objects to helm by manually creating and editing state until helm accepted them. https://medium.com/beekeeper-technology-blog/zero-downtime-migration-to-helm-chart-37c562b24c2d
thomastaylor312 commentedon Mar 13, 2024
I will say that I am not working on this at all right now! But if someone does want to take the idea and roll it into a HIP, please feel free to do so!
howardjohn commentedon May 24, 2024
Wrote up a quick function to do this automatically...
(depends on https://github.com/howardjohn/kubectl-grep, you could do it without but that is a bit too much bash for me)
perj commentedon Sep 26, 2024
When I do the equivalent of what you wrote @howardjohn the install ends up in a weird state. It won't set any labels that exist in the helm chart but didn't exist before. This is also described in this comment that was my first hit while researching this and led me on to this issue.
Even further helm upgrade don't seem to apply new labels, as far as I can tell.
lucasfcnunes commentedon Sep 26, 2024
Using helm diff and applying/installing it with the env var
export HELM_DIFF_THREE_WAY_MERGE=truemay solve your issue.*It's better if you only diff first to see what's gonna change.
perj commentedon Sep 26, 2024
Thanks for the reply. Just like
helm get manifestshows the labels that aren't actually there, thehelm diffoutput also seem to imply it thinks the labels are set, eventhough they aren't on the actual object. It seems to me that the initialhelm installdoesn't modify anything but sets the state to mark as if it had.The obvious workaround is to make sure the resources match completely before running
helm install. But with automated tooling, that's sometimes easier said than done...