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

output empty creationTimestamp as null #53464

Conversation

juanvallejo
Copy link
Contributor

@juanvallejo juanvallejo commented Oct 4, 2017

Release note

NONE

Updates the value of the creationTimestamp field to be null
when empty, to keep parity between it and deletionTimestamp.

Adds a round-trip test to ensure that unstructured objects containing
empty metadata fields are able to be re-converted back into internal
or external objects. Prior to the proposed patch in this PR, an
unstructured object whose .metadata.creationTimestamp value had
been set through the metadata accessor to an empty value
(metav1.Time{} in this case), was unable to be re-converted to an
internal or external type using the runtime decoder. Conversion would
fail with the error:

unstructured_test.go:177: FromUnstructured failed: parsing time "" as "2006-01-02T15:04:05Z07:00": cannot parse "" as "2006"

cc @liggitt @fabianofranz

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Oct 4, 2017
@k8s-ci-robot
Copy link
Contributor

Hi @juanvallejo. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@juanvallejo
Copy link
Contributor Author

/assign fabianofranz
/assign shyiwang

@k8s-ci-robot
Copy link
Contributor

@juanvallejo: GitHub didn't allow me to assign the following users: shyiwang.

Note that only kubernetes members can be assigned.

In response to this:

/assign fabianofranz
/assign shyiwang

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@cblecker
Copy link
Member

cblecker commented Oct 5, 2017

/ok-to-test

@k8s-ci-robot k8s-ci-robot removed the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Oct 5, 2017
@juanvallejo
Copy link
Contributor Author

/test pull-kubernetes-e2e-gce-bazel

@liggitt
Copy link
Member

liggitt commented Oct 7, 2017

Lgtm, would like to see a test

@juanvallejo juanvallejo force-pushed the jvallejo/output-empty-creation-ts-as-null branch from d78cd09 to 465edb2 Compare October 9, 2017 15:23
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Oct 9, 2017
@juanvallejo
Copy link
Contributor Author

@liggitt thanks, test added

