Commit Graph

48 Commits

Author SHA1 Message Date
Dmitry Chepurovskiy aa5be82834
Make helmfile respect signals send by kill command (not only Ctrl+C in terminal) (#750)
Fixes #746 

Signed-off-by: Dmitry Chepurovskiy <me@dm3ch.net>
Signed-off-by: yxxhero <aiopsclub@163.com>
Co-authored-by: yxxhero <aiopsclub@163.com>
2023-04-29 15:25:29 +09:00
yxxhero 522392c08c
fix get template func (#721) 2023-03-03 06:37:22 +08:00
yxxhero f629ee1ae6
bump vals to v0.22.0 (#703)
Signed-off-by: yxxhero <aiopsclub@163.com>
2023-02-17 14:09:49 +08:00
yxxhero db5c2a52d6
Enhance tpl func test (#619)
enfore tpl func test

Signed-off-by: yxxhero <aiopsclub@163.com>
2023-01-07 11:04:52 +08:00
Yusuke Kuoka 4688cf0132
Use gopkg.in/yaml.v2 for Helmfile v0.x (#609)
This should fix #435 for Helmfile v0.x releases since the next v0.150.0.
We introduce a new envvar to opt-in to the new YAML library, so that you can give it a shot before upgrading your Helmfile to v1. The same envvar can be used to opt-out of the new YAML library after you upgrade to Helmfile v1, giving you a more flexible migration story.

Signed-off-by: Yusuke Kuoka <ykuoka@gmail.com>
2023-01-04 18:17:24 +09:00
Yusuke Kuoka 6664f01596
Use goccy/go-yaml for v1 / Prep bringing back go-yaml v2 for v0.x (#604)
This is a successor to #596. We need a smooth migration path from `gopkg.in/yaml.v2`, and this pull request moves it forward with `goccy/go-yaml` instead of `gopkg.in/yaml.v3`. Merging this unblocks users stuck in Helmfile v0.146.x or earlier due to #435, so that they can upgrade to 0.147.x or greater without updating their helmfile configs.

We previously tried to upgrade to `yaml.v3` (https://github.com/helmfile/helmfile/issues/394) in Helmfile v0.x, presuming it won't break anything. Apparently, it broke use-cases where you want to layer release's `values` field over three or more release templates and releases (#435).

We then tried to bring back `yaml.v2` for Helmfile v0.x and keep `yaml.v3` for the upcoming Helmfile v1. However, it failed due to incompatibility in the Unmarshaller interface between `yaml.v2` and `yaml.v3` (https://github.com/helmfile/helmfile/pull/596).

`goccy/go-yaml` is, from my observation, a well-maintained alternative to `yaml.v2`. One of its premises is that it enables us to swap the implementation from `gopkg.in/yaml.v2` to `goccy/go-yaml` just by replacing the import directive. It seems to use the same `Unmarshaller` interface as yaml.v2 too.

Once this PR gets merged, I'd like to follow-up with adding a new build-time variable and an envvar to set the proper default for the yaml parser Helmfile uses and the ability to switch the parser at runtime. All in all, the next Helmfile release, v0.150.0 will get reverted to use `gopkg.in/yaml.v2` by default which resolves #435.

New users who started using Helmfile since any of v0.148.0, v0.148.1, and v0.149.0 might be already relying on the new behavior, They might need to specify a new envvar to enable `goccy/go-yaml`.

Signed-off-by: yxxhero <aiopsclub@163.com>
Signed-off-by: yxxhero <aiopsclub@163.com>
Co-authored-by: yxxhero <aiopsclub@163.com>
2022-12-27 10:14:35 +09:00
yxxhero 36c91c5427
optimize lint logic (#586)
Signed-off-by: yxxhero <aiopsclub@163.com>
2022-12-18 08:39:45 +08:00
yxxhero 14ba7cd156 bump: upgrade gopkg.in/yaml.v2 to gopkg.in/yaml.v3
Signed-off-by: yxxhero <aiopsclub@163.com>
2022-10-03 05:24:51 +08:00
Arkaitz Jimenez cc33e7b7d8
Introduce Helmfile's own filesystem abstraction to correctly unit test some components (#307)
Use abstracted FS

Signed-off-by: Arkaitz Jimenez <arkaitzj@gmail.com>

Signed-off-by: Arkaitz Jimenez <arkaitzj@gmail.com>
2022-08-24 12:58:43 +09:00
Arkaitz Jimenez 4553efdcf1 Formatting
Signed-off-by: Arkaitz Jimenez <arkaitzj@gmail.com>
2022-08-16 16:25:24 +02:00
Arkaitz Jimenez 684be0af50 Missing context readDir, required for any template using readDir* functions
Signed-off-by: Arkaitz Jimenez <arkaitzj@gmail.com>
2022-08-16 16:25:24 +02:00
yxxhero 8690d63401 fix lint error
Signed-off-by: yxxhero <aiopsclub@163.com>
2022-08-13 07:40:32 +08:00
vasicvuk 68d7c5f6a4 Implement readDirEntries method
Signed-off-by: vasicvuk <vuk.vasic@asseco-see.rs>
2022-07-26 16:20:38 +02:00
yxxhero ac23def893 add Go lint
Signed-off-by: yxxhero <aiopsclub@163.com>
2022-07-16 20:21:11 +08:00
Eng Zer Jun ce3b81e2a1
test: use `T.Setenv` to set env vars in tests (#189)
This commit replaces `os.Setenv` with `t.Setenv` in tests. The
environment variable is automatically restored to its original value
when the test and all its subtests complete.

Reference: https://pkg.go.dev/testing#T.Setenv
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2022-06-30 09:15:34 +09:00
yxxhero 5bd5f72170
add unittest for text_renderer.go (#168)
Signed-off-by: yxxhero <aiopsclub@163.com>
2022-06-29 20:33:15 +09:00
Quan TRAN 577f54af7a
Introduce DISABLE_INSECURE_FEATURES to disable insecure command executions (#1)
* introduce DISABLE_INSECURE_FEATURES to disable insecure executions

Signed-off-by: Quan TRAN <account@itscaro.me>

* disable remote sources when DISABLE_INSECURE_FEATURES is set to "true"

Signed-off-by: Quan TRAN <account@itscaro.me>

* refactor envvar package

Signed-off-by: Quan TRAN <account@itscaro.me>

* (test) fix test fixtures

Signed-off-by: Quan TRAN <account@itscaro.me>

* use absolute path to avoid unit test failure

Signed-off-by: Quan TRAN <account@itscaro.me>

* Fix conflicts

Co-authored-by: Yusuke Kuoka <ykuoka@gmail.com>
2022-06-05 15:15:06 +09:00
yxxhero 33c66a6f46 add readfile e2e test
Signed-off-by: yxxhero <aiopsclub@163.com>
2022-05-24 07:50:08 +08:00
Yusuke Kuoka 281fe9bf59
Merge pull request #101 from austince/rename-module
Rename module to github.com/helmfile/helmfile
2022-05-22 15:19:16 +09:00
austin ce eb3484d4a8
Rename module to github.com/helmfile/helmfile
Also updates a few more references to the roboll/helmfile repository,
where possible.

Signed-off-by: austin ce <austin.cawley@gmail.com>
2022-05-18 10:05:07 -04:00
yxxhero 10c3eb61a5 fix issue in context_funcs.go
Signed-off-by: yxxhero <aiopsclub@163.com>
2022-05-17 17:37:47 +08:00
yxxhero d83e9214e6 rename execEnvs to envExec
Signed-off-by: yxxhero <aiopsclub@163.com>
2022-05-17 08:30:46 +08:00
yxxhero a320fccdd2 update unittest for execEnvs
Signed-off-by: yxxhero <aiopsclub@163.com>
2022-05-16 22:54:31 +08:00
yxxhero 1258c9ed10 add execEnvs
Signed-off-by: yxxhero <aiopsclub@163.com>
2022-05-14 09:59:08 +08:00
yxxhero 33f733026b remove cmd.Env set
Signed-off-by: yxxhero <aiopsclub@163.com>
2022-04-22 08:36:02 +08:00
yxxhero d26f83c460 add unittest for Exec and add feature that inherit the environment variables from the parent process for Exec
Signed-off-by: yxxhero <aiopsclub@163.com>
2022-04-21 19:29:32 +08:00
yxxhero b895f75198 add unittest for constants.go
Signed-off-by: yxxhero <aiopsclub@163.com>
2022-04-18 17:15:04 +08:00
yxxhero 5cb82ec3d1 add unittest for RequiredEnv func
Signed-off-by: yxxhero <aiopsclub@163.com>
2022-04-05 22:53:07 +08:00
yxxhero 303ef9cd80 remove ioutil usage in all project
Signed-off-by: yxxhero <aiopsclub@163.com>
2022-04-03 15:53:19 +08:00
Quan TRAN ed436ba68b
Add template function isFile (#2045)
* Add template function isFile

* Update context_funcs.go
2022-03-31 10:59:10 +09:00
Anton Bretting 2f04831817
Fix various golangci-lint errors (#2059) 2022-02-12 20:28:08 +09:00
Quan TRAN 766b03047c
Enable get() to be used with alias $.StateValues (#2081) 2022-02-09 09:18:46 +09:00
Yusuke Kuoka 061644c5d0
Fix readdir regression while merging (#2061)
Ref https://github.com/roboll/helmfile/pull/2058#issuecomment-1019439394
2022-01-23 20:37:46 +09:00
Nils 1d70130ab9
Fix ReadDir templating function to respect base path (#2058)
Ref https://github.com/roboll/helmfile/pull/1934#issuecomment-1018663764
2022-01-23 12:20:56 +09:00
Nils 753de35ee0
Add readDir as a templating function (#1934)
Adds a new templating function called `readDir`. With `readDir` users can read the contents of a specified directory and get a list of all contained files. This is useful when reading a bunch of files from a directory. The following example shows a snippet of a values file for configuring a Logstash deployment. Using only `readFile`, a user must specify each file by hand and adjust this list as the number of files to be read grows.
```yaml
logstash:
  configs:
    logstash.yml: |
      {{- tpl (readFile "config/logstash.yml.gotmpl") . | nindent 6 }}
    jvm.options: |
      {{- readFile "config/jvm.options" | nindent 6 }}
    pipelines.yml: |
      {{- readFile "config/pipelines.yml" | nindent 6 }}
  pipelines:
    beats-log4j.conf: |
      {{- readFile "config/pipelines/beats-log4j.conf" | nindent 6 }}
    nginx-access.conf: |
      {{- readFile "config/pipelines/nginx-access.conf" | nindent 6 }}
    nginx-error.conf: |
      {{- readFile "config/pipelines/nginx-error.conf" | nindent 6 }}
    syslog-logs.conf: |
      {{- readFile "config/pipelines/syslog-logs.conf" | nindent 6 }}
    tcp-logs.conf: |
      {{- readFile "config/pipelines/tcp-logs.conf" | nindent 6 }}
    udp-debug.conf: |
      {{- readFile "config/pipelines/udp-debug.conf" | nindent 6 }}
    udp-logs.conf: |
      {{- readFile "config/pipelines/udp-logs.conf" | nindent 6 }}
  certificates:
    ca.crt: |
      {{- readFile "config/certificates/ca.crt" | nindent 6 }}
    logstash.crt: |
      {{- readFile "config/certificates/logstash.crt" | nindent 6 }}
    logstash.key: |
      {{- readFile "config/certificates/logstash.key" | nindent 6 }}
```
With `readDir` the above snippet can be rewritten as follows:
```yaml
logstash:
  configs:
  {{- range readDir "config" }}
    {{ base . }}: |
      {{- if hasSuffix "gotmpl" . }}
          {{- tpl (readFile .) $ | nindent 6 }}
      {{- else }}
          {{- readFile . | nindent 6 }}
      {{- end }}
  {{- end }}
  pipelines:
  {{- range readDir "config/pipelines" }}
    {{ base . }}: |
      {{- readFile . | nindent 6 }}
  {{- end }}
  certificates:
  {{- range readDir "config/certificates" }}
    {{ base . }}: |
      {{- readFile . | nindent 6 }}
  {{- end }}
```
2022-01-10 17:22:24 +09:00
Yusuke Kuoka f614e8b1bf
feat: Helmfile renders *.yaml.gotmpl in a K8s manifests/kustomization directory (#1745)
Related to #494

This feature is mostly a built-in alternative to the `incubator/raw` chart without external dependency and has
access to helmfile's own template functions and template data.

The expected use-case of this feature is to add arbitrary K8s resources to your deployment.

Unlike the original issue raised in #494 this doesn't enable you to add arbitary resources to a release. That's another story. But this would be a good foundation for that, too.
2021-04-06 14:22:34 +09:00
Yoann Ciabaud 54eb73b423
Use ghodss/yaml for yaml marshaling & unmarshaling in template (#1556)
Fixes #1555

Co-authored-by: Yoann Ciabaud <yoann@linxo.com>
Co-authored-by: Yusuke Kuoka <ykuoka@gmail.com>
2020-12-13 11:03:20 +09:00
Johannes Alkjær 9d2c0d4285
Bump sprig to v3.1.0 and mergo 3.11 (#1456)
* Bump sprig to v3.1.0
test for mergeOverwrite

* Let mergo not (accidentally) try to merge unexported fields

This is also a good chance separate `HelmState` with the config loaded from YAML, which I had been wanting to do for a long time.

Co-authored-by: Johannes Alkjær <johannes.alkjaer@wunderman.com>
Co-authored-by: Yusuke Kuoka <ykuoka@gmail.com>
2020-09-04 09:58:54 +09:00
Yusuke Kuoka efd26f288a
Bump sprig to v3 (#1452)
Resolves #1294
Resolves #1447
2020-09-01 19:10:29 +09:00
KUOKA Yusuke 7db31846cf
fix: Do not include stderr content in result of `{{ exec }}` (#1298)
Seems like this was a regression since f676c61425 and #1159

Fixes #1258
2020-06-06 09:29:12 +09:00
Marcin Kaciuba b1190508b2
feat(template): added secret template function (#1221)
* feat(tmpl): added fetchSecretValue template function

This adds a tmpl `fetchSecretValue` and `expandSecretRefs` function by:
- Adding:
    - `expandSecretRefs` function in tmpl package that uses vals
    package to fetch secrets
    - `fetchSecretValue` function in tmpl package like below but for
    single string value
    - gomock for tests purpose
- Changing:
    - move init of vals package to function (so the same instance can be used for template values and rendering the whole template)

* doc(secret): added doc how to use new tmpl methods

Added example usage of `fetchSecretValue` and `expandSecretRefs`
2020-04-25 21:10:02 +09:00
RaymondKYLiu 7d11f5dedc
feat: add tmpl function `required` (#1188)
Co-authored-by: Raymond Liu (RD-TW) <raymond_liu@trend.com.tw>
2020-04-10 08:23:42 +09:00
KUOKA Yusuke f676c61425
feat: Better exec error reporting (#1159)
Enhances Helmfile to print more helpful message on error while calling `exec` template function.

Helmfile has been printing error messages like the below:

```
in ./helmfile.yaml: error during helmfile.yaml.part.0 parsing: template: stringTemplate:5:8: executing "stringTemplate" at <exec "./exectest.sha" (list)>: error calling exec: exit status 1
```

Adding captured stdout and stderr, with some indentation to make it readable, it now produces the following message on missing executable:

```
$ make build && ./helmfile build
go build
in ./helmfile.yaml: error during helmfile.yaml.part.0 parsing: template: stringTemplate:5:8: executing "stringTemplate" at <exec "./exectest.sha" (list)>: error calling exec: fork/exec ./exectest.sha: no such file or directory

COMMAND:
  ./exectest.sha

ERROR:
  fork/exec ./exectest.sha: no such file or directory
```

On non-zero exit status without output:

```
$ make build && ./helmfile build
go build
in ./helmfile.yaml: error during helmfile.yaml.part.0 parsing: template: stringTemplate:5:8: executing "stringTemplate" at <exec "./exectest.sh" (list)>: error calling exec: exit status 1

COMMAND:
  ./exectest.sh

ERROR:
  exit status 1
```

On non-zero exit status with output:

```
$ make build && ./helmfile build
go build
in ./helmfile.yaml: error during helmfile.yaml.part.0 parsing: template: stringTemplate:5:8: executing "stringTemplate" at <exec "./exectest.sh" (list)>: error calling exec: exit status 2

COMMAND:
  ./exectest.sh

ERROR:
  exit status 2

COMBINED OUTPUT:
  out1
  err1
```

Resolves #1158
2020-03-29 10:49:02 +09:00
KUOKA Yusuke 994e4b66fc
fix: `exec` template func should not throw away stdout when stdin is non empty (#1151)
Fixes #1149
2020-03-20 12:23:34 +09:00
a-hat e5038fb04f print yaml content on error in fromYaml (#765) 2019-07-30 10:43:30 +09:00
KUOKA Yusuke 78b03e0d92
fix: --state-values-set panic: value of type interface {} is not assignable to type string (#680)
Probably since #647 helmfile has been unable to merge nested maps in environment values if they were loaded from files. This fixes it.

The relevant test is also enhanced so that no further regression like this happens.

Fixes #677
2019-06-12 13:35:04 +09:00
KUOKA Yusuke 65ee6a2124
fix: "cannot unmarshal !!str `<no value>` into bool" errors in state templates (#645)
Seems like we are affected by https://github.com/golang/go/issues/24963. That is, even though we internally use the template option `missingkey=zero`, in some cases it still prints `<no value>` instead of zero values, which has been confusing the state yaml parsing.

This fixes the issue by naively replacing all the remaining occurrences of `<no value>` in the rendered text, while printing debug logs to ease debugging in the future when there is unexpected side-effects introduced by this native method.

Fixes #553
2019-06-04 13:23:38 +09:00
KUOKA Yusuke c68fc5bc50
chore: tidy up pkgs (#636)
for readability and towards potentially making helmfile usable as a go library
2019-06-01 13:36:05 +09:00