This is primarily useful in unit tests and therefore supported by
featuregate/testing. Without this, all warnings are emitted to stderr, with no
connection to the test which caused the warning to be emitted.
When a single test fails, `go test` started by showing all warnings triggered by
any test, not just the failed test:
I1121 18:50:28.112284 396950 feature_gate.go:466] feature gates: {map[DRADeviceTaintRules:true DRADeviceTaints:true]}
...
I1121 18:50:29.704907 396950 feature_gate.go:466] feature gates: {map[DRADeviceTaintRules:false DRADeviceTaints:false]}
--- FAIL: TestAll (1.58s)
--- FAIL: TestAll/Eviction (0.02s)
This warning was actually slightly broken: it passed an atomic.Value to Infof,
not the map. This violates the "must not be copied after first use" rule
for atomic.Value (thus wasn't thread-safe) and printed the value in an awkward
way (extra {}).
Now it shows that the feature gates are modified inside TestAll (in this example):
--- FAIL: TestAll (1.56s)
feature_gate.go:170: I1124 17:31:27.245108] Updated featureGates={"DRADeviceTaintRules":true,"DRADeviceTaints":true}
--- FAIL: TestAll/Eviction (0.02s)
--- FAIL: TestAll/Eviction/initial (0.00s)
...
feature_gate.go:170: I1124 17:31:28.821975] Updated featureGates={"DRADeviceTaintRules":false,"DRADeviceTaints":false}
FAIL
FAIL k8s.io/kubernetes/pkg/controller/devicetainteviction 1.602s
add cpumanager to contextual logging linter
regenerate with
```hack/update-golangci-lint-config.sh```
Signed-off-by: Francesco Romani <fromani@redhat.com>
Remove context.TODO and context.Background
Fix linter error in volume_manager_test
Fix QF1008: Could remove embedded field "ObjectMeta" from selector
Remove the extra code change
Remove the extra change
Update the NewTestContext
Update the order of imports to follow the standard convention
Quick update on import order for cadvisor_windows.go
Update the hack files
Update contextual logging in Test_convertWinApiToCadvisorApi
The context is used for cancellation and to support contextual logging.
In most cases, alternative *WithContext APIs get added, except for
NewIntegerResourceVersionMutationCache where code searches indicate that the
API is not used downstream.
An API break around SharedInformer couldn't be avoided because the
alternative (keeping the interface unchanged and adding a second one with
the new method) would have been worse. controller-runtime needs to be updated
because it implements that interface in a test package. Downstream consumers of
controller-runtime will work unless they use those test package.
Converting Kubernetes to use the other new alternatives will follow. In the
meantime, usage of the new alternatives cannot be enforced via logcheck
yet (see https://github.com/kubernetes/kubernetes/issues/126379 for the
process).
Passing context through and checking it for cancellation is tricky for event
handlers. A better approach is to map the context cancellation to the normal
removal of an event handler via a helper goroutine. Thanks to the new
HandleErrorWithLogr and HandleCrashWithLogr, remembering the logger is
sufficient for handling problems at runtime.