@@ -464,6 +464,10 @@ func (u *Unstructured) GetCreationTimestamp() metav1.Time {

func (u *Unstructured) SetCreationTimestamp(timestamp metav1.Time) {
ts, _ := timestamp.MarshalQueryParameter()
if len(ts) == 0 {
u.setNestedField(nil, "metadata", "creationTimestamp")
Copy link
Member

Choose a reason for hiding this comment

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

hmm... actually, should this be storing nil or removing from the map? @ironcladlou, any thoughts here?

Copy link
Contributor

Choose a reason for hiding this comment

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

I suggested removing nil keys from the map generally in #48211, but I wouldn't say there's consensus on that point yet.

@deads2k suggested we rely on omitempty in the external types to accommodate a nil here (mirroring his prior counterpoint to #48211 (comment)), which I'm fine with.

Maybe some more godocs would help here in the meantime?

Copy link
Contributor

Choose a reason for hiding this comment

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

This field is omitempty.

@juanvallejo I prefer to delete the entry, then this lgtm.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, will update

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Oct 11, 2017
@juanvallejo
Copy link
Contributor Author

@ironcladlou thanks for your feedback on this; per our conversation I added a round trip test
that ensures empty metadata field values in an object do not inhibit that object's conversion.
Updated PR's description to explain the new test, and did a local test proving the fix from
this patch.

From the PR's description:

Adds a round-trip test to ensure that unstructured objects containing
empty metadata fields are able to be re-converted back into internal
or external objects. Prior to the proposed patch in this PR, an
unstructured object whose `.metadata.creationTimestamp` value had
been set through the metadata accessor to an empty value 
(`metav1.Time{}` in this case), was unable to be re-converted to an
internal or external type using the runtime decoder. Conversion would
fail with the error:

unstructured_test.go:177: FromUnstructured failed: parsing time "" as "2006-01-02T15:04:05Z07:00": cannot parse "" as "2006"

@juanvallejo juanvallejo force-pushed the jvallejo/output-empty-creation-ts-as-null branch 2 times, most recently from d06e84c to 327353c Compare October 11, 2017 19:15
@juanvallejo
Copy link
Contributor Author

/retest

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 12, 2017
@juanvallejo juanvallejo force-pushed the jvallejo/output-empty-creation-ts-as-null branch from 327353c to a358092 Compare October 12, 2017 13:55
@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 12, 2017
@juanvallejo juanvallejo force-pushed the jvallejo/output-empty-creation-ts-as-null branch from 2d4692e to 62a8e47 Compare November 1, 2017 17:20
@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 2, 2017
@juanvallejo juanvallejo force-pushed the jvallejo/output-empty-creation-ts-as-null branch from 62a8e47 to 288e21f Compare November 2, 2017 14:41
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 2, 2017
@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 2, 2017
@@ -258,6 +258,10 @@ func (u *Unstructured) GetCreationTimestamp() metav1.Time {

func (u *Unstructured) SetCreationTimestamp(timestamp metav1.Time) {
ts, _ := timestamp.MarshalQueryParameter()
if len(ts) == 0 {
RemoveNestedField(u.Object, "metadata", "creationTimestamp")
Copy link
Contributor

@deads2k deads2k Nov 2, 2017

Choose a reason for hiding this comment

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

@sttts creationtime is an omitEmpty field, so when it is zero value it doesn't get serialized. While I may not detect it this way (@juanvallejo can you check if the passed timestamp is zero value), removing the field when this happens is reasonable.

Also, the current serialization is incorrect. We should never produce one with an empty string.

Copy link
Member

@liggitt liggitt Nov 2, 2017

Choose a reason for hiding this comment

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

creationtime is an omitEmpty field, so when it is zero value it doesn't get serialized

actually, since it's a struct in ObjectMeta, it still does (yay, go json), but logically, should not

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@deads2k

@juanvallejo can you check if the passed timestamp is zero value

Done

@juanvallejo juanvallejo force-pushed the jvallejo/output-empty-creation-ts-as-null branch 2 times, most recently from 7d34131 to e7ca207 Compare November 2, 2017 15:53
@deads2k
Copy link
Contributor

deads2k commented Nov 2, 2017

lgtm, please squash for merge.

@juanvallejo juanvallejo force-pushed the jvallejo/output-empty-creation-ts-as-null branch from e7ca207 to 2008750 Compare November 2, 2017 18:08
@juanvallejo
Copy link
Contributor Author

@deads2k thanks, commits squashed

@juanvallejo
Copy link
Contributor Author

/test pull-kubernetes-e2e-kops-aws

@liggitt
Copy link
Member

liggitt commented Nov 3, 2017

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 3, 2017
@fabianofranz
Copy link
Contributor

/approve no-issue

@k8s-github-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: fabianofranz, juanvallejo, liggitt

No associated issue. Update pull-request body to add a reference to an issue, or get approval with /approve no-issue

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@fabianofranz
Copy link
Contributor

/sig cli
/kind bug

@k8s-ci-robot k8s-ci-robot added sig/cli Categorizes an issue or PR as relevant to SIG CLI. kind/bug Categorizes issue or PR as related to a bug. labels Nov 3, 2017
@fabianofranz fabianofranz added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 3, 2017
@k8s-github-robot
Copy link

/test all [submit-queue is verifying that this PR is safe to merge]

@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 55050, 53464, 54936, 55028, 54928). If you want to cherry-pick this change to another branch, please follow the instructions here.

@k8s-github-robot k8s-github-robot merged commit 1ad792f into kubernetes:master Nov 3, 2017
@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented Nov 3, 2017

@juanvallejo: The following test failed, say /retest to rerun them all:

Test name Commit Details Rerun command
pull-kubernetes-unit 2008750 link /test pull-kubernetes-unit

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

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. 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. release-note-none Denotes a PR that doesn't merit a release note. sig/cli Categorizes an issue or PR as relevant to SIG CLI. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet