Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix panic when upgrading configurations with patches #1971

Merged
merged 3 commits into from
Apr 18, 2019

Conversation

corneliusweig
Copy link
Contributor

@corneliusweig corneliusweig commented Apr 16, 2019

This PR fixes two problems:

  1. the upgrade path of skaffold yaml. The problem here was that config upgrades rely on JSON serialization, but the yamlpatch.Node did not behave as desired.
  2. validation visits all fields in the Skaffold config, while it should only visit exported fields.

Fix #1964

@corneliusweig
Copy link
Contributor Author

Unexported field access is fixed, however schema upgrade of configs with profile patches still fails:

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

goroutine 1 [running]:
github.com/GoogleContainerTools/skaffold/vendor/gopkg.in/yaml%2ev2.handleErr(0xc00051bc68)
        vendor/gopkg.in/yaml.v2/yaml.go:249 +0x9a
panic(0x1503440, 0x27101d0)
        /usr/lib64/go/src/runtime/panic.go:522 +0x1b5
github.com/GoogleContainerTools/skaffold/vendor/github.com/krishicks/yaml-patch.(*Node).MarshalYAML(0xc00001e3e0, 0x159e480, 0xc00001e3e0, 0x7f15b9e6b968, 0xc00001e3e0)
        vendor/github.com/krishicks/yaml-patch/node.go:26 +0x33
github.com/GoogleContainerTools/skaffold/vendor/gopkg.in/yaml%2ev2.(*encoder).marshal(0xc00023ab00, 0x0, 0x0, 0x159e480, 0xc0001283b0, 0x196)
        vendor/gopkg.in/yaml.v2/encode.go:98 +0x82a
github.com/GoogleContainerTools/skaffold/vendor/gopkg.in/yaml%2ev2.(*encoder).structv.func1()
        vendor/gopkg.in/yaml.v2/encode.go:198 +0x55a
github.com/GoogleContainerTools/skaffold/vendor/gopkg.in/yaml%2ev2.(*encoder).mappingv(0xc00023ab00, 0x0, 0x0, 0xc00051ab80)
        vendor/gopkg.in/yaml.v2/encode.go:228 +0x147
github.com/GoogleContainerTools/skaffold/vendor/gopkg.in/yaml%2ev2.(*encoder).structv(0xc00023ab00, 0x0, 0x0, 0x15de100, 0xc000128380, 0x199)
        vendor/gopkg.in/yaml.v2/encode.go:185 +0xf7
github.com/GoogleContainerTools/skaffold/vendor/gopkg.in/yaml%2ev2.(*encoder).marshal(0xc00023ab00, 0x0, 0x0, 0x15de100, 0xc000128380, 0x199)
        vendor/gopkg.in/yaml.v2/encode.go:132 +0x726
github.com/GoogleContainerTools/skaffold/vendor/gopkg.in/yaml%2ev2.(*encoder).slicev(0xc00023ab00, 0x0, 0x0, 0x143f460, 0xc0004e8b30, 0x197)
        vendor/gopkg.in/yaml.v2/encode.go:244 +0x1f8
github.com/GoogleContainerTools/skaffold/vendor/gopkg.in/yaml%2ev2.(*encoder).marshal(0xc00023ab00, 0x0, 0x0, 0x143f460, 0xc0004e8b30, 0x197)
        vendor/gopkg.in/yaml.v2/encode.go:138 +0x412
github.com/GoogleContainerTools/skaffold/vendor/gopkg.in/yaml%2ev2.(*encoder).structv.func1()
        vendor/gopkg.in/yaml.v2/encode.go:198 +0x55a
github.com/GoogleContainerTools/skaffold/vendor/gopkg.in/yaml%2ev2.(*encoder).mappingv(0xc00023ab00, 0x0, 0x0, 0xc00051b108)
        vendor/gopkg.in/yaml.v2/encode.go:228 +0x147
github.com/GoogleContainerTools/skaffold/vendor/gopkg.in/yaml%2ev2.(*encoder).structv(0xc00023ab00, 0x0, 0x0, 0x15de1c0, 0xc0004e8a80, 0x199)
        vendor/gopkg.in/yaml.v2/encode.go:185 +0xf7
github.com/GoogleContainerTools/skaffold/vendor/gopkg.in/yaml%2ev2.(*encoder).marshal(0xc00023ab00, 0x0, 0x0, 0x15de1c0, 0xc0004e8a80, 0x199)
        vendor/gopkg.in/yaml.v2/encode.go:132 +0x726
github.com/GoogleContainerTools/skaffold/vendor/gopkg.in/yaml%2ev2.(*encoder).slicev(0xc00023ab00, 0x0, 0x0, 0x143f4a0, 0xc000128520, 0x197)
        vendor/gopkg.in/yaml.v2/encode.go:244 +0x1f8
github.com/GoogleContainerTools/skaffold/vendor/gopkg.in/yaml%2ev2.(*encoder).marshal(0xc00023ab00, 0x0, 0x0, 0x143f4a0, 0xc000128520, 0x197)
        vendor/gopkg.in/yaml.v2/encode.go:138 +0x412
github.com/GoogleContainerTools/skaffold/vendor/gopkg.in/yaml%2ev2.(*encoder).structv.func1()
        vendor/gopkg.in/yaml.v2/encode.go:198 +0x55a
github.com/GoogleContainerTools/skaffold/vendor/gopkg.in/yaml%2ev2.(*encoder).mappingv(0xc00023ab00, 0x0, 0x0, 0xc00051b690)
        vendor/gopkg.in/yaml.v2/encode.go:228 +0x147
