kubernetes-sigs / kustomize

Customization of kubernetes YAML configurations
Apache License 2.0
11k stars 2.25k forks source link

patchJson6902YAML crash #396

Closed miekg closed 6 years ago

miekg commented 6 years ago

kustomize.yaml

resources:
- ../deployment.yaml

patchesJson6902:
- path: secret_patch.yaml
  target:
    group: apps
    kind: Deployment
    name: base
    version: v1

secret_path.yaml has: (the /- bit is wrong, removing that make things not crash)

- op: replace
  path: /spec/template/spec/volumes/0/secret/secretName/-
  value: web

This crashes with (v1.0.8):

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x1011399]

goroutine 1 [running]:
sigs.k8s.io/kustomize/vendor/github.com/krishicks/yaml-patch.tryReplace(0x1425080, 0xc0000b0048, 0xc0000b4e00, 0xffffffffffffffff, 0xc0004ab6e8)
        external/com_github_kubernetes-sigs_kustomize/vendor/github.com/krishicks/yaml-patch/operation.go:110 +0x99
sigs.k8s.io/kustomize/vendor/github.com/krishicks/yaml-patch.(*Operation).Perform(0xc0000b4e00, 0x1425080, 0xc0000b0048, 0x108f120, 0xc00041bcb0)
        external/com_github_kubernetes-sigs_kustomize/vendor/github.com/krishicks/yaml-patch/operation.go:72 +0x207
sigs.k8s.io/kustomize/vendor/github.com/krishicks/yaml-patch.Patch.Apply(0xc0000b4480, 0x1, 0x1, 0xc000126400, 0x339, 0x400, 0x0, 0xc0000ad2f0, 0x4, 0x0, ...)
        external/com_github_kubernetes-sigs_kustomize/vendor/github.com/krishicks/yaml-patch/patch.go:52 +0x535
sigs.k8s.io/kustomize/pkg/patch/transformer.(*patchJson6902YAMLTransformer).Transform(0xc000314d00, 0xc000418ba0, 0x0, 0x0)
        external/com_github_kubernetes-sigs_kustomize/pkg/patch/transformer/patchjson6902yaml.go:53 +0xf0
sigs.k8s.io/kustomize/pkg/transformers.(*multiTransformer).transform(0xc0001fc980, 0xc000418ba0, 0x10024cf, 0x1e7e628)
        external/com_github_kubernetes-sigs_kustomize/pkg/transformers/multitransformer.go:60 +0x6f
sigs.k8s.io/kustomize/pkg/transformers.(*multiTransformer).transformWithCheckConflict(0xc0001fc980, 0xc000418ba0, 0x0, 0x0)
        external/com_github_kubernetes-sigs_kustomize/pkg/transformers/multitransformer.go:73 +0x51
sigs.k8s.io/kustomize/pkg/transformers.(*multiTransformer).Transform(0xc0001fc980, 0xc000418ba0, 0x0, 0x0)
        external/com_github_kubernetes-sigs_kustomize/pkg/transformers/multitransformer.go:54 +0x44
sigs.k8s.io/kustomize/pkg/transformers.(*multiTransformer).transform(0xc0001fc9e0, 0xc000418ba0, 0x30, 0x3)
        external/com_github_kubernetes-sigs_kustomize/pkg/transformers/multitransformer.go:60 +0x6f
sigs.k8s.io/kustomize/pkg/transformers.(*multiTransformer).Transform(0xc0001fc9e0, 0xc000418ba0, 0x3, 0x3)
        external/com_github_kubernetes-sigs_kustomize/pkg/transformers/multitransformer.go:56 +0x75
sigs.k8s.io/kustomize/pkg/app.(*Application).loadCustomizedResMap(0xc000317590, 0x10d, 0x30d, 0xc00038e000)
        external/com_github_kubernetes-sigs_kustomize/pkg/app/application.go:181 +0x765
sigs.k8s.io/kustomize/pkg/app.(*Application).MakeCustomizedResMap(0xc000317590, 0xc0002f9440, 0x142edc0, 0x1e7e628)
        external/com_github_kubernetes-sigs_kustomize/pkg/app/application.go:83 +0x2b
sigs.k8s.io/kustomize/pkg/commands.(*buildOptions).RunBuild(0xc0002f8b40, 0x140c320, 0xc0000b0008, 0x142edc0, 0x1e7e628, 0x0, 0x0)
        external/com_github_kubernetes-sigs_kustomize/pkg/commands/build.go:102 +0x103
sigs.k8s.io/kustomize/pkg/commands.newCmdBuild.func1(0xc000131b80, 0x1e7e628, 0x0, 0x0, 0x0, 0x0)
        external/com_github_kubernetes-sigs_kustomize/pkg/commands/build.go:66 +0xab
sigs.k8s.io/kustomize/vendor/github.com/spf13/cobra.(*Command).execute(0xc000131b80, 0x1e7e628, 0x0, 0x0, 0xc000131b80, 0x1e7e628)
        external/com_github_kubernetes-sigs_kustomize/vendor/github.com/spf13/cobra/command.go:756 +0x473
sigs.k8s.io/kustomize/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0xc000131400, 0xc000131b80, 0xc0001ee000, 0xc000289180)
        external/com_github_kubernetes-sigs_kustomize/vendor/github.com/spf13/cobra/command.go:846 +0x2fd
sigs.k8s.io/kustomize/vendor/github.com/spf13/cobra.(*Command).Execute(0xc000131400, 0x13015b0, 0xc000092058)
        external/com_github_kubernetes-sigs_kustomize/vendor/github.com/spf13/cobra/command.go:794 +0x2b
main.main()
        external/com_github_kubernetes-sigs_kustomize/kustomize.go:30 +0x43
Liujingfang1 commented 6 years ago

What is the meaning of - in the path? Is it for a list?

miekg commented 6 years ago

Sorry I don't know what it means, I was just toying with some stuff to get a patch applied. I think it has some meaning but I have to read RFC 6902 to be sure.

Liujingfang1 commented 6 years ago

Here is the link https://tools.ietf.org/html/rfc6902 And the only example containing - I found is

   An example target JSON document:

   { "foo": ["bar"] }

   A JSON Patch document:

   [
     { "op": "add", "path": "/foo/-", "value": ["abc", "def"] }
   ]

   The resulting JSON document:

   { "foo": ["bar", ["abc", "def"]] }
Liujingfang1 commented 6 years ago

secretName is a string field, not an array. - in the json patch is used to append values to existing array. So the json patch is not a valid input for you deployment.

miekg commented 6 years ago

[ Quoting notifications@github.com in "Re: [kubernetes-sigs/kustomize] pat..." ]

secretName is a string field, not an array. - in the json patch is used to append values to existing array. So the json patch is not a valid input for you deployment.

kustomize crashes, it should not, regardless if this is valid syntax or not