Skip to content

Fix potential nil pointer dereferences in kubelet-to-gcm#1203

Open
courageJ wants to merge 1 commit into
GoogleCloudPlatform:masterfrom
courageJ:fix/kubelet-poll-marshaling
Open

Fix potential nil pointer dereferences in kubelet-to-gcm#1203
courageJ wants to merge 1 commit into
GoogleCloudPlatform:masterfrom
courageJ:fix/kubelet-poll-marshaling

Conversation

@courageJ
Copy link
Copy Markdown
Contributor

This PR hardens the kubelet-to-gcm monitoring daemon against crashes by adding nil pointer protections across several components.

Changes

  • Translation Logic: Added nil checks for optional Kubelet stats fields (UsedBytes in FsStats, MajorPageFaults in MemoryStats) before dereferencing them in monitor/kubelet/translate.go.
  • Service & Client Safety: Added nil checks for the GCM service pointer in the Once function (monitor/poll.go) and for HTTP responses in client helpers (monitor/controller/client.go and monitor/kubelet/client.go) to prevent panics during defer response.Body.Close().
  • Helpers: Added Uint64Ptr to the monitor package for parity with existing pointer helpers.
  • Testing: Added a TestTranslator_NilFields regression test in monitor/kubelet/translate_test.go to verify that missing optional fields in stats.Summary do not cause panics.

Verification

  • All existing unit tests passed.
  • New regression test TestTranslator_NilFields passed and verified the fixes.

@courageJ courageJ requested a review from erain May 21, 2026 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant