├── .github └── workflows │ └── update-version.yml ├── .gitignore ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── NOTICE ├── README.md ├── artifacthub-repo.yml ├── lib ├── api │ ├── helm-ops.sh │ ├── ttl.sh │ └── upgrade.sh ├── config.sh ├── main.sh └── utility.sh ├── panda.jpg ├── plugin.yaml └── release.sh /.github/workflows/update-version.yml: -------------------------------------------------------------------------------- 1 | name: Upgrade Version 2 | on: 3 | release: 4 | types: [published] 5 | 6 | jobs: 7 | upgrade-version: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v2 11 | - uses: pocket-apps/action-update-version@v1 12 | with: 13 | files: 'plugin.yaml' 14 | version-regexp: '\d+.\d+.\d+' 15 | repo-token: ${{ secrets.GITHUB_TOKEN }} 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | yq 2 | .idea 3 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our 6 | community a harassment-free experience for everyone, regardless of age, body 7 | size, visible or invisible disability, ethnicity, sex characteristics, gender 8 | identity and expression, level of experience, education, socio-economic status, 9 | nationality, personal appearance, race, religion, or sexual identity 10 | and orientation. 11 | 12 | We pledge to act and interact in ways that contribute to an open, welcoming, 13 | diverse, inclusive, and healthy community. 14 | 15 | ## Our Standards 16 | 17 | Examples of behavior that contributes to a positive environment for our 18 | community include: 19 | 20 | * Demonstrating empathy and kindness toward other people 21 | * Being respectful of differing opinions, viewpoints, and experiences 22 | * Giving and gracefully accepting constructive feedback 23 | * Accepting responsibility and apologizing to those affected by our mistakes, 24 | and learning from the experience 25 | * Focusing on what is best not just for us as individuals, but for the 26 | overall community 27 | 28 | Examples of unacceptable behavior include: 29 | 30 | * The use of sexualized language or imagery, and sexual attention or 31 | advances of any kind 32 | * Trolling, insulting or derogatory comments, and personal or political attacks 33 | * Public or private harassment 34 | * Publishing others' private information, such as a physical or email 35 | address, without their explicit permission 36 | * Other conduct which could reasonably be considered inappropriate in a 37 | professional setting 38 | 39 | ## Enforcement Responsibilities 40 | 41 | Community leaders are responsible for clarifying and enforcing our standards of 42 | acceptable behavior and will take appropriate and fair corrective action in 43 | response to any behavior that they deem inappropriate, threatening, offensive, 44 | or harmful. 45 | 46 | Community leaders have the right and responsibility to remove, edit, or reject 47 | comments, commits, code, wiki edits, issues, and other contributions that are 48 | not aligned to this Code of Conduct, and will communicate reasons for moderation 49 | decisions when appropriate. 50 | 51 | ## Scope 52 | 53 | This Code of Conduct applies within all community spaces, and also applies when 54 | an individual is officially representing the community in public spaces. 55 | Examples of representing our community include using an official e-mail address, 56 | posting via an official social media account, or acting as an appointed 57 | representative at an online or offline event. 58 | 59 | ## Enforcement 60 | 61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 62 | reported to the community leaders responsible for enforcement at 63 | conduct@jovianx.com. 64 | All complaints will be reviewed and investigated promptly and fairly. 65 | 66 | All community leaders are obligated to respect the privacy and security of the 67 | reporter of any incident. 68 | 69 | ## Enforcement Guidelines 70 | 71 | Community leaders will follow these Community Impact Guidelines in determining 72 | the consequences for any action they deem in violation of this Code of Conduct: 73 | 74 | ### 1. Correction 75 | 76 | **Community Impact**: Use of inappropriate language or other behavior deemed 77 | unprofessional or unwelcome in the community. 78 | 79 | **Consequence**: A private, written warning from community leaders, providing 80 | clarity around the nature of the violation and an explanation of why the 81 | behavior was inappropriate. A public apology may be requested. 82 | 83 | ### 2. Warning 84 | 85 | **Community Impact**: A violation through a single incident or series 86 | of actions. 87 | 88 | **Consequence**: A warning with consequences for continued behavior. No 89 | interaction with the people involved, including unsolicited interaction with 90 | those enforcing the Code of Conduct, for a specified period of time. This 91 | includes avoiding interactions in community spaces as well as external channels 92 | like social media. Violating these terms may lead to a temporary or 93 | permanent ban. 94 | 95 | ### 3. Temporary Ban 96 | 97 | **Community Impact**: A serious violation of community standards, including 98 | sustained inappropriate behavior. 99 | 100 | **Consequence**: A temporary ban from any sort of interaction or public 101 | communication with the community for a specified period of time. No public or 102 | private interaction with the people involved, including unsolicited interaction 103 | with those enforcing the Code of Conduct, is allowed during this period. 104 | Violating these terms may lead to a permanent ban. 105 | 106 | ### 4. Permanent Ban 107 | 108 | **Community Impact**: Demonstrating a pattern of violation of community 109 | standards, including sustained inappropriate behavior, harassment of an 110 | individual, or aggression toward or disparagement of classes of individuals. 111 | 112 | **Consequence**: A permanent ban from any sort of public interaction within 113 | the community. 114 | 115 | ## Attribution 116 | 117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 118 | version 2.0, available at 119 | https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 120 | 121 | Community Impact Guidelines were inspired by [Mozilla's code of conduct 122 | enforcement ladder](https://github.com/mozilla/diversity). 123 | 124 | [homepage]: https://www.contributor-covenant.org 125 | 126 | For answers to common questions about this code of conduct, see the FAQ at 127 | https://www.contributor-covenant.org/faq. Translations are available at 128 | https://www.contributor-covenant.org/translations. 129 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | We love your input! We want to make contributing to this project as easy and transparent as possible, whether it's: 3 | 4 | - Reporting a bug 5 | - Discussing the current state of the code 6 | - Submitting a fix 7 | - Proposing new features 8 | - Becoming a maintainer 9 | 10 | ## We Develop with Github 11 | We use github to host code, to track issues and feature requests, as well as accept pull requests. 12 | 13 | ## We Use [Github Flow](https://guides.github.com/introduction/flow/index.html), So All Code Changes Happen Through Pull Requests 14 | Pull requests are the best way to propose changes to the codebase (we use [Github Flow](https://guides.github.com/introduction/flow/index.html)). We actively welcome your pull requests: 15 | 16 | 1. Fork the repo and create your branch from `main`. 17 | 1. Make your code changes. 18 | 1. Update the documentation according the change. 19 | 1. Issue that pull request! 20 | 21 | 22 | ## Developmnet environmnet 23 | To debug and test in developmnet, run command: 24 | ``` 25 | cd 26 | HELM_PLUGINS=$(pwd)/.. helm release 27 | ``` 28 | 29 | Alternatively install a branch version of the plugin. 30 | You may need to uninstall first in order to be able to reinstall the plugin `helm plugin uninstall release` 31 | ``` 32 | helm plugin install https://github.com/JovianX/helm-release-plugin --version 33 | ``` 34 | 35 | ## Any contributions you make will be under the Apache 2.0 Software License 36 | In short, when you submit code changes, your submissions are understood to be under the same [Apache License]([http://choosealicense.com/licenses/mit/](https://github.com/JovianX/helm-release-plugin/blob/main/LICENSE)) that covers the project. Feel free to contact the maintainers if that's a concern. 37 | 38 | ## Report bugs using Github's [issues](https://github.com/JovianX/helm-release-plugin/issues) 39 | We use GitHub issues to track public bugs. Report a bug by [opening a new issue](https://github.com/JovianX/helm-release-plugin/issues/new); it's that easy! 40 | 41 | 42 | **Great Bug Reports** tend to have: 43 | 44 | - A quick summary and/or background 45 | - Steps to reproduce 46 | - Be specific! 47 | - Give sample code if you can. 48 | - What you expected would happen 49 | - What actually happens 50 | - Notes (possibly including why you think this might be happening, or stuff you tried that didn't work) 51 | 52 | People *love* thorough bug reports. I'm not even kidding. 53 | 54 | 55 | ## License 56 | By contributing, you agree that your contributions will be licensed under its Apache 2.0 License. 57 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Copyright 2022 JovianX Ltd. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | [![Open Source](https://badges.frapsoft.com/os/v1/open-source.svg?v=103)](https://opensource.org/) 6 | [![GitHub license](https://img.shields.io/github/license/JovianX/helm-release-plugin)](https://github.com/JovianX/helm-release-plugin) 7 | [![Artifact Hub](https://img.shields.io/endpoint?url=https://artifacthub.io/badge/repository/helm-release)](https://artifacthub.io/packages/helm-plugin/helm-release/release) 8 | ![GitHub contributors](https://img.shields.io/github/contributors/JovianX/helm-release-plugin) 9 | ![Discord](https://img.shields.io/discord/1014893148599754894?style=flat) 10 | [![GitHub stars](https://img.shields.io/github/stars/JovianX/helm-release-plugin)](https://github.com/JovianX/helm-release-plugin/stargazers) 11 | 12 | 13 | | **Please star ⭐ the repo if you find it useful.** | 14 | | --- | 15 | 16 |
17 | 18 | # Helm3 Plugin `helm-release` 19 | 20 | `helm-release` is a Helm 3 plugin that allows running operations on Helm releases (deployed Helm charts). 21 | 22 | ### ✨ Features: 23 | 24 | * 📥 [PULL](#helm-release-pull) to pull (re-create) Helm charts from a deployed helm release. 25 | * 📄 [UPGRADE](#helm-release-upgrade) to Update values of a deployed release, without providing the chart used for release deployment. 26 | * ⏳ [TTL](#helm-release-ttl) to schedule an uninstallation/removal/deletion of a release. [Article](https://dev.to/rtpro/helm-release-time-to-livettl-for-temporary-environments-1239) 27 | 28 | ### 🫶 Common use-Cases: 29 | * Redeploy a release on another cluster or namespace with the same helm chart. 30 | * Update values of a release, when you are not sure what exact chart version was used, or you don't have access to the original helm chart (Contrary to the `helm upgrade` command which requires the chart). 31 | * configure temporary or ephemeral helm releases so they are automatically deleted after some time and not forgotten on the cluster forever. 32 | 33 | ## Getting started 34 | ### Installation 35 | To install the plugin: 36 | ```shell 37 | helm plugin install https://github.com/JovianX/helm-release-plugin 38 | ``` 39 | 40 | > 41 | > Dependencies: `helm-release` plugin depends on: 42 | >> jq - a lightweight and flexible command-line JSON processor. 43 | >> Install: https://stedolan.github.io/jq/download/ 44 | > 45 | 46 | Update to the latest version: 47 | ```shell 48 | $ helm plugin update release 49 | ``` 50 | Verify it's been installed: 51 | ```shell 52 | $ helm plugin list 53 | NAME VERSION DESCRIPTION 54 | ... 55 | release 0.3.2 Update values of a release, pull charts from releases 56 | ... 57 | ``` 58 | 59 | 60 | ### Usage 61 | 62 | ``` 63 | $ helm release 64 | usage: helm release [ pull | upgrade ] 65 | ``` 66 | Available Commands: 67 | * __pull__ - Pulls (re-create) the Helm chart from a deployed Helm release. 68 | * __upgrade__ - Updates Helm release values without the Helm chart. 69 | * __ttl__ - Sets release time to live(TTL) to schedule release automatic delete. 70 | 71 | > 72 | > Note: Setting Namespace and Context are supported via helm native flags 73 | > ``` 74 | > -n, --namespace string namespace scope for this request` 75 | > --kube-context string name of the kubeconfig context to use 76 | > ``` 77 | > 78 | 79 | 80 | 81 | ### `helm release pull` 82 | 83 | Pulls (re-create) a Helm chart from a deployed Helm release. 84 | 85 | ``` 86 | $ helm release pull 87 | usage: helm release pull [-d | --destination ] [-o | --output [yaml | json | text]] 88 | ``` 89 | 90 | Example: 91 | ``` 92 | $ helm --namespace nginx release pull nginx --destination /home/me/helm-charts 93 | Chart saved to nginx-ingress-0.13.2 94 | 95 | $ ls /home/me/helm-charts/nginx-ingress-0.13.2/ 96 | Chart.yaml crds README.md templates values-icp.yaml values-nsm.yaml values-plus.yaml values.yaml 97 | ``` 98 | > 99 | >Note: Setting namespace`[-n | --namespace ]` or context `[--context]` name as needed) 100 | > 101 | ### `helm release upgrade` 102 | 103 | Update the Helm release values, without specifying the helm chart. The `helm release upgrade` command accepts the same parameters as `helm upgrade` without specifying the helm chart. `--destination` is an optional parameter to set the directory where the chart is saved, defaults to `/tmp`. After the release is updated the chart is deleted. We recommend setting the `--reuse-values` flag to keep existing values and provide only the values you would like to change. 104 | ``` 105 | $ helm release upgrade 106 | Update release values without specifying the Helm Chart. Usage: helm release upgrade [RELEASE NAME] [-d | --destination ] [helm upgrade arguments] 107 | ``` 108 | 109 | Example: 110 | ``` 111 | helm release upgrade rabbitmq --namespace=rabbitmq --set=key1=value1 --reuse-values 112 | ... 113 | ... standard helm upgrade output ... 114 | Update Complete. ⎈Happy Helming!⎈ 115 | ``` 116 | 117 | 118 | ### `helm release ttl` 119 | Sets release time-to-live(TTL) to schedule automatic release uninstallation. `release ttl` uses Kubernetes CronJob to schedule automatic uninstallation of releases. Helm release TTL supports actions: **set**, **unset** and **get** TTL for a helm release. 120 | 121 | 122 | | Note: Helm release TTL feature uses `date` binary provided by `coreutils` package. | 123 | | --- | 124 | 125 | #### GET TTL 126 | To get the current TTL of a release pass the ``. 127 | ``` 128 | helm release ttl 129 | ``` 130 | 131 | Supproted outputs: `text`(defaul), `yaml` and `json`. 132 | For example, to see when `redis` release is scheduled for deletion, run: 133 | ``` 134 | helm release ttl redis 135 | Scheduled release removal date: Tue Aug 30 20:12:00 EEST 2022 136 | ``` 137 | Same request with `json` output: 138 | ``` 139 | helm release ttl redis --output=json 140 | {"scheduled_date": "2022-08-30 17:12"} 141 | ``` 142 | Same request with `yaml` output: 143 | ``` 144 | helm release ttl redis --output=yaml 145 | scheduled_date: 2022-08-30 17:12 146 | ``` 147 | 148 | | Note: Dates returned in cluster timezone (default UTC). | 149 | | --- | 150 | 151 | 152 | #### SET TTL 153 | 154 | Sets the TTL of a release, after which the release is deleted. Provide `` and `--set` to set the release TTL time using `date` format. 155 | ``` 156 | helm release ttl --set 157 | ``` 158 | 159 | For example to schedule deletion of a release in `five minutes, run: 160 | ``` 161 | helm release ttl redis --set='5 minutes' 162 | cronjob.batch/redis-ttl created 163 | ``` 164 | > Refer to complete `` [documentation](https://www.gnu.org/software/ coreutils/manual/html_node/Relative-items-in-date-strings.html) for 165 | > detailed description of possible time delta options. 166 | 167 | If TTL is configured (CronJob exists) and the `--set` command is executed again the TTL(CronJob) will be rescheduled: 168 | ``` 169 | helm release ttl redis --set='5 minutes' 170 | cronjob.batch/redis-ttl configured 171 | ``` 172 | 173 | #### UNSET TTL 174 | To remove release TTL pass `` and `--unset` flag. 175 | ``` 176 | helm release ttl --unset 177 | ``` 178 | 179 | 180 | For example, to remove `redis` release TTL run: 181 | ``` 182 | helm release ttl redis --unset 183 | cronjob.batch "redis-ttl" deleted 184 | ``` 185 | 186 | ##### Service Account 187 | You can specify which service account should be used once the TTL has expired. The `default` service account is used, unless otherwise specified which is highly recommended. You can specify the service account with the `--service-account` parameter. Note this is only used in the job context when the TTL has expired and the cleanup is triggered. 188 | 189 | ``` 190 | helm release ttl redis --service-account='my-privileged-serviceaccount' --set='5 minutes' 191 | ``` 192 | 193 | Example service account (needs to be provisioned/created separately) 194 | ``` 195 | apiVersion: v1 196 | kind: ServiceAccount 197 | metadata: 198 | name: my-privileged-serviceaccount 199 | namespace: default 200 | --- 201 | apiVersion: rbac.authorization.k8s.io/v1 202 | kind: ClusterRoleBinding 203 | metadata: 204 | name: my-privileged-serviceaccount 205 | roleRef: 206 | apiGroup: rbac.authorization.k8s.io 207 | kind: ClusterRole 208 | name: cluster-admin 209 | subjects: 210 | - kind: ServiceAccount 211 | name: my-privileged-serviceaccount 212 | namespace: default 213 | ``` 214 | 215 | 216 | ## Contributing 217 | We love your input! We want to make contributing to this project as easy and transparent as possible, whether it's: 218 | - Reporting a bug 219 | - Submitting a fix 220 | - Proposing new features 221 | - All pull requests are welcome. 222 | 223 | Please see the [CONTRIBUTING](CONTRIBUTING.md) guide. 224 | 225 | ## Users 226 | Who is using helm-release-plugin: 227 | 228 | 229 | - [JovianX ServiceHub](https://github.com/JovianX/Service-Hub) 230 | 231 | 232 | ## Contributors 233 | 234 | 235 | 236 | 237 | ## License 238 | Copyright 2022 JovianX Ltd. 239 | 240 | Licensed under the Apache License, Version 2.0 (the "[LICENSE](https://github.com/JovianX/helm-release-plugin/blob/main/LICENSE)") 241 | 242 | 243 | 244 | 245 | 246 | -------------------------------------------------------------------------------- /artifacthub-repo.yml: -------------------------------------------------------------------------------- 1 | repositoryID: cdb5f6dd-aca0-4c63-a4c0-bb5b108e1506 2 | owners: 3 | - name: JovianX 4 | email: info@jovianx.com 5 | -------------------------------------------------------------------------------- /lib/api/helm-ops.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | function pull_chart_from_release() { 3 | 4 | local msg="usage: helm release pull [-d | --destination ] [-o | --output [yaml | json | text]]" 5 | NAMESPACE=$HELM_NAMESPACE 6 | K8S_CONTEXT=$HELM_KUBECONTEXT 7 | DESTINATION_DIR="." 8 | RELEASE="" 9 | OUTPUT="text" 10 | 11 | while test $# -gt 0; do 12 | case "$1" in 13 | (-d|--destination) 14 | shift 15 | if test $# -gt 0; then 16 | export DESTINATION_DIR=$1 17 | else 18 | exit_with_help "$msg" 19 | fi 20 | shift 21 | ;; 22 | --destination*) 23 | export DESTINATION_DIR=`echo $1 | sed -e 's/^[^=]*=//g'` 24 | shift 25 | ;; 26 | (-o|--output) 27 | shift 28 | if test $# -gt 0; then 29 | export OUTPUT=$1 30 | if [ "$OUTPUT" != "text" ] && [ "$OUTPUT" != "yaml" ] && [ "$OUTPUT" != "json" ]; then 31 | exit_with_help "$msg" 32 | fi 33 | else 34 | exit_with_help "$msg" 35 | fi 36 | shift 37 | ;; 38 | --output*) 39 | export OUTPUT=`echo $1 | sed -e 's/^[^=]*=//g'` 40 | if [ "$OUTPUT" != "text" ] && [ "$OUTPUT" != "yaml" ] && [ "$OUTPUT" != "json" ]; then 41 | exit_with_help "$msg" 42 | fi 43 | shift 44 | ;; 45 | *) 46 | if [[ -z $RELEASE ]]; then 47 | RELEASE=$1 48 | else 49 | exit_with_help "$msg" 50 | fi 51 | shift 52 | ;; 53 | esac 54 | done 55 | if [[ -z $RELEASE ]]; then 56 | exit_with_help "$msg" 57 | fi 58 | 59 | RELEASE_STATUS=$(helm -n $NAMESPACE --kube-context=$K8S_CONTEXT status $RELEASE -o json) 60 | if [ $? -eq 0 ]; then 61 | echo $RELEASE_STATUS | jq > $(dirname -- "$0")/data/release-$RELEASE-status.json; 62 | VERSION=$(cat $(dirname -- "$0")/data/release-$RELEASE-status.json | jq -r .version) 63 | 64 | RELEASE_CONTENT=$(kubectl \ 65 | get secrets sh.helm.release.v1.$RELEASE.v$VERSION \ 66 | -n $NAMESPACE \ 67 | --context=$K8S_CONTEXT \ 68 | -o jsonpath='{.data.release}' \ 69 | | base64 -d | base64 -d | gzip -d | jq | tee $(dirname -- "$0")/data/release-$RELEASE-content.json) 70 | 71 | CHART_NAME=$(cat $(dirname -- "$0")/data/release-$RELEASE-content.json | jq -r .chart.metadata.name) 72 | CHART_VERSION=$(cat $(dirname -- "$0")/data/release-$RELEASE-content.json | jq -r .chart.metadata.version) 73 | CHART_DIR_NAME="$CHART_NAME-$CHART_VERSION" 74 | CHART_DIR="$DESTINATION_DIR/$CHART_DIR_NAME" 75 | 76 | mkdir -p $CHART_DIR 77 | 78 | echo $RELEASE_CONTENT | jq -r '.chart.metadata' | $HELM_PLUGIN_DIR/lib/yq e -P - > $CHART_DIR/Chart.yaml 79 | echo $RELEASE_CONTENT | jq -r '.chart.values' | $HELM_PLUGIN_DIR/lib/yq e -P - > $CHART_DIR/values.yaml 80 | 81 | # Create Chart Templates 82 | for row in $(echo $RELEASE_CONTENT | jq -r '.chart.templates[] | @base64'); do 83 | #echo $row 84 | _jq() { 85 | echo ${row} | base64 --decode | jq -r ${1} 86 | } 87 | filename=$(echo $(_jq '.name')) 88 | data=$(echo $(_jq '.data') ) 89 | mkdir -p $(dirname $CHART_DIR/$filename) 90 | echo $data | base64 -d > $CHART_DIR/$filename 91 | done 92 | # Create Chart files 93 | for row in $(echo $RELEASE_CONTENT | jq -r '.chart.files[] | @base64'); do 94 | #echo $row 95 | _jq() { 96 | echo ${row} | base64 --decode | jq -r ${1} 97 | } 98 | filename=$(echo $(_jq '.name')) 99 | data=$(echo $(_jq '.data') ) 100 | mkdir -p $(dirname $CHART_DIR/$filename) 101 | echo $data | base64 -d > $CHART_DIR/$filename 102 | done 103 | fi 104 | rm_dir './data' 105 | case $OUTPUT in 106 | json) 107 | echo "{\"chart_directory\": \"$CHART_DIR_NAME\"}" ;; 108 | yaml) 109 | echo "chart_directory: $CHART_DIR_NAME" ;; 110 | *) 111 | echo "Chart saved to $CHART_DIR_NAME" ;; 112 | esac 113 | return 0; 114 | } -------------------------------------------------------------------------------- /lib/api/ttl.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | HELM_VERSION="3.17.0" 4 | KUBECTL_VERSION="1.32.1" 5 | 6 | help_text=" 7 | Sets release TTL. Under the hood creates Kubernetes CronJob that will delete specific release in concrete time. 8 | Usage: 9 | helm release ttl --set