Skip to content

fix(kube): use non global Scheme to convert - #7401

Merged
thomastaylor312 merged 2 commits into
helm:masterfrom
hiddeco:non-global-scheme-convert
Feb 18, 2020
Merged

thomastaylor312 merged 2 commits into
helm:masterfrom
hiddeco:non-global-scheme-convert

Conversation

@hiddeco

@hiddeco hiddeco commented Jan 14, 2020 •

Copy link
Copy Markdown
Contributor

But instead use a newly initialized Scheme with only Kubernetes native
resources added. This ensures the 3-way-merge patch strategy is not
accidentally chosen for custom resources due to them being added
to the global Scheme by e.g. versioned clients while using Helm as a
package, and not a self-contained binary.

Signed-off-by: Hidde Beydals [email protected]

Closes #7400

@helm-bot helm-bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Jan 14, 2020
Comment thread pkg/kube/converter.go Resolved

@thomastaylor312 thomastaylor312 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good fix on this. Just one point of feedback around constructing the scheme

Comment thread pkg/kube/converter.go Outdated
// combination with e.g. a versioned kube client. If we would not do this, the client
// may attempt to perform e.g. a 3-way-merge strategy patch for custom resources.
func kubernetesNativeScheme() *runtime.Scheme {
s := runtime.NewScheme()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably use sync.Once to set this up and then only generate it once instead of every time. convertWithMapper is used a lot (basically for every resource), so it might be good to do this once. It could be stored in a non-exported global variable local to this package

Comment thread pkg/kube/converter.go Resolved
But instead use a newly initialized Scheme with only Kubernetes native
resources added. This ensures the 3-way-merge patch strategy is not
accidentally chosen for custom resources due to them being added
to the global Scheme by e.g. versioned clients while using Helm as a
package, and not a self-contained binary.

Signed-off-by: Hidde Beydals <[email protected]>
@hiddeco
hiddeco force-pushed the non-global-scheme-convert branch from 3a7132b to e41184a Compare February 12, 2020 00:43

@thomastaylor312 thomastaylor312 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for this fix!

@thomastaylor312 thomastaylor312 added needs-pick Indicates that a PR needs to be cherry-picked into the next release candidate. and removed in progress labels Feb 18, 2020
@thomastaylor312
thomastaylor312 merged commit 512e1b8 into helm:master Feb 18, 2020
@hiddeco
hiddeco deleted the non-global-scheme-convert branch February 19, 2020 06:31
@mattfarina mattfarina added the picked Indicates that a PR has been cherry-picked into the next release candidate. label Feb 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Categorizes issue or PR as related to a bug. needs-pick Indicates that a PR needs to be cherry-picked into the next release candidate. picked Indicates that a PR has been cherry-picked into the next release candidate. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Usage of global Scheme can cause Helm to wrongly choose a 3-way-merge patch

4 participants