Compare commits
38 Commits
v0.9.2
...
alias-sett
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7892c9c0a6 | ||
|
|
b4b1f7882d | ||
|
|
a826f66425 | ||
|
|
71421fbaa5 | ||
|
|
cfd8e33995 | ||
|
|
a5342d7bac | ||
|
|
6aa1d79d56 | ||
|
|
1d1117ba49 | ||
|
|
04de280821 | ||
|
|
7cfe20db1f | ||
|
|
7fc8212451 | ||
|
|
7cb7ecec90 | ||
|
|
55017eed0f | ||
|
|
b6ba856c31 | ||
|
|
8c6c6fbfa5 | ||
|
|
e071d23fef | ||
|
|
c8b4ad4c46 | ||
|
|
971e3f17cb | ||
|
|
ee3dc9ff0e | ||
|
|
7ecfe70e3e | ||
|
|
d5bd083bf5 | ||
|
|
8d8bcf78a7 | ||
|
|
222261d931 | ||
|
|
e694d93445 | ||
|
|
eaac6dd643 | ||
|
|
c569059b87 | ||
|
|
45428a2e25 | ||
|
|
7b816ea257 | ||
|
|
3c44be059e | ||
|
|
11ffdc7210 | ||
|
|
b4a13d9971 | ||
|
|
4330728215 | ||
|
|
3ae13d4b3c | ||
|
|
17724e7015 | ||
|
|
04a2c48ece | ||
|
|
997a33fc0d | ||
|
|
280c8577a4 | ||
|
|
51058470e5 |
11
.github/ISSUE_TEMPLATE/documentation.md
vendored
Normal file
11
.github/ISSUE_TEMPLATE/documentation.md
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
---
|
||||
name: Documentation
|
||||
about: Docs you'd like to see, or questions about existing docs
|
||||
title: ''
|
||||
labels: documentation
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**What needs explanation:**
|
||||
<!-- e.g. "what happens when ____", "how do I ___", etc. -->
|
||||
6
.github/pull_request_template.md
vendored
6
.github/pull_request_template.md
vendored
@@ -3,6 +3,8 @@
|
||||
Pre-merge checklist:
|
||||
|
||||
* [ ] Code changes have tests
|
||||
* [ ] Any changes to the config are documented in `docs/parameter_reference.md`
|
||||
* [ ] Any new _required_ config is documented in `README.md`
|
||||
* [ ] Any config changes are documented:
|
||||
* If the change touches _required_ config, there's a corresponding update to `README.md`
|
||||
* There's a corresponding update to `docs/parameter_reference.md`
|
||||
* There's a pull request to update [the parameter reference in drone-plugin-index](https://github.com/drone/drone-plugin-index/blob/master/content/pelotech/drone-helm3/index.md)
|
||||
* [ ] Any large changes have been verified by running a Drone job
|
||||
|
||||
28
README.md
28
README.md
@@ -10,7 +10,7 @@ This plugin provides an interface between [Drone](https://drone.io/) and [Helm 3
|
||||
* Deploy your service
|
||||
* Delete your service
|
||||
|
||||
The plugin is inpsired by [drone-helm](https://github.com/ipedrazas/drone-helm), which fills the same role for Helm 2. It provides a comparable feature-set and the configuration settings are backwards-compatible.
|
||||
The plugin is inpsired by [drone-helm](https://github.com/ipedrazas/drone-helm), which fills the same role for Helm 2. It provides a comparable feature-set and the configuration settings are backward-compatible.
|
||||
|
||||
## Example configuration
|
||||
|
||||
@@ -23,7 +23,7 @@ steps:
|
||||
- name: lint
|
||||
image: pelotech/drone-helm3
|
||||
settings:
|
||||
helm_command: lint
|
||||
mode: lint
|
||||
chart: ./
|
||||
```
|
||||
|
||||
@@ -34,12 +34,12 @@ steps:
|
||||
- name: deploy
|
||||
image: pelotech/drone-helm3
|
||||
settings:
|
||||
helm_command: upgrade
|
||||
mode: upgrade
|
||||
chart: ./
|
||||
release: my-project
|
||||
environment:
|
||||
API_SERVER: https://my.kubernetes.installation/clusters/a-1234
|
||||
KUBERNETES_TOKEN:
|
||||
KUBE_API_SERVER: https://my.kubernetes.installation/clusters/a-1234
|
||||
KUBE_TOKEN:
|
||||
from_secret: kubernetes_token
|
||||
```
|
||||
|
||||
@@ -50,21 +50,22 @@ steps:
|
||||
- name: uninstall
|
||||
image: pelotech/drone-helm3
|
||||
settings:
|
||||
helm_command: uninstall
|
||||
mode: uninstall
|
||||
release: my-project
|
||||
environment:
|
||||
API_SERVER: https://my.kubernetes.installation/clusters/a-1234
|
||||
KUBERNETES_TOKEN:
|
||||
KUBE_API_SERVER: https://my.kubernetes.installation/clusters/a-1234
|
||||
KUBE_TOKEN:
|
||||
from_secret: kubernetes_token
|
||||
```
|
||||
|
||||
## Upgrading from drone-helm
|
||||
|
||||
drone-helm3 is largely backwards-compatible with drone-helm. There are some known differences:
|
||||
drone-helm3 is largely backward-compatible with drone-helm. There are some known differences:
|
||||
|
||||
* You'll need to migrate the deployments in the cluster [helm-v2-to-helm-v3](https://helm.sh/blog/migrate-from-helm-v2-to-helm-v3/).
|
||||
* EKS is not supported. See [#5](https://github.com/pelotech/drone-helm3/issues/5) for more information.
|
||||
* The `prefix` setting is no longer supported. If you were relying on the `prefix` setting with `secrets: [...]`, you'll need to switch to the `from_secret` syntax.
|
||||
* During uninstallations, the release history is purged by default. Use `keep_history: true` to return to the old behavior.
|
||||
* Several settings no longer have any effect. The plugin will produce warnings if any of these are present:
|
||||
* `purge` -- this is the default behavior in Helm 3
|
||||
* `recreate_pods`
|
||||
@@ -73,6 +74,15 @@ drone-helm3 is largely backwards-compatible with drone-helm. There are some know
|
||||
* `canary_image`
|
||||
* `client_only`
|
||||
* `stable_repo_url`
|
||||
* Several settings have been renamed, to clarify their purpose and provide a more consistent naming scheme. For backward-compatibility, the old names are still available as aliases. If the old and new names are both present, the updated form takes priority. Conflicting settings will make your `.drone.yml` harder to understand, so we recommend updating to the new names:
|
||||
* `helm_command` is now `mode`
|
||||
° `helm_repos` is now `add_repos`
|
||||
* `api_server` is now `kube_api_server`
|
||||
* `service_account` is now `kube_service_account`
|
||||
* `kubernetes_token` is now `kube_token`
|
||||
* `kubernetes_certificate` is now `kube_certificate`
|
||||
* `wait` is now `wait_for_upgrade`
|
||||
* `force` is now `force_upgrade`
|
||||
|
||||
Since helm 3 does not require Tiller, we also recommend switching to a service account with less-expansive permissions.
|
||||
|
||||
|
||||
@@ -4,11 +4,12 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
_ "github.com/joho/godotenv/autoload"
|
||||
"github.com/pelotech/drone-helm3/internal/helm"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cfg, err := helm.NewConfig(os.Stdout, os.Stderr)
|
||||
cfg, err := helm.NewConfig(os.Stdout, os.Stderr, os.Args...)
|
||||
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%s\n", err.Error())
|
||||
|
||||
@@ -3,15 +3,15 @@
|
||||
## Global
|
||||
| Param name | Type | Purpose |
|
||||
|---------------------|-----------------|---------|
|
||||
| helm_command | string | Indicates the operation to perform. Recommended, but not required. Valid options are `upgrade`, `uninstall`, `lint`, and `help`. |
|
||||
| mode | string | Indicates the operation to perform. Recommended, but not required. Valid options are `upgrade`, `uninstall`, `lint`, and `help`. |
|
||||
| update_dependencies | boolean | Calls `helm dependency update` before running the main command.|
|
||||
| helm_repos | list\<string\> | Calls `helm repo add $repo` before running the main command. Each string should be formatted as `repo_name=https://repo.url/`. |
|
||||
| add_repos | list\<string\> | Calls `helm repo add $repo` before running the main command. Each string should be formatted as `repo_name=https://repo.url/`. |
|
||||
| namespace | string | Kubernetes namespace to use for this operation. |
|
||||
| debug | boolean | Generate debug output within drone-helm3 and pass `--debug` to all helm commands. Use with care, since the debug output may include secrets. |
|
||||
|
||||
## Linting
|
||||
|
||||
Linting is only triggered when the `helm_command` setting is "lint".
|
||||
Linting is only triggered when the `mode` setting is "lint".
|
||||
|
||||
| Param name | Type | Required | Purpose |
|
||||
|---------------|----------------|----------|---------|
|
||||
@@ -19,24 +19,27 @@ Linting is only triggered when the `helm_command` setting is "lint".
|
||||
| values | list\<string\> | | Chart values to use as the `--set` argument to `helm lint`. |
|
||||
| string_values | list\<string\> | | Chart values to use as the `--set-string` argument to `helm lint`. |
|
||||
| values_files | list\<string\> | | Values to use as `--values` arguments to `helm lint`. |
|
||||
| lint_strictly | boolean | | Pass `--strict` to `helm lint`, to turn warnings into errors. |
|
||||
|
||||
## Installation
|
||||
|
||||
Installations are triggered when the `helm_command` setting is "upgrade." They can also be triggered when the build was triggered by a `push`, `tag`, `deployment`, `pull_request`, `promote`, or `rollback` Drone event.
|
||||
Installations are triggered when the `mode` setting is "upgrade." They can also be triggered when the build was triggered by a `push`, `tag`, `deployment`, `pull_request`, `promote`, or `rollback` Drone event.
|
||||
|
||||
| Param name | Type | Required | Purpose |
|
||||
|------------------------|----------------|----------|---------|
|
||||
| chart | string | yes | The chart to use for this installation. |
|
||||
| release | string | yes | The release name for helm to use. |
|
||||
| api_server | string | yes | API endpoint for the Kubernetes cluster. |
|
||||
| kubernetes_token | string | yes | Token for authenticating to Kubernetes. |
|
||||
| service_account | string | | Service account for authenticating to Kubernetes. Default is `helm`. |
|
||||
| kubernetes_certificate | string | | Base64 encoded TLS certificate used by the Kubernetes cluster's certificate authority. |
|
||||
| kube_api_server | string | yes | API endpoint for the Kubernetes cluster. |
|
||||
| kube_token | string | yes | Token for authenticating to Kubernetes. |
|
||||
| kube_service_account | string | | Service account for authenticating to Kubernetes. Default is `helm`. |
|
||||
| kube_certificate | string | | Base64 encoded TLS certificate used by the Kubernetes cluster's certificate authority. |
|
||||
| chart_version | string | | Specific chart version to install. |
|
||||
| dry_run | boolean | | Pass `--dry-run` to `helm upgrade`. |
|
||||
| wait | boolean | | Wait until kubernetes resources are in a ready state before marking the installation successful. |
|
||||
| wait_for_upgrade | boolean | | Wait until kubernetes resources are in a ready state before marking the installation successful. |
|
||||
| timeout | duration | | Timeout for any *individual* Kubernetes operation. The installation's full runtime may exceed this duration. |
|
||||
| force | boolean | | Pass `--force` to `helm upgrade`. |
|
||||
| force_upgrade | boolean | | Pass `--force` to `helm upgrade`. |
|
||||
| atomic_upgrade | boolean | | Pass `--atomic` to `helm upgrade`. |
|
||||
| cleanup_failed_upgrade | boolean | | Pass `--cleanup-on-fail` to `helm upgrade`. |
|
||||
| values | list\<string\> | | Chart values to use as the `--set` argument to `helm upgrade`. |
|
||||
| string_values | list\<string\> | | Chart values to use as the `--set-string` argument to `helm upgrade`. |
|
||||
| values_files | list\<string\> | | Values to use as `--values` arguments to `helm upgrade`. |
|
||||
@@ -45,15 +48,16 @@ Installations are triggered when the `helm_command` setting is "upgrade." They c
|
||||
|
||||
## Uninstallation
|
||||
|
||||
Uninstallations are triggered when the `helm_command` setting is "uninstall" or "delete." They can also be triggered when the build was triggered by a `delete` Drone event.
|
||||
Uninstallations are triggered when the `mode` setting is "uninstall" or "delete." They can also be triggered when the build was triggered by a `delete` Drone event.
|
||||
|
||||
| Param name | Type | Required | Purpose |
|
||||
|------------------------|----------|----------|---------|
|
||||
| release | string | yes | The release name for helm to use. |
|
||||
| api_server | string | yes | API endpoint for the Kubernetes cluster. |
|
||||
| kubernetes_token | string | yes | Token for authenticating to Kubernetes. |
|
||||
| service_account | string | | Service account for authenticating to Kubernetes. Default is `helm`. |
|
||||
| kubernetes_certificate | string | | Base64 encoded TLS certificate used by the Kubernetes cluster's certificate authority. |
|
||||
| kube_api_server | string | yes | API endpoint for the Kubernetes cluster. |
|
||||
| kube_token | string | yes | Token for authenticating to Kubernetes. |
|
||||
| kube_service_account | string | | Service account for authenticating to Kubernetes. Default is `helm`. |
|
||||
| kube_certificate | string | | Base64 encoded TLS certificate used by the Kubernetes cluster's certificate authority. |
|
||||
| keep_history | boolean | | Pass `--keep-history` to `helm uninstall`, to retain the release history. |
|
||||
| dry_run | boolean | | Pass `--dry-run` to `helm uninstall`. |
|
||||
| timeout | duration | | Timeout for any *individual* Kubernetes operation. The uninstallation's full runtime may exceed this duration. |
|
||||
| skip_tls_verify | boolean | | Connect to the Kubernetes cluster without checking for a valid TLS certificate. Not recommended in production. |
|
||||
@@ -61,7 +65,9 @@ Uninstallations are triggered when the `helm_command` setting is "uninstall" or
|
||||
|
||||
### Where to put settings
|
||||
|
||||
Any setting can go in either the `settings` or `environment` section.
|
||||
Any setting can go in either the `settings` or `environment` section. If a setting exists in _both_ sections, the version in `environment` will override the version in `settings`.
|
||||
|
||||
We recommend putting all drone-helm3 configuration in the `settings` block and limiting the `environment` block to variables that are used when building your charts.
|
||||
|
||||
### Formatting non-string values
|
||||
|
||||
|
||||
5
go.mod
5
go.mod
@@ -4,9 +4,8 @@ go 1.13
|
||||
|
||||
require (
|
||||
github.com/golang/mock v1.3.1
|
||||
github.com/kelseyhightower/envconfig v1.4.0
|
||||
github.com/joho/godotenv v1.3.0
|
||||
github.com/stretchr/testify v1.4.0
|
||||
golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f // indirect
|
||||
golang.org/x/tools v0.0.0-20191209225234-22774f7dae43 // indirect
|
||||
github.com/urfave/cli/v2 v2.1.1
|
||||
gopkg.in/yaml.v2 v2.2.2
|
||||
)
|
||||
|
||||
23
go.sum
23
go.sum
@@ -1,31 +1,30 @@
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/golang/mock v1.3.1 h1:qGJ6qTW+x6xX/my+8YUVl4WNpX9B7+/l2tRsHGZ7f2s=
|
||||
github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y=
|
||||
github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8=
|
||||
github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg=
|
||||
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
|
||||
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
|
||||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/urfave/cli/v2 v2.1.1 h1:Qt8FeAtxE/vfdrLmR3rxR6JRE0RoVmbXu8+6kZtYU4k=
|
||||
github.com/urfave/cli/v2 v2.1.1/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f h1:J5lckAjkw6qYlOZNj90mLYNTEKDvWeuc1yieZ8qUzUE=
|
||||
golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/tools v0.0.0-20190425150028-36563e24a262 h1:qsl9y/CJx34tuA7QCPNp86JNJe4spst6Ff8MjvPUdPg=
|
||||
golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||
golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f h1:kDxGY2VmgABOe55qheT/TFqUMtcTHnomIPS1iv3G4Ms=
|
||||
golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20191206204035-259af5ff87bd h1:Zc7EU2PqpsNeIfOoVA7hvQX4cS3YDJEs5KlfatT3hLo=
|
||||
golang.org/x/tools v0.0.0-20191206204035-259af5ff87bd/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20191209225234-22774f7dae43 h1:NfPq5mgc5ArFgVLCpeS4z07IoxSAqVfV/gQ5vxdgaxI=
|
||||
golang.org/x/tools v0.0.0-20191209225234-22774f7dae43/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
||||
|
||||
@@ -2,7 +2,7 @@ package helm
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/kelseyhightower/envconfig"
|
||||
"github.com/urfave/cli/v2"
|
||||
"io"
|
||||
"os"
|
||||
"regexp"
|
||||
@@ -20,45 +20,190 @@ var (
|
||||
// not have the `PLUGIN_` prefix.
|
||||
type Config struct {
|
||||
// Configuration for drone-helm itself
|
||||
Command string `envconfig:"HELM_COMMAND"` // Helm command to run
|
||||
DroneEvent string `envconfig:"DRONE_BUILD_EVENT"` // Drone event that invoked this plugin.
|
||||
UpdateDependencies bool `split_words:"true"` // Call `helm dependency update` before the main command
|
||||
AddRepos []string `envconfig:"HELM_REPOS"` // Call `helm repo add` before the main command
|
||||
Debug bool `` // Generate debug output and pass --debug to all helm commands
|
||||
Values string `` // Argument to pass to --set in applicable helm commands
|
||||
StringValues string `split_words:"true"` // Argument to pass to --set-string in applicable helm commands
|
||||
ValuesFiles []string `split_words:"true"` // Arguments to pass to --values in applicable helm commands
|
||||
Namespace string `` // Kubernetes namespace for all helm commands
|
||||
KubeToken string `envconfig:"KUBERNETES_TOKEN"` // Kubernetes authentication token to put in .kube/config
|
||||
SkipTLSVerify bool `envconfig:"SKIP_TLS_VERIFY"` // Put insecure-skip-tls-verify in .kube/config
|
||||
Certificate string `envconfig:"KUBERNETES_CERTIFICATE"` // The Kubernetes cluster CA's self-signed certificate (must be base64-encoded)
|
||||
APIServer string `envconfig:"API_SERVER"` // The Kubernetes cluster's API endpoint
|
||||
ServiceAccount string `split_words:"true"` // Account to use for connecting to the Kubernetes cluster
|
||||
ChartVersion string `split_words:"true"` // Specific chart version to use in `helm upgrade`
|
||||
DryRun bool `split_words:"true"` // Pass --dry-run to applicable helm commands
|
||||
Wait bool `` // Pass --wait to applicable helm commands
|
||||
ReuseValues bool `split_words:"true"` // Pass --reuse-values to `helm upgrade`
|
||||
Timeout string `` // Argument to pass to --timeout in applicable helm commands
|
||||
Chart string `` // Chart argument to use in applicable helm commands
|
||||
Release string `` // Release argument to use in applicable helm commands
|
||||
Force bool `` // Pass --force to applicable helm commands
|
||||
Command string // Helm command to run
|
||||
DroneEvent string // Drone event that invoked this plugin.
|
||||
UpdateDependencies bool // Call `helm dependency update` before the main command
|
||||
AddRepos []string // Call `helm repo add` before the main command
|
||||
Debug bool // Generate debug output and pass --debug to all helm commands
|
||||
Values string // Argument to pass to --set in applicable helm commands
|
||||
StringValues string // Argument to pass to --set-string in applicable helm commands
|
||||
ValuesFiles []string // Arguments to pass to --values in applicable helm commands
|
||||
Namespace string // Kubernetes namespace for all helm commands
|
||||
KubeToken string // Kubernetes authentication token to put in .kube/config
|
||||
SkipTLSVerify bool // Put insecure-skip-tls-verify in .kube/config
|
||||
Certificate string // The Kubernetes cluster CA's self-signed certificate (must be base64-encoded)
|
||||
APIServer string // The Kubernetes cluster's API endpoint
|
||||
ServiceAccount string // Account to use for connecting to the Kubernetes cluster
|
||||
ChartVersion string // Specific chart version to use in `helm upgrade`
|
||||
DryRun bool // Pass --dry-run to applicable helm commands
|
||||
Wait bool // Pass --wait to applicable helm commands
|
||||
ReuseValues bool // Pass --reuse-values to `helm upgrade`
|
||||
KeepHistory bool // Pass --keep-history to `helm uninstall`
|
||||
Timeout string // Argument to pass to --timeout in applicable helm commands
|
||||
Chart string // Chart argument to use in applicable helm commands
|
||||
Release string // Release argument to use in applicable helm commands
|
||||
Force bool // Pass --force to applicable helm commands
|
||||
AtomicUpgrade bool // Pass --atomic to `helm upgrade`
|
||||
CleanupOnFail bool // Pass --cleanup-on-fail to `helm upgrade`
|
||||
LintStrictly bool // Pass --strict to `helm lint`
|
||||
|
||||
Stdout io.Writer `ignored:"true"`
|
||||
Stderr io.Writer `ignored:"true"`
|
||||
Stdout io.Writer
|
||||
Stderr io.Writer
|
||||
}
|
||||
|
||||
// NewConfig creates a Config and reads environment variables into it, accounting for several possible formats.
|
||||
func NewConfig(stdout, stderr io.Writer) (*Config, error) {
|
||||
func NewConfig(stdout, stderr io.Writer, argv ...string) (*Config, error) {
|
||||
cfg := Config{
|
||||
Stdout: stdout,
|
||||
Stderr: stderr,
|
||||
}
|
||||
if err := envconfig.Process("plugin", &cfg); err != nil {
|
||||
// cli doesn't support Destination for string slices, so we'll use bare
|
||||
// strings as an intermediate value and split them on commas ourselves.
|
||||
var addRepos, valuesFiles string
|
||||
app := &cli.App{
|
||||
Name: "drone-helm3",
|
||||
Action: func(*cli.Context) error { return nil },
|
||||
Flags: []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "mode",
|
||||
Destination: &cfg.Command,
|
||||
EnvVars: []string{"MODE", "PLUGIN_MODE", "HELM_COMMAND", "PLUGIN_HELM_COMMAND"},
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "drone-event",
|
||||
Destination: &cfg.DroneEvent,
|
||||
EnvVars: []string{"DRONE_BUILD_EVENT"},
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "update-dependencies",
|
||||
Destination: &cfg.UpdateDependencies,
|
||||
EnvVars: []string{"UPDATE_DEPENDENCIES", "PLUGIN_UPDATE_DEPENDENCIES"},
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "add-repos",
|
||||
Destination: &addRepos,
|
||||
EnvVars: []string{"ADD_REPOS", "PLUGIN_ADD_REPOS", "HELM_REPOS", "PLUGIN_HELM_REPOS"},
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "debug",
|
||||
Destination: &cfg.Debug,
|
||||
EnvVars: []string{"DEBUG", "PLUGIN_DEBUG"},
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "values",
|
||||
Destination: &cfg.Values,
|
||||
EnvVars: []string{"VALUES", "PLUGIN_VALUES"},
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "string-values",
|
||||
Destination: &cfg.StringValues,
|
||||
EnvVars: []string{"STRING_VALUES", "PLUGIN_STRING_VALUES"},
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "values-files",
|
||||
Destination: &valuesFiles,
|
||||
EnvVars: []string{"VALUES_FILES", "PLUGIN_VALUES_FILES"},
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "namespace",
|
||||
Destination: &cfg.Namespace,
|
||||
EnvVars: []string{"NAMESPACE", "PLUGIN_NAMESPACE"},
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "kube-token",
|
||||
Destination: &cfg.KubeToken,
|
||||
EnvVars: []string{"KUBE_TOKEN", "PLUGIN_KUBE_TOKEN", "KUBERNETES_TOKEN", "PLUGIN_KUBERNETES_TOKEN"},
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "skip-tls-verify",
|
||||
Destination: &cfg.SkipTLSVerify,
|
||||
EnvVars: []string{"SKIP_TLS_VERIFY", "PLUGIN_SKIP_TLS_VERIFY"},
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "kube-certificate",
|
||||
Destination: &cfg.Certificate,
|
||||
EnvVars: []string{"KUBE_CERTIFICATE", "PLUGIN_KUBE_CERTIFICATE", "KUBERNETES_CERTIFICATE", "PLUGIN_KUBERNETES_CERTIFICATE"},
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "kube-api-server",
|
||||
Destination: &cfg.APIServer,
|
||||
EnvVars: []string{"KUBE_API_SERVER", "PLUGIN_KUBE_API_SERVER", "API_SERVER", "PLUGIN_API_SERVER"},
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "service-account",
|
||||
Destination: &cfg.ServiceAccount,
|
||||
EnvVars: []string{"KUBE_SERVICE_ACCOUNT", "PLUGIN_KUBE_SERVICE_ACCOUNT", "SERVICE_ACCOUNT", "PLUGIN_SERVICE_ACCOUNT"},
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "chart-version",
|
||||
Destination: &cfg.ChartVersion,
|
||||
EnvVars: []string{"CHART_VERSION", "PLUGIN_CHART_VERSION"},
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "dry-run",
|
||||
Destination: &cfg.DryRun,
|
||||
EnvVars: []string{"DRY_RUN", "PLUGIN_DRY_RUN"},
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "wait-for-upgrade",
|
||||
Destination: &cfg.Wait,
|
||||
EnvVars: []string{"WAIT_FOR_UPGRADE", "PLUGIN_WAIT_FOR_UPGRADE", "WAIT", "PLUGIN_WAIT"},
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "reuse-values",
|
||||
Destination: &cfg.ReuseValues,
|
||||
EnvVars: []string{"REUSE_VALUES", "PLUGIN_REUSE_VALUES"},
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "keep-history",
|
||||
Destination: &cfg.KeepHistory,
|
||||
EnvVars: []string{"KEEP_HISTORY", "PLUGIN_KEEP_HISTORY"},
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "timeout",
|
||||
Destination: &cfg.Timeout,
|
||||
EnvVars: []string{"TIMEOUT", "PLUGIN_TIMEOUT"},
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "chart",
|
||||
Destination: &cfg.Chart,
|
||||
EnvVars: []string{"CHART", "PLUGIN_CHART"},
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "release",
|
||||
Destination: &cfg.Release,
|
||||
EnvVars: []string{"RELEASE", "PLUGIN_RELEASE"},
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "force-upgrade",
|
||||
Destination: &cfg.Force,
|
||||
EnvVars: []string{"FORCE_UPGRADE", "PLUGIN_FORCE_UPGRADE", "FORCE", "PLUGIN_FORCE"},
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "atomic-upgrade",
|
||||
Destination: &cfg.AtomicUpgrade,
|
||||
EnvVars: []string{"ATOMIC_UPGRADE", "PLUGIN_ATOMIC_UPGRADE"},
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "cleanup-failed-upgrade",
|
||||
Destination: &cfg.CleanupOnFail,
|
||||
EnvVars: []string{"CLEANUP_FAILED_UPGRADE", "PLUGIN_CLEANUP_FAILED_UPGRADE"},
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "lint-strictly",
|
||||
Destination: &cfg.LintStrictly,
|
||||
EnvVars: []string{"LINT_STRICTLY", "PLUGIN_LINT_STRICTLY"},
|
||||
},
|
||||
},
|
||||
}
|
||||
if err := app.Run(argv); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := envconfig.Process("", &cfg); err != nil {
|
||||
return nil, err
|
||||
if addRepos != "" {
|
||||
cfg.AddRepos = strings.Split(addRepos, ",")
|
||||
}
|
||||
if valuesFiles != "" {
|
||||
cfg.ValuesFiles = strings.Split(valuesFiles, ",")
|
||||
}
|
||||
|
||||
if justNumbers.MatchString(cfg.Timeout) {
|
||||
|
||||
@@ -20,60 +20,308 @@ func TestConfigTestSuite(t *testing.T) {
|
||||
}
|
||||
|
||||
func (suite *ConfigTestSuite) TestNewConfigWithPluginPrefix() {
|
||||
suite.unsetenv("HELM_COMMAND")
|
||||
suite.unsetenv("UPDATE_DEPENDENCIES")
|
||||
suite.unsetenv("DEBUG")
|
||||
stdout := strings.Builder{}
|
||||
stderr := strings.Builder{}
|
||||
for _, varname := range []string{
|
||||
"MODE",
|
||||
"DRONE_BUILD_EVENT",
|
||||
"HELM_COMMAND",
|
||||
"PLUGIN_HELM_COMMAND",
|
||||
"UPDATE_DEPENDENCIES",
|
||||
"ADD_REPOS",
|
||||
"HELM_REPOS",
|
||||
"PLUGIN_HELM_REPOS",
|
||||
"DEBUG",
|
||||
"VALUES",
|
||||
"STRING_VALUES",
|
||||
"VALUES_FILES",
|
||||
"NAMESPACE",
|
||||
"KUBE_TOKEN",
|
||||
"KUBERNETES_TOKEN",
|
||||
"PLUGIN_KUBERNETES_TOKEN",
|
||||
"SKIP_TLS_VERIFY",
|
||||
"KUBE_CERTIFICATE",
|
||||
"KUBERNETES_CERTIFICATE",
|
||||
"PLUGIN_KUBERNETES_CERTIFICATE",
|
||||
"KUBE_API_SERVER",
|
||||
"API_SERVER",
|
||||
"PLUGIN_API_SERVER",
|
||||
"KUBE_SERVICE_ACCOUNT",
|
||||
"SERVICE_ACCOUNT",
|
||||
"PLUGIN_SERVICE_ACCOUNT",
|
||||
"CHART_VERSION",
|
||||
"DRY_RUN",
|
||||
"WAIT_FOR_UPGRADE",
|
||||
"WAIT",
|
||||
"PLUGIN_WAIT",
|
||||
"REUSE_VALUES",
|
||||
"KEEP_HISTORY",
|
||||
"TIMEOUT",
|
||||
"CHART",
|
||||
"RELEASE",
|
||||
"FORCE",
|
||||
"FORCE_UPGRADE",
|
||||
"PLUGIN_FORCE_UPGRADE",
|
||||
"ATOMIC_UPGRADE",
|
||||
"CLEANUP_FAILED_UPGRADE",
|
||||
"LINT_STRICTLY",
|
||||
} {
|
||||
suite.unsetenv(varname)
|
||||
}
|
||||
|
||||
suite.setenv("PLUGIN_HELM_COMMAND", "execute order 66")
|
||||
suite.setenv("PLUGIN_MODE", "upgrade")
|
||||
suite.setenv("PLUGIN_UPDATE_DEPENDENCIES", "true")
|
||||
suite.setenv("PLUGIN_ADD_REPOS", "foo=http://bar,goo=http://baz")
|
||||
suite.setenv("PLUGIN_DEBUG", "true")
|
||||
suite.setenv("PLUGIN_VALUES", "dog=husky")
|
||||
suite.setenv("PLUGIN_STRING_VALUES", "version=1.0")
|
||||
suite.setenv("PLUGIN_VALUES_FILES", "underrides.yml,overrides.yml")
|
||||
suite.setenv("PLUGIN_NAMESPACE", "myapp")
|
||||
suite.setenv("PLUGIN_KUBE_TOKEN", "cGxlYXNlIHNpciwgbGV0IG1lIGlu")
|
||||
suite.setenv("PLUGIN_SKIP_TLS_VERIFY", "true")
|
||||
suite.setenv("PLUGIN_KUBE_CERTIFICATE", "SSBhbSB0b3RhbGx5IHRoZSBzZXJ2ZXIgeW91IHdhbnQ=")
|
||||
suite.setenv("PLUGIN_KUBE_API_SERVER", "http://my.kube/cluster")
|
||||
suite.setenv("PLUGIN_KUBE_SERVICE_ACCOUNT", "deploybot")
|
||||
suite.setenv("PLUGIN_CHART_VERSION", "six")
|
||||
suite.setenv("PLUGIN_DRY_RUN", "true")
|
||||
suite.setenv("PLUGIN_WAIT_FOR_UPGRADE", "true")
|
||||
suite.setenv("PLUGIN_REUSE_VALUES", "true")
|
||||
suite.setenv("PLUGIN_KEEP_HISTORY", "true")
|
||||
suite.setenv("PLUGIN_TIMEOUT", "5m20s")
|
||||
suite.setenv("PLUGIN_CHART", "./helm/myapp/")
|
||||
suite.setenv("PLUGIN_RELEASE", "my_app")
|
||||
suite.setenv("PLUGIN_FORCE_UPGRADE", "true")
|
||||
suite.setenv("PLUGIN_ATOMIC_UPGRADE", "true")
|
||||
suite.setenv("PLUGIN_CLEANUP_FAILED_UPGRADE", "true")
|
||||
suite.setenv("PLUGIN_LINT_STRICTLY", "true")
|
||||
|
||||
cfg, err := NewConfig(&strings.Builder{}, &strings.Builder{})
|
||||
cfg, err := NewConfig(&stdout, &stderr, "test")
|
||||
suite.Require().NoError(err)
|
||||
|
||||
suite.Equal("execute order 66", cfg.Command)
|
||||
suite.True(cfg.UpdateDependencies)
|
||||
suite.True(cfg.Debug)
|
||||
want := Config{
|
||||
Command: "upgrade",
|
||||
DroneEvent: "",
|
||||
UpdateDependencies: true,
|
||||
AddRepos: []string{"foo=http://bar", "goo=http://baz"},
|
||||
Debug: true,
|
||||
Values: "dog=husky",
|
||||
StringValues: "version=1.0",
|
||||
ValuesFiles: []string{"underrides.yml", "overrides.yml"},
|
||||
Namespace: "myapp",
|
||||
KubeToken: "cGxlYXNlIHNpciwgbGV0IG1lIGlu",
|
||||
SkipTLSVerify: true,
|
||||
Certificate: "SSBhbSB0b3RhbGx5IHRoZSBzZXJ2ZXIgeW91IHdhbnQ=",
|
||||
APIServer: "http://my.kube/cluster",
|
||||
ServiceAccount: "deploybot",
|
||||
ChartVersion: "six",
|
||||
DryRun: true,
|
||||
Wait: true,
|
||||
ReuseValues: true,
|
||||
KeepHistory: true,
|
||||
Timeout: "5m20s",
|
||||
Chart: "./helm/myapp/",
|
||||
Release: "my_app",
|
||||
Force: true,
|
||||
AtomicUpgrade: true,
|
||||
CleanupOnFail: true,
|
||||
LintStrictly: true,
|
||||
Stdout: &stdout,
|
||||
Stderr: &stderr,
|
||||
}
|
||||
|
||||
suite.Equal(&want, cfg)
|
||||
}
|
||||
|
||||
func (suite *ConfigTestSuite) TestNewConfigWithNoPrefix() {
|
||||
suite.unsetenv("PLUGIN_HELM_COMMAND")
|
||||
suite.unsetenv("PLUGIN_UPDATE_DEPENDENCIES")
|
||||
suite.unsetenv("PLUGIN_DEBUG")
|
||||
stdout := strings.Builder{}
|
||||
stderr := strings.Builder{}
|
||||
for _, varname := range []string{
|
||||
"PLUGIN_MODE",
|
||||
"PLUGIN_HELM_COMMAND",
|
||||
"HELM_COMMAND",
|
||||
"PLUGIN_UPDATE_DEPENDENCIES",
|
||||
"PLUGIN_ADD_REPOS",
|
||||
"PLUGIN_HELM_REPOS",
|
||||
"HELM_REPOS",
|
||||
"PLUGIN_DEBUG",
|
||||
"PLUGIN_VALUES",
|
||||
"PLUGIN_STRING_VALUES",
|
||||
"PLUGIN_VALUES_FILES",
|
||||
"PLUGIN_NAMESPACE",
|
||||
"PLUGIN_KUBE_TOKEN",
|
||||
"PLUGIN_KUBERNETES_TOKEN",
|
||||
"KUBERNETES_TOKEN",
|
||||
"PLUGIN_SKIP_TLS_VERIFY",
|
||||
"PLUGIN_KUBE_CERTIFICATE",
|
||||
"PLUGIN_KUBERNETES_CERTIFICATE",
|
||||
"KUBERNETES_CERTIFICATE",
|
||||
"PLUGIN_KUBE_API_SERVER",
|
||||
"PLUGIN_API_SERVER",
|
||||
"API_SERVER",
|
||||
"PLUGIN_KUBE_SERVICE_ACCOUNT",
|
||||
"PLUGIN_SERVICE_ACCOUNT",
|
||||
"SERVICE_ACCOUNT",
|
||||
"PLUGIN_CHART_VERSION",
|
||||
"PLUGIN_DRY_RUN",
|
||||
"PLUGIN_WAIT_FOR_UPGRADE",
|
||||
"PLUGIN_WAIT",
|
||||
"WAIT",
|
||||
"PLUGIN_REUSE_VALUES",
|
||||
"PLUGIN_KEEP_HISTORY",
|
||||
"PLUGIN_TIMEOUT",
|
||||
"PLUGIN_CHART",
|
||||
"PLUGIN_RELEASE",
|
||||
"PLUGIN_FORCE",
|
||||
"PLUGIN_FORCE_UPGRADE",
|
||||
"FORCE_UPGRADE",
|
||||
"PLUGIN_ATOMIC_UPGRADE",
|
||||
"PLUGIN_CLEANUP_FAILED_UPGRADE",
|
||||
"PLUGIN_LINT_STRICTLY",
|
||||
} {
|
||||
suite.unsetenv(varname)
|
||||
}
|
||||
|
||||
suite.setenv("HELM_COMMAND", "execute order 66")
|
||||
suite.setenv("MODE", "upgrade")
|
||||
suite.setenv("DRONE_BUILD_EVENT", "tag")
|
||||
suite.setenv("UPDATE_DEPENDENCIES", "true")
|
||||
suite.setenv("ADD_REPOS", "foo=http://bar,goo=http://baz")
|
||||
suite.setenv("DEBUG", "true")
|
||||
suite.setenv("VALUES", "dog=husky")
|
||||
suite.setenv("STRING_VALUES", "version=1.0")
|
||||
suite.setenv("VALUES_FILES", "underrides.yml,overrides.yml")
|
||||
suite.setenv("NAMESPACE", "myapp")
|
||||
suite.setenv("KUBE_TOKEN", "cGxlYXNlIHNpciwgbGV0IG1lIGlu")
|
||||
suite.setenv("SKIP_TLS_VERIFY", "true")
|
||||
suite.setenv("KUBE_CERTIFICATE", "SSBhbSB0b3RhbGx5IHRoZSBzZXJ2ZXIgeW91IHdhbnQ=")
|
||||
suite.setenv("KUBE_API_SERVER", "http://my.kube/cluster")
|
||||
suite.setenv("KUBE_SERVICE_ACCOUNT", "deploybot")
|
||||
suite.setenv("CHART_VERSION", "six")
|
||||
suite.setenv("DRY_RUN", "true")
|
||||
suite.setenv("WAIT_FOR_UPGRADE", "true")
|
||||
suite.setenv("REUSE_VALUES", "true")
|
||||
suite.setenv("KEEP_HISTORY", "true")
|
||||
suite.setenv("TIMEOUT", "5m20s")
|
||||
suite.setenv("CHART", "./helm/myapp/")
|
||||
suite.setenv("RELEASE", "my_app")
|
||||
suite.setenv("FORCE_UPGRADE", "true")
|
||||
suite.setenv("ATOMIC_UPGRADE", "true")
|
||||
suite.setenv("CLEANUP_FAILED_UPGRADE", "true")
|
||||
suite.setenv("LINT_STRICTLY", "true")
|
||||
|
||||
cfg, err := NewConfig(&strings.Builder{}, &strings.Builder{})
|
||||
cfg, err := NewConfig(&stdout, &stderr, "test")
|
||||
suite.Require().NoError(err)
|
||||
|
||||
suite.Equal("execute order 66", cfg.Command)
|
||||
suite.True(cfg.UpdateDependencies)
|
||||
suite.True(cfg.Debug)
|
||||
want := Config{
|
||||
Command: "upgrade",
|
||||
DroneEvent: "tag",
|
||||
UpdateDependencies: true,
|
||||
AddRepos: []string{"foo=http://bar", "goo=http://baz"},
|
||||
Debug: true,
|
||||
Values: "dog=husky",
|
||||
StringValues: "version=1.0",
|
||||
ValuesFiles: []string{"underrides.yml", "overrides.yml"},
|
||||
Namespace: "myapp",
|
||||
KubeToken: "cGxlYXNlIHNpciwgbGV0IG1lIGlu",
|
||||
SkipTLSVerify: true,
|
||||
Certificate: "SSBhbSB0b3RhbGx5IHRoZSBzZXJ2ZXIgeW91IHdhbnQ=",
|
||||
APIServer: "http://my.kube/cluster",
|
||||
ServiceAccount: "deploybot",
|
||||
ChartVersion: "six",
|
||||
DryRun: true,
|
||||
Wait: true,
|
||||
ReuseValues: true,
|
||||
KeepHistory: true,
|
||||
Timeout: "5m20s",
|
||||
Chart: "./helm/myapp/",
|
||||
Release: "my_app",
|
||||
Force: true,
|
||||
AtomicUpgrade: true,
|
||||
CleanupOnFail: true,
|
||||
LintStrictly: true,
|
||||
Stdout: &stdout,
|
||||
Stderr: &stderr,
|
||||
}
|
||||
|
||||
suite.Equal(&want, cfg)
|
||||
}
|
||||
|
||||
func (suite *ConfigTestSuite) TestNewConfigWithConflictingVariables() {
|
||||
suite.setenv("PLUGIN_HELM_COMMAND", "execute order 66")
|
||||
suite.setenv("HELM_COMMAND", "defend the jedi") // values from the `environment` block override those from `settings`
|
||||
suite.setenv("PLUGIN_MODE", "iambic")
|
||||
suite.setenv("MODE", "haiku") // values from the `environment` block override those from `settings`
|
||||
|
||||
cfg, err := NewConfig(&strings.Builder{}, &strings.Builder{})
|
||||
cfg, err := NewConfig(&strings.Builder{}, &strings.Builder{}, "test")
|
||||
suite.Require().NoError(err)
|
||||
|
||||
suite.Equal("defend the jedi", cfg.Command)
|
||||
suite.Equal("haiku", cfg.Command)
|
||||
}
|
||||
|
||||
func (suite *ConfigTestSuite) TestNewConfigInfersNumbersAreSeconds() {
|
||||
suite.setenv("PLUGIN_TIMEOUT", "42")
|
||||
cfg, err := NewConfig(&strings.Builder{}, &strings.Builder{})
|
||||
cfg, err := NewConfig(&strings.Builder{}, &strings.Builder{}, "test")
|
||||
suite.Require().NoError(err)
|
||||
suite.Equal("42s", cfg.Timeout)
|
||||
}
|
||||
|
||||
func (suite *ConfigTestSuite) TestNewConfigWithAliases() {
|
||||
for _, varname := range []string{
|
||||
"MODE",
|
||||
"ADD_REPOS",
|
||||
"KUBE_API_SERVER",
|
||||
"KUBE_SERVICE_ACCOUNT",
|
||||
"WAIT_FOR_UPGRADE",
|
||||
"FORCE_UPGRADE",
|
||||
"KUBE_TOKEN",
|
||||
"KUBE_CERTIFICATE",
|
||||
} {
|
||||
suite.unsetenv(varname)
|
||||
suite.unsetenv("PLUGIN_" + varname)
|
||||
}
|
||||
suite.setenv("PLUGIN_HELM_COMMAND", "beware the jabberwock")
|
||||
suite.setenv("PLUGIN_HELM_REPOS", "chortle=http://calloo.callay/frabjous/day")
|
||||
suite.setenv("PLUGIN_API_SERVER", "http://tumtum.tree")
|
||||
suite.setenv("PLUGIN_SERVICE_ACCOUNT", "tulgey")
|
||||
suite.setenv("PLUGIN_WAIT", "true")
|
||||
suite.setenv("PLUGIN_FORCE", "true")
|
||||
suite.setenv("PLUGIN_KUBERNETES_TOKEN", "Y29tZSB0byBteSBhcm1z")
|
||||
suite.setenv("PLUGIN_KUBERNETES_CERTIFICATE", "d2l0aCBpdHMgaGVhZA==")
|
||||
|
||||
cfg, err := NewConfig(&strings.Builder{}, &strings.Builder{}, "test")
|
||||
suite.Require().NoError(err)
|
||||
suite.Equal("beware the jabberwock", cfg.Command)
|
||||
suite.Equal([]string{"chortle=http://calloo.callay/frabjous/day"}, cfg.AddRepos)
|
||||
suite.Equal("http://tumtum.tree", cfg.APIServer)
|
||||
suite.Equal("tulgey", cfg.ServiceAccount)
|
||||
suite.True(cfg.Wait, "Wait should be aliased")
|
||||
suite.True(cfg.Force, "Force should be aliased")
|
||||
suite.Equal("Y29tZSB0byBteSBhcm1z", cfg.KubeToken, "KubeToken should be aliased")
|
||||
suite.Equal("d2l0aCBpdHMgaGVhZA==", cfg.Certificate, "Certificate should be aliased")
|
||||
}
|
||||
|
||||
func (suite *ConfigTestSuite) TestAliasedSettingWithoutPluginPrefix() {
|
||||
suite.unsetenv("FORCE_UPGRADE")
|
||||
suite.unsetenv("PLUGIN_FORCE_UPGRADE")
|
||||
suite.unsetenv("PLUGIN_FORCE")
|
||||
suite.setenv("FORCE", "true")
|
||||
|
||||
cfg, err := NewConfig(&strings.Builder{}, &strings.Builder{}, "test")
|
||||
suite.Require().NoError(err)
|
||||
suite.True(cfg.Force)
|
||||
}
|
||||
|
||||
func (suite *ConfigTestSuite) TestNewConfigWithAliasConflicts() {
|
||||
suite.unsetenv("FORCE_UPGRADE")
|
||||
suite.setenv("PLUGIN_FORCE", "true")
|
||||
suite.setenv("PLUGIN_FORCE_UPGRADE", "false") // should override even when set to the zero value
|
||||
|
||||
cfg, err := NewConfig(&strings.Builder{}, &strings.Builder{}, "test")
|
||||
suite.NoError(err)
|
||||
suite.False(cfg.Force, "official names should override alias names")
|
||||
}
|
||||
|
||||
func (suite *ConfigTestSuite) TestNewConfigSetsWriters() {
|
||||
stdout := &strings.Builder{}
|
||||
stderr := &strings.Builder{}
|
||||
cfg, err := NewConfig(stdout, stderr)
|
||||
cfg, err := NewConfig(stdout, stderr, "test")
|
||||
suite.Require().NoError(err)
|
||||
|
||||
suite.Equal(stdout, cfg.Stdout)
|
||||
@@ -90,7 +338,7 @@ func (suite *ConfigTestSuite) TestDeprecatedSettingWarnings() {
|
||||
suite.setenv("UPGRADE", "") // entries should cause warnings even when set to empty string
|
||||
|
||||
stderr := &strings.Builder{}
|
||||
_, err := NewConfig(&strings.Builder{}, stderr)
|
||||
_, err := NewConfig(&strings.Builder{}, stderr, "test")
|
||||
suite.NoError(err)
|
||||
|
||||
for _, varname := range deprecatedVars {
|
||||
@@ -100,11 +348,11 @@ func (suite *ConfigTestSuite) TestDeprecatedSettingWarnings() {
|
||||
|
||||
func (suite *ConfigTestSuite) TestLogDebug() {
|
||||
suite.setenv("DEBUG", "true")
|
||||
suite.setenv("HELM_COMMAND", "upgrade")
|
||||
suite.setenv("MODE", "upgrade")
|
||||
|
||||
stderr := strings.Builder{}
|
||||
stdout := strings.Builder{}
|
||||
_, err := NewConfig(&stdout, &stderr)
|
||||
_, err := NewConfig(&stdout, &stderr, "test")
|
||||
suite.Require().NoError(err)
|
||||
|
||||
suite.Equal("", stdout.String())
|
||||
|
||||
@@ -30,9 +30,6 @@ func NewPlan(cfg Config) (*Plan, error) {
|
||||
cfg: cfg,
|
||||
runCfg: run.Config{
|
||||
Debug: cfg.Debug,
|
||||
Values: cfg.Values,
|
||||
StringValues: cfg.StringValues,
|
||||
ValuesFiles: cfg.ValuesFiles,
|
||||
Namespace: cfg.Namespace,
|
||||
Stdout: cfg.Stdout,
|
||||
Stderr: cfg.Stderr,
|
||||
@@ -106,9 +103,14 @@ var upgrade = func(cfg Config) []Step {
|
||||
ChartVersion: cfg.ChartVersion,
|
||||
DryRun: cfg.DryRun,
|
||||
Wait: cfg.Wait,
|
||||
Values: cfg.Values,
|
||||
StringValues: cfg.StringValues,
|
||||
ValuesFiles: cfg.ValuesFiles,
|
||||
ReuseValues: cfg.ReuseValues,
|
||||
Timeout: cfg.Timeout,
|
||||
Force: cfg.Force,
|
||||
Atomic: cfg.AtomicUpgrade,
|
||||
CleanupOnFail: cfg.CleanupOnFail,
|
||||
})
|
||||
|
||||
return steps
|
||||
@@ -122,6 +124,7 @@ var uninstall = func(cfg Config) []Step {
|
||||
steps = append(steps, &run.Uninstall{
|
||||
Release: cfg.Release,
|
||||
DryRun: cfg.DryRun,
|
||||
KeepHistory: cfg.KeepHistory,
|
||||
})
|
||||
|
||||
return steps
|
||||
@@ -134,6 +137,10 @@ var lint = func(cfg Config) []Step {
|
||||
}
|
||||
steps = append(steps, &run.Lint{
|
||||
Chart: cfg.Chart,
|
||||
Values: cfg.Values,
|
||||
StringValues: cfg.StringValues,
|
||||
ValuesFiles: cfg.ValuesFiles,
|
||||
Strict: cfg.LintStrictly,
|
||||
})
|
||||
|
||||
return steps
|
||||
|
||||
@@ -35,9 +35,6 @@ func (suite *PlanTestSuite) TestNewPlan() {
|
||||
cfg := Config{
|
||||
Command: "help",
|
||||
Debug: false,
|
||||
Values: "steadfastness,forthrightness",
|
||||
StringValues: "tensile_strength,flexibility",
|
||||
ValuesFiles: []string{"/root/price_inventory.yml"},
|
||||
Namespace: "outer",
|
||||
Stdout: &stdout,
|
||||
Stderr: &stderr,
|
||||
@@ -45,9 +42,6 @@ func (suite *PlanTestSuite) TestNewPlan() {
|
||||
|
||||
runCfg := run.Config{
|
||||
Debug: false,
|
||||
Values: "steadfastness,forthrightness",
|
||||
StringValues: "tensile_strength,flexibility",
|
||||
ValuesFiles: []string{"/root/price_inventory.yml"},
|
||||
Namespace: "outer",
|
||||
Stdout: &stdout,
|
||||
Stderr: &stderr,
|
||||
@@ -139,11 +133,16 @@ func (suite *PlanTestSuite) TestUpgrade() {
|
||||
ChartVersion: "seventeen",
|
||||
DryRun: true,
|
||||
Wait: true,
|
||||
Values: "steadfastness,forthrightness",
|
||||
StringValues: "tensile_strength,flexibility",
|
||||
ValuesFiles: []string{"/root/price_inventory.yml"},
|
||||
ReuseValues: true,
|
||||
Timeout: "go sit in the corner",
|
||||
Chart: "billboard_top_100",
|
||||
Release: "post_malone_circles",
|
||||
Force: true,
|
||||
AtomicUpgrade: true,
|
||||
CleanupOnFail: true,
|
||||
}
|
||||
|
||||
steps := upgrade(cfg)
|
||||
@@ -159,9 +158,14 @@ func (suite *PlanTestSuite) TestUpgrade() {
|
||||
ChartVersion: cfg.ChartVersion,
|
||||
DryRun: true,
|
||||
Wait: cfg.Wait,
|
||||
Values: "steadfastness,forthrightness",
|
||||
StringValues: "tensile_strength,flexibility",
|
||||
ValuesFiles: []string{"/root/price_inventory.yml"},
|
||||
ReuseValues: cfg.ReuseValues,
|
||||
Timeout: cfg.Timeout,
|
||||
Force: cfg.Force,
|
||||
Atomic: true,
|
||||
CleanupOnFail: true,
|
||||
}
|
||||
|
||||
suite.Equal(expected, upgrade)
|
||||
@@ -198,6 +202,7 @@ func (suite *PlanTestSuite) TestUninstall() {
|
||||
DryRun: true,
|
||||
Timeout: "think about what you did",
|
||||
Release: "jetta_id_love_to_change_the_world",
|
||||
KeepHistory: true,
|
||||
}
|
||||
|
||||
steps := uninstall(cfg)
|
||||
@@ -222,6 +227,7 @@ func (suite *PlanTestSuite) TestUninstall() {
|
||||
expected = &run.Uninstall{
|
||||
Release: "jetta_id_love_to_change_the_world",
|
||||
DryRun: true,
|
||||
KeepHistory: true,
|
||||
}
|
||||
suite.Equal(expected, actual)
|
||||
}
|
||||
@@ -300,6 +306,10 @@ func (suite *PlanTestSuite) TestAddRepos() {
|
||||
func (suite *PlanTestSuite) TestLint() {
|
||||
cfg := Config{
|
||||
Chart: "./flow",
|
||||
Values: "steadfastness,forthrightness",
|
||||
StringValues: "tensile_strength,flexibility",
|
||||
ValuesFiles: []string{"/root/price_inventory.yml"},
|
||||
LintStrictly: true,
|
||||
}
|
||||
|
||||
steps := lint(cfg)
|
||||
@@ -307,6 +317,10 @@ func (suite *PlanTestSuite) TestLint() {
|
||||
|
||||
want := &run.Lint{
|
||||
Chart: "./flow",
|
||||
Values: "steadfastness,forthrightness",
|
||||
StringValues: "tensile_strength,flexibility",
|
||||
ValuesFiles: []string{"/root/price_inventory.yml"},
|
||||
Strict: true,
|
||||
}
|
||||
suite.Equal(want, steps[0])
|
||||
}
|
||||
@@ -356,7 +370,7 @@ func (suite *PlanTestSuite) TestDeterminePlanUninstallCommand() {
|
||||
suite.Same(&uninstall, stepsMaker)
|
||||
}
|
||||
|
||||
// helm_command = delete is provided as an alias for backwards-compatibility with drone-helm
|
||||
// helm_command = delete is provided as an alias for backward-compatibility with drone-helm
|
||||
func (suite *PlanTestSuite) TestDeterminePlanDeleteCommand() {
|
||||
cfg := Config{
|
||||
Command: "delete",
|
||||
|
||||
@@ -7,9 +7,6 @@ import (
|
||||
// Config contains configuration applicable to all helm commands
|
||||
type Config struct {
|
||||
Debug bool
|
||||
Values string
|
||||
StringValues string
|
||||
ValuesFiles []string
|
||||
Namespace string
|
||||
Stdout io.Writer
|
||||
Stderr io.Writer
|
||||
|
||||
@@ -7,6 +7,10 @@ import (
|
||||
// Lint is an execution step that calls `helm lint` when executed.
|
||||
type Lint struct {
|
||||
Chart string
|
||||
Values string
|
||||
StringValues string
|
||||
ValuesFiles []string
|
||||
Strict bool
|
||||
cmd cmd
|
||||
}
|
||||
|
||||
@@ -32,15 +36,18 @@ func (l *Lint) Prepare(cfg Config) error {
|
||||
|
||||
args = append(args, "lint")
|
||||
|
||||
if cfg.Values != "" {
|
||||
args = append(args, "--set", cfg.Values)
|
||||
if l.Values != "" {
|
||||
args = append(args, "--set", l.Values)
|
||||
}
|
||||
if cfg.StringValues != "" {
|
||||
args = append(args, "--set-string", cfg.StringValues)
|
||||
if l.StringValues != "" {
|
||||
args = append(args, "--set-string", l.StringValues)
|
||||
}
|
||||
for _, vFile := range cfg.ValuesFiles {
|
||||
for _, vFile := range l.ValuesFiles {
|
||||
args = append(args, "--values", vFile)
|
||||
}
|
||||
if l.Strict {
|
||||
args = append(args, "--strict")
|
||||
}
|
||||
|
||||
args = append(args, l.Chart)
|
||||
|
||||
|
||||
@@ -80,14 +80,14 @@ func (suite *LintTestSuite) TestPrepareRequiresChart() {
|
||||
func (suite *LintTestSuite) TestPrepareWithLintFlags() {
|
||||
defer suite.ctrl.Finish()
|
||||
|
||||
cfg := Config{
|
||||
Values: "width=5",
|
||||
StringValues: "version=2.0",
|
||||
ValuesFiles: []string{"/usr/local/underrides", "/usr/local/overrides"},
|
||||
}
|
||||
cfg := Config{}
|
||||
|
||||
l := Lint{
|
||||
Chart: "./uk/top_40",
|
||||
Values: "width=5",
|
||||
StringValues: "version=2.0",
|
||||
ValuesFiles: []string{"/usr/local/underrides", "/usr/local/overrides"},
|
||||
Strict: true,
|
||||
}
|
||||
|
||||
command = func(path string, args ...string) cmd {
|
||||
@@ -97,6 +97,7 @@ func (suite *LintTestSuite) TestPrepareWithLintFlags() {
|
||||
"--set-string", "version=2.0",
|
||||
"--values", "/usr/local/underrides",
|
||||
"--values", "/usr/local/overrides",
|
||||
"--strict",
|
||||
"./uk/top_40"}, args)
|
||||
|
||||
return suite.mockCmd
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
type Uninstall struct {
|
||||
Release string
|
||||
DryRun bool
|
||||
KeepHistory bool
|
||||
cmd cmd
|
||||
}
|
||||
|
||||
@@ -36,6 +37,9 @@ func (u *Uninstall) Prepare(cfg Config) error {
|
||||
if u.DryRun {
|
||||
args = append(args, "--dry-run")
|
||||
}
|
||||
if u.KeepHistory {
|
||||
args = append(args, "--keep-history")
|
||||
}
|
||||
|
||||
args = append(args, u.Release)
|
||||
|
||||
|
||||
@@ -81,6 +81,21 @@ func (suite *UninstallTestSuite) TestPrepareDryRunFlag() {
|
||||
suite.Equal(expected, suite.actualArgs)
|
||||
}
|
||||
|
||||
func (suite *UninstallTestSuite) TestPrepareKeepHistoryFlag() {
|
||||
u := Uninstall{
|
||||
Release: "perturbator_sentient",
|
||||
KeepHistory: true,
|
||||
}
|
||||
cfg := Config{}
|
||||
|
||||
suite.mockCmd.EXPECT().Stdout(gomock.Any()).AnyTimes()
|
||||
suite.mockCmd.EXPECT().Stderr(gomock.Any()).AnyTimes()
|
||||
|
||||
suite.NoError(u.Prepare(cfg))
|
||||
expected := []string{"uninstall", "--keep-history", "perturbator_sentient"}
|
||||
suite.Equal(expected, suite.actualArgs)
|
||||
}
|
||||
|
||||
func (suite *UninstallTestSuite) TestPrepareNamespaceFlag() {
|
||||
u := Uninstall{
|
||||
Release: "carly_simon_run_away_with_me",
|
||||
|
||||
@@ -12,9 +12,14 @@ type Upgrade struct {
|
||||
ChartVersion string
|
||||
DryRun bool
|
||||
Wait bool
|
||||
Values string
|
||||
StringValues string
|
||||
ValuesFiles []string
|
||||
ReuseValues bool
|
||||
Timeout string
|
||||
Force bool
|
||||
Atomic bool
|
||||
CleanupOnFail bool
|
||||
|
||||
cmd cmd
|
||||
}
|
||||
@@ -62,13 +67,19 @@ func (u *Upgrade) Prepare(cfg Config) error {
|
||||
if u.Force {
|
||||
args = append(args, "--force")
|
||||
}
|
||||
if cfg.Values != "" {
|
||||
args = append(args, "--set", cfg.Values)
|
||||
if u.Atomic {
|
||||
args = append(args, "--atomic")
|
||||
}
|
||||
if cfg.StringValues != "" {
|
||||
args = append(args, "--set-string", cfg.StringValues)
|
||||
if u.CleanupOnFail {
|
||||
args = append(args, "--cleanup-on-fail")
|
||||
}
|
||||
for _, vFile := range cfg.ValuesFiles {
|
||||
if u.Values != "" {
|
||||
args = append(args, "--set", u.Values)
|
||||
}
|
||||
if u.StringValues != "" {
|
||||
args = append(args, "--set-string", u.StringValues)
|
||||
}
|
||||
for _, vFile := range u.ValuesFiles {
|
||||
args = append(args, "--values", vFile)
|
||||
}
|
||||
|
||||
|
||||
@@ -91,20 +91,21 @@ func (suite *UpgradeTestSuite) TestPrepareWithUpgradeFlags() {
|
||||
u := Upgrade{
|
||||
Chart: "hot_ac",
|
||||
Release: "maroon_5_memories",
|
||||
ChartVersion: "radio_edit", //-version
|
||||
DryRun: true, //-run
|
||||
Wait: true, //-wait
|
||||
ReuseValues: true, //-values
|
||||
Timeout: "sit_in_the_corner", //-timeout
|
||||
Force: true, //-force
|
||||
}
|
||||
|
||||
cfg := Config{
|
||||
ChartVersion: "radio_edit",
|
||||
DryRun: true,
|
||||
Wait: true,
|
||||
Values: "age=35",
|
||||
StringValues: "height=5ft10in",
|
||||
ValuesFiles: []string{"/usr/local/stats", "/usr/local/grades"},
|
||||
ReuseValues: true,
|
||||
Timeout: "sit_in_the_corner",
|
||||
Force: true,
|
||||
Atomic: true,
|
||||
CleanupOnFail: true,
|
||||
}
|
||||
|
||||
cfg := Config{}
|
||||
|
||||
command = func(path string, args ...string) cmd {
|
||||
suite.Equal(helmBin, path)
|
||||
suite.Equal([]string{"upgrade", "--install",
|
||||
@@ -114,6 +115,8 @@ func (suite *UpgradeTestSuite) TestPrepareWithUpgradeFlags() {
|
||||
"--reuse-values",
|
||||
"--timeout", "sit_in_the_corner",
|
||||
"--force",
|
||||
"--atomic",
|
||||
"--cleanup-on-fail",
|
||||
"--set", "age=35",
|
||||
"--set-string", "height=5ft10in",
|
||||
"--values", "/usr/local/stats",
|
||||
|
||||
Reference in New Issue
Block a user