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

encode NamespacedName with lower case in JSON #117238

Merged
merged 1 commit into from
Apr 13, 2023

Conversation

pohly
Copy link
Contributor

@pohly pohly commented Apr 12, 2023

What type of PR is this?

/kind bug
/kind failing-test

What this PR does / why we need it:

Lower case is how a workaround in controller-runtime has encoded NamespacedName (https://github.com/kubernetes-sigs/controller-runtime/blob/a33d038b84d0e7f615b8d803bdc47f0d1f8484b7/pkg/log/zap/kube_helpers.go#L49-L57) and it is also more consistent with Kubernetes API standards.

Which issue(s) this PR fixes:

Returning an anonymous struct in MarshalLog makes it impossible for controller-runtime to adapt the type and thus blocks updating controller-runtime to Kubernetes 1.27 because log content would change.

Special notes for your reviewer:

Once merged we need to backport.

Does this PR introduce a user-facing change?

Structured logging of NamespacedName was inconsistent with klog.KObj. Now both use lower case field names and namespace is optional.

@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/XS Denotes a PR that changes 0-9 lines, ignoring generated files. kind/bug Categorizes issue or PR as related to a bug. kind/failing-test Categorizes issue or PR as related to a consistently or frequently failing test. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Apr 12, 2023
@k8s-ci-robot k8s-ci-robot added sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/architecture Categorizes an issue or PR as relevant to SIG Architecture. sig/instrumentation Categorizes an issue or PR as relevant to SIG Instrumentation. wg/structured-logging Categorizes an issue or PR as relevant to WG Structured Logging. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Apr 12, 2023
That is how a workaround in controller-runtime has encoded
NamespacedName (https://github.com/kubernetes-sigs/controller-runtime/blob/a33d038b84d0e7f615b8d803bdc47f0d1f8484b7/pkg/log/zap/kube_helpers.go#L49-L57)
and it is also more consistent with Kubernetes API standards.

The namespace can be left out.

Returning an anonymous struct in MarshalLog makes it impossible for
controller-runtime to adapt the type and thus blocks updating
controller-runtime to Kubernetes 1.27 because log content would
change.
@pohly pohly force-pushed the namespaces-name-lowercase branch from b66e2ac to 4438208 Compare April 12, 2023 10:48
@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 Apr 12, 2023
@mythi
Copy link
Contributor

mythi commented Apr 12, 2023

LGTM and I've tested this as part of my PR kubernetes-sigs/controller-runtime#2189

@pohly
Copy link
Contributor Author

pohly commented Apr 12, 2023

/assign @dims

This is a follow-up to #106379 which you also helped to get merged. Sorry that we need to modify the behavior again so soon! But that controller-runtime had a workaround for this problem shows that it was a real issue that bothered people, we just need to make the upstream solution work for them.

@dims
Copy link
Member

dims commented Apr 12, 2023

@pohly gonna defer to Jordan on this one. (it seems ok to me for sure!)

/assign @liggitt

@liggitt
Copy link
Member

liggitt commented Apr 12, 2023

Returning an anonymous struct in MarshalLog makes it impossible for controller-runtime to adapt the type and thus blocks updating controller-runtime to Kubernetes 1.27 because log content would change.

This does not seem like a Kubernetes bug. Log content is not an API we guarantee, and downstreams taking hard dependencies on exact log content seems like a problem / anti-pattern we want to flush out and get rid of, not enable.

@liggitt
Copy link
Member

liggitt commented Apr 12, 2023

To be clear, I don't really object to lowercasing the keys... I object strongly to positioning log content as a shadow API surface area downstreams take hard dependencies on and we treat changes in as bugs.

@pohly
Copy link
Contributor Author

pohly commented Apr 13, 2023

Okay, so not a bug. I agree with the argument and had the same thought initially, but then came to the conclusion that we should have chosen lower case for internal consistency, too, and therefore should change this also in 1.27.1, i.e. backport the change. Can we do that?

@pohly
Copy link
Contributor Author

pohly commented Apr 13, 2023

Note that it's not just general API conventions, but also klog.KObj which uses lower case field names. We really should have used lower case for NamespacedName from the start.

@liggitt
Copy link
Member

liggitt commented Apr 13, 2023

/lgtm
/approve

I updated the release note to remove the reference to consistency with controller-runtime / API standards, since neither of those are things that we promise log output will match

I'm on the fence about picking to 1.27.1... I could go either way

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 13, 2023
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: e353a4917eb359207bf1541da37598ad9045d83d

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: liggitt, pohly

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

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 13, 2023
@liggitt liggitt changed the title api: encode NamespacedName with lower case in JSON encode NamespacedName with lower case in JSON Apr 13, 2023
@liggitt
Copy link
Member

liggitt commented Apr 13, 2023

/remove-kind bug
/kind cleanup

@k8s-ci-robot k8s-ci-robot added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. and removed kind/bug Categorizes issue or PR as related to a bug. labels Apr 13, 2023
@liggitt
Copy link
Member

liggitt commented Apr 13, 2023

/remove-kind failing-test

@k8s-ci-robot k8s-ci-robot removed the kind/failing-test Categorizes issue or PR as related to a consistently or frequently failing test. label Apr 13, 2023
@k8s-ci-robot k8s-ci-robot merged commit b98659b into kubernetes:master Apr 13, 2023
@k8s-ci-robot k8s-ci-robot added this to the v1.28 milestone Apr 13, 2023
@pohly
Copy link
Contributor Author

pohly commented Apr 13, 2023

The release note now describes the inconsistency with klog.KObj.

@pohly
Copy link
Contributor Author

pohly commented Apr 13, 2023

Let's backport. There's no need to make the life of our downstream consumers harder than it has to be. We still reserve the right to make log changes when it's necessary, but in this case it wasn't. In a way we should be thankful for the test in component-base because it highlighted a bad (= inconsistent) choice.

@pohly
Copy link
Contributor Author

pohly commented Apr 13, 2023

=> #117298

@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 Apr 18, 2023
k8s-ci-robot added a commit that referenced this pull request May 4, 2023
…8-origin-release-1.27

Automated cherry pick of #117238: api: encode NamespacedName with lower case in JSON
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/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/architecture Categorizes an issue or PR as relevant to SIG Architecture. sig/instrumentation Categorizes an issue or PR as relevant to SIG Instrumentation. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on. wg/structured-logging Categorizes an issue or PR as relevant to WG Structured Logging.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants