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

CustomResources dropping "null" values from arrays #98080

Closed
caseydavenport opened this issue Jan 14, 2021 · 13 comments · Fixed by #102467
Closed

CustomResources dropping "null" values from arrays #98080

caseydavenport opened this issue Jan 14, 2021 · 13 comments · Fixed by #102467
Labels
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. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. triage/accepted Indicates an issue or PR is ready to be actively worked on.

Comments

@caseydavenport
Copy link
Member

What happened:

While attempting to work around #98079, I encountered an issue where data was not preserved when writing a custom resource instance to the apiserver with kubectl.

Specifically, I am using a CRD that has a properly which is an array of values which can either be an integer, or null:

spec:
  properties:
    allocations:
      items:
        nullable: true
        type: integer
      type: array

When using kubectl to modify the resource, all of the "null" values are lost upon write. So, if I attempt to write a resource with the following:

allocations:
- 1
- 5
- null
- null

It is written successfully. However, when I query the resource from the API afterwards, this is what I get back:

allocations:
- 1
- 5

The null entries have been lost.

What you expected to happen:

The null entries in the array should be maintained.

How to reproduce it (as minimally and precisely as possible):

Create a CustomResourceDefinition with a property like the one specified above, and create an instance of it (you may need to pass --validate=false in order to bypass the bug in #98079).

Notice that null values are removed from the array.

Anything else we need to know?:

Environment:

  • Kubernetes version (use kubectl version):
Client Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.8", GitCommit:"9f2892aab98fe339f3bd70e3c470144299398ace", GitTreeState:"clean", BuildDate:"2020-08-13T16:12:48Z", GoVersion:"go1.13.15", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.2", GitCommit:"52c56ce7a8272c798dbc29846288d7cd9fbae032", GitTreeState:"clean", BuildDate:"2020-04-30T20:19:45Z", GoVersion:"go1.13.9", Compiler:"gc", Platform:"linux/amd64"}

Also reproduced on master by @liggitt

CC @sttts @apelisse

/sig api-machinery

@caseydavenport caseydavenport added the kind/bug Categorizes issue or PR as related to a bug. label Jan 14, 2021
@k8s-ci-robot k8s-ci-robot added sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jan 14, 2021
@apelisse
Copy link
Member

That's clearly a bug, thanks for the easy steps to reproduce, I'll look at it.

@sttts sttts added the priority/critical-urgent Highest priority. Must be actively worked on as someone's top priority right now. label Jan 15, 2021
@sttts
Copy link
Contributor

sttts commented Jan 15, 2021

This is about data loss. Set to urgent to investigate.

@liggitt
Copy link
Member

liggitt commented Jan 15, 2021

Digging briefly, it looks at first glance like json-patch is dropping all null values in https://github.com/evanphx/json-patch/blob/master/merge.go#L81 (haven't verified with a test yet, just manual inspection)

@apelisse
Copy link
Member

Based on Jordan's reading and mine, this is a bug/misreading of the JSON Merge patch. We should probably patch upstream.
Can the spec be updated to improve readability/add a test case?

@fedebongio
Copy link
Contributor

/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jan 19, 2021
@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Apr 19, 2021
@fejta-bot
Copy link

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels May 19, 2021
@DraggonFantasy
Copy link

The patch about preserving null values in the arrays was merged to the json-patch, so the issue should be fixed

@apelisse
Copy link
Member

apelisse commented Jun 1, 2021

We probably need to update the version of json-patch used in kubernetes now!

@pacoxu
Copy link
Member

pacoxu commented Jun 1, 2021

@apelisse is there a new release version with the fix?

I asked @evanphx to make one.

/remove-lifecycle rotten

@k8s-ci-robot k8s-ci-robot removed the lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. label Jun 1, 2021
@evanphx
Copy link

evanphx commented Jun 1, 2021

@pacoxu Yup, v5.5.0 has been released with the fixes.

@pacoxu
Copy link
Member

pacoxu commented Jun 1, 2021

Currently, v4.5.0 cannot be removed for kustomize

  • sigs.k8s.io/kustomize/api@v0.8.10 is using github.com/evanphx/json-patch@v4.5.0+incompatible.
  • staging/src/k8s.io/sample-cli-plugin/go.sum is using v4.5.0+incompatible.

I opened kubernetes-sigs/kustomize#3938 for kustomize.

@pacoxu
Copy link
Member

pacoxu commented Jun 4, 2021

Update to v4.11.0 to fix it.
v5.5.0 has some break changes and the upgrade will be discussed later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants