Code change:
<!-- Please use this template while reporting a bug and provide as much info as possible. Not doing so may result in your bug not being addressed in a timely manner. Thanks! If the matter is security related, please disclose it privately via --When is passed a ref while logging, it panics: or an empty reference should be logged. I have fixed this in so we will need to bump klog. ht for reporting in /priority critical-urgent /sig instrumentation
need update klog dependencies later. milestone 1.21
/milestone v1.21 Will set the milestone for the issue and let people review the PR during regular burndown.
Scope check: potentially affected components are: Kubelet Controller manager Scheduler (grep for KObj: )
I looked in current implementation of handling object. Please remember how checking works. Current fix should work on simple nil (): but it will fail on structs implementing KMetadata interface, but not handling nil pointer (). Reason is that interface with nil value is not nil. Resulting call to 'Log' function will panic on call. In stacktrace presented above it was function that panicked which leads to thinking that the problem is in function which panics if pointer is empty. Potential solutions: Replace all calls with until we solve this issue Fix this particular case where pod can be nil (solves only local problem, but not the long term issue that every log call can be a panic) Use reflection to verify if object under interface is an nil (expected overhead EDIT: got results only 7% increased cpu usage) Fix all and functions to check for nil (not enough time before the freeze, some overhead on calls) Do runtime checks for K8s types (would require klog to import api types) Looking at all options I think that first one makes most sense as all other have bad impact on whole k/k repo
Did benchmarking for using reflections, looks like performance overhead is not as significant as I previously anticipated, around 20%. I think we could consider using reflections.
/cc For feedback
/cc
There are hundreds of instances of in k/k now, and every single one would need to be carefully checked when obtaining the pod name/namespace, and we'd need a top-level approver to do the replacement. I think this really needs to be fixed in klog.
With benchmark results being not as bad as first estimated I think we could use reflection in klog like proposed in kubernetes/klog
/reopen needs to get bumped in k/k to close
Reopened this issue. <detailsIn response to : /reopen Instructions for interacting with me using PR comments are available . If you have questions or suggestions related to my behavior, please file an issue against the repository. </details
/triage accepted

Related discussion:
text: <ins> /* Copyright 2014 Google Inc. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package cloudcfg import ( "bytes" "encoding/json" "reflect" "testing" "gopkg.in/v1/yaml" ) func TestYAMLPrinterPrint(t *testing.T) { type testStruct struct { Key        string         `yaml:"Key" json:"Key"` Map        map[string]int `yaml:"Map" json:"Map"` StringList []string       `yaml:"StringList" json:"StringList"` IntList    []int          `yaml:"IntList" json:"IntList"` } testData := testStruct{ "testValue", map[string]int{"TestSubkey": 1}, []string{"a", "b", "c"}, []int{1, 2, 3}, } printer := &YAMLPrinter{} buf := bytes.NewBuffer([]byte{}) err := printer.Print([]byte("invalidJSON"), buf) if err == nil { t.Error("Error: didn't fail on invalid JSON data") } jTestData, err := json.Marshal(&testData) if err != nil { t.Fatal("Unexpected error: couldn't marshal test data") } err = printer.Print(jTestData, buf) if err != nil { t.Fatal(err) } var poutput testStruct err = yaml.Unmarshal(buf.Bytes(), &poutput) if err != nil { t.Fatal(err) } if !reflect.DeepEqual(testData, poutput) { t.Error("Test data and unmarshaled data are not equal") } } </ins>