github.com/GoogleContainerTools/skaffold/vendor/gopkg.in/yaml%2ev2.(*encoder).structv(0xc00023ab00, 0x0, 0x0, 0x15de280, 0xc000128460, 0x199)
        vendor/gopkg.in/yaml.v2/encode.go:185 +0xf7
github.com/GoogleContainerTools/skaffold/vendor/gopkg.in/yaml%2ev2.(*encoder).marshal(0xc00023ab00, 0x0, 0x0, 0x15de280, 0xc000128460, 0x199)
        vendor/gopkg.in/yaml.v2/encode.go:132 +0x726
github.com/GoogleContainerTools/skaffold/vendor/gopkg.in/yaml%2ev2.(*encoder).marshal(0xc00023ab00, 0x0, 0x0, 0x150aba0, 0xc000128460, 0x16)
        vendor/gopkg.in/yaml.v2/encode.go:126 +0x59f
github.com/GoogleContainerTools/skaffold/vendor/gopkg.in/yaml%2ev2.(*encoder).marshalDoc(0xc00023ab00, 0x0, 0x0, 0x150aba0, 0xc000128460, 0x16)
        vendor/gopkg.in/yaml.v2/encode.go:80 +0x10f
github.com/GoogleContainerTools/skaffold/vendor/gopkg.in/yaml%2ev2.Marshal(0x150aba0, 0xc000128460, 0x0, 0x0, 0x0, 0x0, 0x0)
        vendor/gopkg.in/yaml.v2/yaml.go:203 +0x329
github.com/GoogleContainerTools/skaffold/cmd/skaffold/app/cmd.runFix(0x191d520, 0xc0000cc008, 0x16f799e, 0xd, 0xc00051bc00, 0x0, 0x0)
        cmd/skaffold/app/cmd/fix.go:66 +0x144
github.com/GoogleContainerTools/skaffold/cmd/skaffold/app/cmd.NewCmdFix.func1(0xc00033c280, 0xc0002566e0, 0x0, 0x2, 0x0, 0x0)
        cmd/skaffold/app/cmd/fix.go:37 +0x56
github.com/GoogleContainerTools/skaffold/vendor/github.com/spf13/cobra.(*Command).execute(0xc00033c280, 0xc0002566a0, 0x2, 0x2, 0xc00033c280, 0xc0002566a0)
        vendor/github.com/spf13/cobra/command.go:762 +0x465
github.com/GoogleContainerTools/skaffold/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0xc00019b900, 0xc0000cc008, 0x191d520, 0xc0000cc010)
        vendor/github.com/spf13/cobra/command.go:852 +0x2ec
github.com/GoogleContainerTools/skaffold/vendor/github.com/spf13/cobra.(*Command).Execute(...)
        vendor/github.com/spf13/cobra/command.go:800
github.com/GoogleContainerTools/skaffold/cmd/skaffold/app.Run(0x191d520, 0xc0000cc008, 0x191d520, 0xc0000cc010, 0xc00051bf88, 0x40584f)
        cmd/skaffold/app/skaffold.go:35 +0xd3
main.main()
        cmd/skaffold/skaffold.go:30 +0x4e

The reason seems to be schema upgrade relies on json marshalling/unmarshalling. However, the Node struct (vendor/github.com/krishicks/yaml-patch/node.go:7) does not serialize well to json, so that its internal raw pointer becomes nil. This results in the above segfault.

yamlpatch.Node hides its implementation with unexported fields, which are not accessible for JSON serialization. Fix this serializing the struct to yaml and include that as an inline string in the json.

Signed-off-by: Cornelius Weig <[email protected]>
Signed-off-by: Cornelius Weig <[email protected]>
@corneliusweig corneliusweig marked this pull request as ready for review April 17, 2019 10:04
@corneliusweig corneliusweig changed the title WIP Fix panic when encountering unexported fields in validation Fix panic when upgrading configurations with patches Apr 17, 2019
@codecov-io
Copy link

Codecov Report

Merging #1971 into master will increase coverage by 0.1%.
The diff coverage is 87.09%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #1971     +/-   ##
=========================================
+ Coverage   52.94%   53.04%   +0.1%     
=========================================
  Files         183      183             
  Lines        7920     7942     +22     
=========================================
+ Hits         4193     4213     +20     
- Misses       3327     3328      +1     
- Partials      400      401      +1
Impacted Files Coverage Δ
pkg/skaffold/schema/v1beta8/config.go 100% <ø> (ø) ⬆️
pkg/skaffold/schema/latest/config.go 100% <ø> (ø) ⬆️
pkg/skaffold/schema/v1beta5/config.go 100% <ø> (ø) ⬆️
pkg/skaffold/schema/v1beta6/config.go 100% <ø> (ø) ⬆️
pkg/skaffold/schema/v1beta7/config.go 100% <ø> (ø) ⬆️
pkg/skaffold/schema/profiles.go 90.57% <100%> (+0.2%) ⬆️
pkg/skaffold/schema/validation/validation.go 100% <100%> (ø) ⬆️
pkg/skaffold/schema/util/util.go 81.81% <84%> (+6.81%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 782c111...0338c8b. Read the comment docs.

@balopat balopat added the kokoro:run runs the kokoro jobs on a PR label Apr 17, 2019
@kokoro-team kokoro-team removed the kokoro:run runs the kokoro jobs on a PR label Apr 17, 2019
@dgageot dgageot merged commit 73a4422 into GoogleContainerTools:master Apr 18, 2019
@corneliusweig corneliusweig deleted the fix-panic branch April 18, 2019 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[v0.27.0] Skaffold fix panic
6 participants