Skip to content

Fix KObjSlice logging nil pointer entries as empty string#438

Merged
kubernetes-prow[bot] merged 1 commit into
kubernetes:mainfrom
iasolanki:fix-kobjslice-nil-entry
Jul 8, 2026
Merged

Fix KObjSlice logging nil pointer entries as empty string#438
kubernetes-prow[bot] merged 1 commit into
kubernetes:mainfrom
iasolanki:fix-kobjslice-nil-entry

Conversation

@iasolanki

Copy link
Copy Markdown

What this PR does / why we need it:

KObjSlice passes each slice entry to KObj, which converts a nil pointer into an empty ObjectRef. That empty ObjectRef was rendered as an empty string (""), making a nil entry indistinguishable from an object with an empty name. An untyped nil entry was already logged as null, but a typed nil pointer (e.g. []*T{nil}) was not, because it is a non-nil interface wrapping a nil pointer. This detects nil pointer entries in both the structured (process) and text (WriteText) paths and logs them as null.

Which issue(s) this PR fixes:
Fixes #409

Special notes for your reviewer:

Added a KObjSlice typed nil entry test case covering []*kmeta{..., nil}. It produces the same expected output as the existing KObjSlice nil entry case, so it reuses the existing expected-output mapping and no backend mappings changed.

Release note:

Fixed `KObjSlice` logging a typed nil pointer entry as an empty string instead of `null`.

@k8s-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: iasolanki
Once this PR has been reviewed and has the lgtm label, please assign thockin for approval. For more information see the Code Review Process.

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

Details 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 needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Jun 14, 2026
@k8s-ci-robot

Copy link
Copy Markdown

This issue is currently awaiting triage.

If klog contributors determine this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Details

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-sigs/prow repository.

@k8s-ci-robot

Copy link
Copy Markdown

Welcome @iasolanki!

It looks like this is your first PR to kubernetes/klog 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/klog has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jun 14, 2026
@iasolanki

iasolanki commented Jun 15, 2026

Copy link
Copy Markdown
Author

Friendly ping for a kubernetes org member when someone has a minute — first time contributor here. CC @pohly @harshanarayana or any other reviewer on the OWNERS list. Thanks!

Comment thread k8s_references.go
Comment thread k8s_references.go
@kubernetes-prow kubernetes-prow Bot 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 Jul 4, 2026

@pohly pohly left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You can squash directly into one commit, the force-push link from GitHub still shows the incremental changes.

Comment thread k8s_references_test.go Outdated
@iasolanki iasolanki force-pushed the fix-kobjslice-nil-entry branch from 0c90f10 to 1a6999a Compare July 7, 2026 03:43
Comment thread k8s_references_test.go Outdated
// and the structured output used by logr backends. Both must render a nil
// pointer entry as null rather than an empty ObjectRef.

func TestKObjSliceString(t *testing.T) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sorry, one more observation: both tests have exactly the same test cases, just different expected outcome for different operations on that input.

Can you consolidate into a single TestKObjSlice which has sub-tests "String" and "MarshalLog" for each test case?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I have consolidated into a single TestKObjSlice with sub-tests, please take a look.

KObjSlice passes each slice entry to KObj, which converts a nil pointer
into an empty ObjectRef. That empty ObjectRef was then rendered as an
empty string (""), making a nil entry indistinguishable from an object
with an empty name.

A literal nil entry (untyped nil in the slice) was already handled and
logged as null, but a typed nil pointer (e.g. []*T{nil}) was not,
because it is a non-nil interface wrapping a nil pointer.

Detect nil pointer entries in both the structured (process) and text
(WriteText) code paths and log them as null, consistent with how an
untyped nil entry is already handled. For a non-nil entry the ObjectRef
is built inline rather than via KObj, so the added nil check does not
reflect on the value a second time.

Add a KObjSlice typed-nil-entry output test plus direct unit tests for
kobjSlice.String and kobjSlice.MarshalLog, the two paths that go through
process().
@iasolanki iasolanki force-pushed the fix-kobjslice-nil-entry branch from 1a6999a to 5f193aa Compare July 8, 2026 03:30

@pohly pohly left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

/lgtm
/approve

@kubernetes-prow

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

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

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

The pull request process is described here

Details 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

@kubernetes-prow kubernetes-prow Bot added approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm "Looks good to me", indicates that a PR is ready to be merged. labels Jul 8, 2026
@pohly

pohly commented Jul 8, 2026

Copy link
Copy Markdown

/assign @dims

Please approve the workflows.

@kubernetes-prow kubernetes-prow Bot merged commit 6e29b68 into kubernetes:main Jul 8, 2026
2 checks passed
@iasolanki

iasolanki commented Jul 8, 2026

Copy link
Copy Markdown
Author

@pohly Thanks for your approval. Just an heads-up, post-merge CI on main is red, but it's not from this change. Both Test and Run lint fail at the Set up job step, before any code is checked out or run:

The actions actions/setup-go@v5 and actions/checkout@v4 are not allowed in kubernetes/klog because all actions must be pinned to a full-length commit SHA.

The org-wide "actions must be pinned to a full commit SHA" policy is now being enforced, and the workflows still use version tags.

@dims

dims commented Jul 8, 2026

Copy link
Copy Markdown
Member

@iasolanki do you mind creating a PR for pinning the version to SHA(s) please?

@iasolanki

Copy link
Copy Markdown
Author

@dims opened #439 to pin the actions to full-length commit SHAs, as requested. It covers both workflows:

Action Version SHA
actions/checkout v4.3.1 34e114876b0b11c390a56381ad16ebd13914f8d5
actions/setup-go v5.6.0 40f1582b2485089dde7abd97c1529aa768e1baff
golangci/golangci-lint-action v6.5.2 55c2c1448f86e01eaae002a5a3a9624417608d84

Each SHA is pinned to the latest release of the major version already in use (no version bumps), with the tag kept in a trailing comment. Please take a look and since this touches .github/workflows, it'll likely need your /approve and a workflow-run approval to go green. Thanks!

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. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. 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.

KObjSlice: nil entry printed as ""

4 participants