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

Make kubernetes json serializer case sensitive #65034

Merged
merged 3 commits into from
Jun 14, 2018

Conversation

caesarxuchao
Copy link
Member

@caesarxuchao caesarxuchao commented Jun 12, 2018

This PR imported the latest jsoniterator library so that case sensitivity during unmarhsaling is optional. The PR also set Kubernetes json serializer to be case sensitive.

Kubernetes json serializer had been case sensitive for 1.1-1.7 as we were using ugorji. This PR restores the behavior.

Fix #64612.

Kubernetes json deserializer is now case-sensitive to restore compatibility with pre-1.8 servers.
If your config files contain fields with wrong case, the config files will be now invalid.

Action required: 
Fix your JSON config files that contain fields of wrong case, otherwise they will be invalid.
If the fields in the golang schema doesn't have json tags, e.g., missing `json:"podSpec,omitempty"`, then the field in the JSON config file should match the case of the golang field, e.g., CamelCase.

Known non camelCase fields:

v1.10.5, scheduler/v1#ExtenderConfig.BindVerb, in the JSON config file, it needs to be "BindVerb".

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 12, 2018
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jun 12, 2018
@caesarxuchao caesarxuchao added sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. and removed cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jun 12, 2018
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jun 12, 2018
@nikhita
Copy link
Member

nikhita commented Jun 13, 2018

I think some tests need fixing because of the ExcludeCIDRs change. And staging godeps needs to be fixed. But looks good otherwise. 👍

Should this be cherry-picked into 1.8+? I'm not sure if that is such a good idea since this does a dependency bump...

@nikhita
Copy link
Member

nikhita commented Jun 13, 2018

/kind bug
/priority critical-urgent

Needs a milestone update too.

@k8s-ci-robot k8s-ci-robot added kind/bug Categorizes issue or PR as related to a bug. priority/critical-urgent Highest priority. Must be actively worked on as someone's top priority right now. labels Jun 13, 2018
@nikhita
Copy link
Member

nikhita commented Jun 13, 2018

cc @cblecker @sttts for godeps bump/approval

@nikhita
Copy link
Member

nikhita commented Jun 13, 2018

/uncc @dchen1107

