helmfile / chartify

Convert K8s manifests/Kustomization into Helm Chart
Apache License 2.0
77 stars 29 forks source link

cannot unmarshal !!str `FOO ---...` into chartify.res] #18

Closed icy closed 2 years ago

icy commented 2 years ago

I had a bug report here https://github.com/roboll/helmfile/issues/2086, but I think the problem is from our library

https://github.com/variantdev/chartify/blob/0b1378d379b91a5a1f60132ad80ff8dd3f91f447/patch.go#L210

Description

When transformers is used, and the helm value is cert-folded, as below

  FOO: |
    -----BEGIN CERTIFICATE-----
    FOO
    -----END CERTIFICATE-----

helmfile will raise an exception

err: [processing all.patched.yaml: parsing yaml doc from "    FOO\n    -----END CERTIFICATE--": yaml: unmarshal errors:
  line 1: cannot unmarshal !!str `FOO ---...` into chartify.res]
in ./helmfile.yaml: [processing all.patched.yaml: parsing yaml doc from "    FOO\n    -----END CERTIFICATE--": yaml: unmarshal errors:
  line 1: cannot unmarshal !!str `FOO ---...` into chartify.res]

Test code

$ git clone https://github.com/icy/helmfile-bug.git
$ cd helmfile-bug/one
$  helmfile  --version
helmfile version v0.143.0
$ helmfile template

Logs

The output of helmfile --debug template command is found here https://github.com/icy/helmfile-bug/blob/main/one/debug.log.txt

Generating /tmp/chartify3660731556/test/all.patched.yaml
running kustomize build /tmp/chartify3660731556/test --output /tmp/chartify3660731556/test/all.patched.yaml
Removed /tmp/helmfile1974484501/test-values-6c8cc986b7
err: [processing all.patched.yaml: parsing yaml doc from "    FOO\n    -----END CERTIFICATE--": yaml: unmarshal errors:
  line 1: cannot unmarshal !!str `FOO ---...` into chartify.res]
in ./helmfile.yaml: [processing all.patched.yaml: parsing yaml doc from "    FOO\n    -----END CERTIFICATE--": yaml: unmarshal errors:
  line 1: cannot unmarshal !!str `FOO ---...` into chartify.res]

The command kustomize runs well, but its output was trapping the next step processing all.patched.yaml

icy commented 2 years ago

The bug may be coming from this https://github.com/variantdev/chartify/blob/0b1378d379b91a5a1f60132ad80ff8dd3f91f447/patch.go#L195

icy commented 2 years ago

https://github.com/variantdev/chartify/blob/0b1378d379b91a5a1f60132ad80ff8dd3f91f447/patch.go#L195

I'd suggest the yaml document separator does match this regex ^---$, but in tersm of byte sequence I don't know how to give it a test. I've updated our test to reflect this case https://github.com/variantdev/chartify/pull/19 . Will continue tomorrow. It's late now :).

icy commented 2 years ago

Okay I hope this works https://github.com/variantdev/chartify/pull/19/files.

@mumoshu Can you please have a look? Please let me know if there is anything I can help. Thanks