@k8s-ci-robot k8s-ci-robot removed the request for review from dchen1107 June 13, 2018 03:16
@@ -157,7 +169,7 @@ func (s *Serializer) Decode(originalData []byte, gvk *schema.GroupVersionKind, i
types, _, err := s.typer.ObjectKinds(into)
switch {
case runtime.IsNotRegisteredError(err), isUnstructured:
if err := jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(data, into); err != nil {
if err := caseSensitiveJsonIterator().Unmarshal(data, into); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

private package var rather than reconstructing the options every time?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@liggitt
Copy link
Member

liggitt commented Jun 13, 2018

more godeps need fixing (apiextensions-apiserver/Godeps/Godeps.json)... should find/replace the json-iter revision in all of them

Other: "test",
},
},
// Unmarshalling is case-sensitive for big strut.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: struct

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@sttts
Copy link
Contributor

sttts commented Jun 13, 2018

/approve

@k8s-ci-robot k8s-ci-robot added area/kubeadm sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. labels Jun 13, 2018
@@ -157,7 +167,7 @@ func (s *Serializer) Decode(originalData []byte, gvk *schema.GroupVersionKind, i
types, _, err := s.typer.ObjectKinds(into)
switch {
case runtime.IsNotRegisteredError(err), isUnstructured:
if err := jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(data, into); err != nil {
Copy link
Member

@liggitt liggitt Jun 13, 2018

Choose a reason for hiding this comment

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

looks like there are four other uses of jsoniter.ConfigCompatibleWithStandardLibrary in the codebase... should replace those as well (and as a follow-up think about how to ensure we only use a standard consistent config; possibly something like #63284)

Copy link
Member Author

Choose a reason for hiding this comment

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

Replaced the other references in the latest commit.

#63284 is a good follow-up.

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 13, 2018
@caesarxuchao
Copy link
Member Author

/retest

@liggitt liggitt removed the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Jun 15, 2018
k8s-publishing-bot added a commit to kubernetes/apiextensions-apiserver that referenced this pull request Jun 15, 2018
Automatic merge from submit-queue (batch tested with PRs 64838, 65138). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

use case-sensitive json-iter to decode custom resource ObjectMeta

found one additional spot where case-insensitivity could bite us. uses the case-sensitive decode added in kubernetes/kubernetes#65034


/assign @sttts
/cc @caesarxuchao 

```release-note
NONE
```

Kubernetes-commit: 4ba0dbde84ba54941d998fc93b863b7eb97b8d53
@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-action-required Denotes a PR that introduces potentially breaking changes that require user action. labels Jun 15, 2018
k8s-github-robot pushed a commit that referenced this pull request Jun 19, 2018
Automatic merge from submit-queue.

Manually cherrypick #65034 to 1.10

Manually cherrypicking #65034. Using hack/cherry_pick_pull.sh to cherrypick is difficult because that requires cherrypicking #63059 first.

This PR imported the latest jsoniterator library so that case sensitivity during unmarhsaling is optional. The PR also set Kubernetes json serializer to be case sensitive.

Fix #64612.

```release-notes
Kubernetes json deserializer is now case-sensitive to restore compatibility with pre-1.8 servers.
If your config files contains fields with wrong case, the config files will be now invalid.
```
@caesarxuchao
Copy link
Member Author

Cherrypicked to 1.10, still needs to be cherrypicked to 1.8 and 1.9.

k8s-github-robot pushed a commit that referenced this pull request Jun 22, 2018
Automatic merge from submit-queue (batch tested with PRs 65339, 65343, 65324, 65335, 65367). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Fix k8s json package import name

Fixes nits found while cherry-picking #65034 in #65298.

**Release note**:

```release-note
NONE
```

/cc sttts liggitt caesarxuchao
k8s-publishing-bot added a commit to kubernetes/apimachinery that referenced this pull request Jun 24, 2018
Automatic merge from submit-queue (batch tested with PRs 65339, 65343, 65324, 65335, 65367). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Fix k8s json package import name

Fixes nits found while cherry-picking kubernetes/kubernetes#65034 in kubernetes/kubernetes#65298.

**Release note**:

```release-note
NONE
```

/cc sttts liggitt caesarxuchao

Kubernetes-commit: 456f85e736069398329226b9dff39d0304ee52d2
@k8s-ci-robot k8s-ci-robot added release-note-action-required Denotes a PR that introduces potentially breaking changes that require user action. and removed release-note Denotes a PR that will be considered when it comes time to generate release notes. labels Jun 24, 2018
k8s-github-robot pushed a commit that referenced this pull request Jun 27, 2018
Automatic merge from submit-queue.

Manual cherrypick of #65034 to 1.9: make json serializer case sensitive

fixes partially #64612

This PR imports the latest jsoniterator library so that case sensitivity during unmarshalling is optional. The PR also sets Kubernetes json serializer to be case sensitive.

**Release note**:

```release-note
ACTION REQUIRED: Kubernetes JSON deserializer is now case-sensitive to restore compatibility with pre-1.8 servers. If your config files contains fields with wrong case, the config files will be now invalid.
```

/sig api-machinery
/kind bug
/assign caesarxuchao liggitt thockin sttts mbohlool
@kfox1111
Copy link

Saw this in the release notes. Are there any tools to verify your cluster only has objects with the correct casing, or does each site need to write a tool to do so?

@liggitt
Copy link
Member

liggitt commented Jun 28, 2018

object data persisted in etcd is correct, so no stored data is problematic.

kubectl create/apply performs case-sensitive client-side validation which complains about incorrect/unknown fields.

For your resource manifest files, I'm not aware of a stand-alone tool that only validates a resource manifest against the openapi schema

k8s-github-robot pushed a commit that referenced this pull request Jun 28, 2018
Automatic merge from submit-queue.

Manual cherrypick of #65034 to 1.8: make json serializer case sensitive

fixes partially #64612

This PR imports the latest jsoniterator library so that case sensitivity during unmarshalling is optional. The PR also sets Kubernetes json serializer to be case sensitive.

**Release note**:

```release-note
ACTION REQUIRED: Kubernetes JSON deserializer is now case-sensitive to restore compatibility with pre-1.8 servers. If your config files contains fields with wrong case, the config files will be now invalid.
```

/sig api-machinery
/kind bug
/assign caesarxuchao liggitt thockin sttts mbohlool
rphillips pushed a commit to kubernetes-retired/bootkube that referenced this pull request Jul 11, 2018
* Bump v1.11.0

* Bump vendor k8s 1.11.0

Also bump json-iterator as required per: kubernetes/kubernetes#65034
dims added a commit to dims/etcd that referenced this pull request Apr 23, 2019
Using lessons learned from k8s changes:
kubernetes/kubernetes#65034

Change-Id: Ia17a8f94ae6ed00c5af2595c2b48d3c9a0344427
dims added a commit to dims/etcd that referenced this pull request Apr 23, 2019
…ugorji

Using lessons learned from k8s changes:
kubernetes/kubernetes#65034

Change-Id: Ia17a8f94ae6ed00c5af2595c2b48d3c9a0344427
dims added a commit to dims/etcd that referenced this pull request Apr 23, 2019
…ugorji

Using lessons learned from k8s changes:
kubernetes/kubernetes#65034

Change-Id: Ia17a8f94ae6ed00c5af2595c2b48d3c9a0344427
dims added a commit to dims/etcd that referenced this pull request Apr 23, 2019
…ugorji

Using lessons learned from k8s changes:
kubernetes/kubernetes#65034

Change-Id: Ia17a8f94ae6ed00c5af2595c2b48d3c9a0344427
dims added a commit to dims/etcd that referenced this pull request Apr 24, 2019
…ugorji

Using lessons learned from k8s changes:
kubernetes/kubernetes#65034

Change-Id: Ia17a8f94ae6ed00c5af2595c2b48d3c9a0344427
hexfusion pushed a commit to etcd-io/etcd that referenced this pull request Apr 25, 2019
…ugorji

Using lessons learned from k8s changes:
kubernetes/kubernetes#65034

Change-Id: Ia17a8f94ae6ed00c5af2595c2b48d3c9a0344427
MartinWeindel pushed a commit to MartinWeindel/etcd that referenced this pull request Jun 12, 2019
…ugorji

Using lessons learned from k8s changes:
kubernetes/kubernetes#65034

Change-Id: Ia17a8f94ae6ed00c5af2595c2b48d3c9a0344427
hexfusion pushed a commit to openshift/etcd that referenced this pull request Sep 26, 2019
…ugorji

Using lessons learned from k8s changes:
kubernetes/kubernetes#65034

Change-Id: Ia17a8f94ae6ed00c5af2595c2b48d3c9a0344427
tamalsaha pushed a commit to gomodules/encoding that referenced this pull request Aug 10, 2021
Automatic merge from submit-queue (batch tested with PRs 65339, 65343, 65324, 65335, 65367). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Fix k8s json package import name

Fixes nits found while cherry-picking kubernetes/kubernetes#65034 in kubernetes/kubernetes#65298.

**Release note**:

```release-note
NONE
```

/cc sttts liggitt caesarxuchao

Kubernetes-commit: 456f85e736069398329226b9dff39d0304ee52d2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/kubeadm cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/critical-urgent Highest priority. Must be actively worked on as someone's top priority right now. release-note-action-required Denotes a PR that introduces potentially breaking changes that require user action. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants