mirror of
https://github.com/kubernetes/kubernetes.git
synced 2026-03-21 18:11:55 -04:00
This fixes a bug that caused log calls involving `klog.Logger` to not be
checked.
As a result we have to fix some code that is now considered faulty:
ERROR: pkg/controller/serviceaccount/tokens_controller.go:382:1: A function should accept either a context or a logger, but not both. Having both makes calling the function harder because it must be defined whether the context must contain the logger and callers have to follow that. (logcheck)
ERROR: func (e *TokensController) generateTokenIfNeeded(ctx context.Context, logger klog.Logger, serviceAccount *v1.ServiceAccount, cachedSecret *v1.Secret) ( /* retry */ bool, error) {
ERROR: ^
ERROR: pkg/controller/storageversionmigrator/storageversionmigrator.go:299:1: A function should accept either a context or a logger, but not both. Having both makes calling the function harder because it must be defined whether the context must contain the logger and callers have to follow that. (logcheck)
ERROR: func (svmc *SVMController) runMigration(ctx context.Context, logger klog.Logger, gvr schema.GroupVersionResource, resourceMonitor *garbagecollector.Monitor, toBeProcessedSVM *svmv1beta1.StorageVersionMigration, listResourceVersion string) (err error, failed bool) {
ERROR: ^
ERROR: pkg/proxy/node.go:121:3: logging function "Error" should not use format specifier "%q" (logcheck)
ERROR: klog.FromContext(ctx).Error(nil, "Timed out waiting for node %q to exist", nodeName)
ERROR: ^
ERROR: pkg/proxy/node.go:123:3: logging function "Error" should not use format specifier "%q" (logcheck)
ERROR: klog.FromContext(ctx).Error(nil, "Timed out waiting for node %q to be assigned IPs", nodeName)
ERROR: ^
ERROR: pkg/scheduler/backend/queue/scheduling_queue.go:610:1: A function should accept either a context or a logger, but not both. Having both makes calling the function harder because it must be defined whether the context must contain the logger and callers have to follow that. (logcheck)
ERROR: func (p *PriorityQueue) runPreEnqueuePlugin(ctx context.Context, logger klog.Logger, pl fwk.PreEnqueuePlugin, pInfo *framework.QueuedPodInfo, shouldRecordMetric bool) *fwk.Status {
ERROR: ^
ERROR: pkg/scheduler/framework/plugins/dynamicresources/extendeddynamicresources.go:286:1: A function should accept either a context or a logger, but not both. Having both makes calling the function harder because it must be defined whether the context must contain the logger and callers have to follow that. (logcheck)
ERROR: func (pl *DynamicResources) deleteClaim(ctx context.Context, claim *resourceapi.ResourceClaim, logger klog.Logger) error {
ERROR: ^
ERROR: pkg/scheduler/framework/plugins/dynamicresources/extendeddynamicresources.go:499:1: A function should accept either a context or a logger, but not both. Having both makes calling the function harder because it must be defined whether the context must contain the logger and callers have to follow that. (logcheck)
ERROR: func (pl *DynamicResources) waitForExtendedClaimInAssumeCache(
ERROR: ^
ERROR: pkg/scheduler/framework/plugins/dynamicresources/extendeddynamicresources.go:528:1: A function should accept either a context or a logger, but not both. Having both makes calling the function harder because it must be defined whether the context must contain the logger and callers have to follow that. (logcheck)
ERROR: func (pl *DynamicResources) createExtendedResourceClaimInAPI(
ERROR: ^
ERROR: pkg/scheduler/framework/plugins/dynamicresources/extendeddynamicresources.go:592:1: A function should accept either a context or a logger, but not both. Having both makes calling the function harder because it must be defined whether the context must contain the logger and callers have to follow that. (logcheck)
ERROR: func (pl *DynamicResources) unreserveExtendedResourceClaim(ctx context.Context, logger klog.Logger, pod *v1.Pod, state *stateData) {
ERROR: ^
ERROR: pkg/scheduler/framework/runtime/batch.go:171:1: A function should accept either a context or a logger, but not both. Having both makes calling the function harder because it must be defined whether the context must contain the logger and callers have to follow that. (logcheck)
ERROR: func (b *OpportunisticBatch) batchStateCompatible(ctx context.Context, logger klog.Logger, pod *v1.Pod, signature fwk.PodSignature, cycleCount int64, state fwk.CycleState, nodeInfos fwk.NodeInfoLister) bool {
ERROR: ^
ERROR: staging/src/k8s.io/component-base/featuregate/feature_gate.go:890:4: Additional arguments to Info should always be Key Value pairs. Please check if there is any key or value missing. (logcheck)
ERROR: logger.Info("Warning: SetEmulationVersionAndMinCompatibilityVersion will change already queried feature", "featureGate", feature, "oldValue", oldVal, newVal)
ERROR: ^
ERROR: test/images/sample-device-plugin/sampledeviceplugin.go:108:2: logging function "Info" should not use format specifier "%s" (logcheck)
ERROR: logger.Info("pluginSocksDir: %s", pluginSocksDir)
ERROR: ^
ERROR: test/images/sample-device-plugin/sampledeviceplugin.go:123:2: logging function "Info" should not use format specifier "%s" (logcheck)
ERROR: logger.Info("CDI_ENABLED: %s", cdiEnabled)
ERROR: ^
While waiting for this to merge, another call was added which also doesn't
follow conventions:
ERROR: pkg/kubelet/kubelet.go:2454:1: A function should accept either a context or a logger, but not both. Having both makes calling the function harder because it must be defined whether the context must contain the logger and callers have to follow that. (logcheck)
ERROR: func (kl *Kubelet) deletePod(ctx context.Context, logger klog.Logger, pod *v1.Pod) error {
ERROR: ^
Contextual logging has been beta and enabled by default for several releases
now. It's mostly just a matter of wrapping up and declaring it GA. Therefore
the calls which directly call WithName or WithValues (always have an effect)
are left as-is instead of converting them to use the klog wrappers (support
disabling the effect). To allow that, the linter gets reconfigured to not
complain about this anymore, anywhere.
The calls which would have to be fixed otherwise are:
ERROR: pkg/kubelet/cm/dra/claiminfo.go:170:11: function "WithName" should be called through klogr.LoggerWithName (logcheck)
ERROR: logger = logger.WithName("dra-claiminfo")
ERROR: ^
ERROR: pkg/kubelet/cm/dra/healthinfo.go:45:11: function "WithName" should be called through klogr.LoggerWithName (logcheck)
ERROR: logger = logger.WithName("dra-healthinfo")
ERROR: ^
ERROR: pkg/kubelet/cm/dra/healthinfo.go:89:11: function "WithName" should be called through klogr.LoggerWithName (logcheck)
ERROR: logger = logger.WithName("dra-healthinfo")
ERROR: ^
ERROR: pkg/kubelet/cm/dra/healthinfo.go:157:11: function "WithName" should be called through klogr.LoggerWithName (logcheck)
ERROR: logger = logger.WithName("dra-healthinfo")
ERROR: ^
ERROR: pkg/kubelet/cm/dra/manager.go:175:12: function "WithName" should be called through klogr.LoggerWithName (logcheck)
ERROR: logger := klog.FromContext(ctx).WithName("dra-manager")
ERROR: ^
ERROR: pkg/kubelet/cm/dra/manager.go:239:12: function "WithName" should be called through klogr.LoggerWithName (logcheck)
ERROR: logger := klog.FromContext(ctx).WithName("dra-manager")
ERROR: ^
ERROR: pkg/kubelet/cm/dra/manager.go:593:12: function "WithName" should be called through klogr.LoggerWithName (logcheck)
ERROR: logger := klog.FromContext(ctx).WithName("dra-manager")
ERROR: ^
ERROR: pkg/kubelet/cm/dra/manager.go:781:12: function "WithName" should be called through klogr.LoggerWithName (logcheck)
ERROR: logger := klog.FromContext(context.Background()).WithName("dra-manager")
ERROR: ^
ERROR: pkg/kubelet/cm/dra/manager.go:898:12: function "WithName" should be called through klogr.LoggerWithName (logcheck)
ERROR: logger := klog.FromContext(ctx).WithName("dra-manager")
ERROR: ^
ERROR: pkg/kubelet/cm/dra/manager_test.go:1638:15: function "WithName" should be called through klogr.LoggerWithName (logcheck)
ERROR: logger := klog.FromContext(streamCtx).WithName(st.Name())
ERROR: ^
ERROR: pkg/kubelet/cm/dra/plugin/dra_plugin.go:77:12: function "WithName" should be called through klogr.LoggerWithName (logcheck)
ERROR: logger := klog.FromContext(ctx).WithName("dra-plugin")
ERROR: ^
ERROR: pkg/kubelet/cm/dra/plugin/dra_plugin.go:108:12: function "WithName" should be called through klogr.LoggerWithName (logcheck)
ERROR: logger := klog.FromContext(ctx).WithName("dra-plugin")
ERROR: ^
ERROR: pkg/kubelet/cm/dra/plugin/dra_plugin.go:161:12: function "WithName" should be called through klogr.LoggerWithName (logcheck)
ERROR: logger := klog.FromContext(ctx).WithName("dra-plugin")
ERROR: ^
ERROR: staging/src/k8s.io/dynamic-resource-allocation/resourceslice/tracker/tracker.go:695:14: function "WithValues" should be called through klogr.LoggerWithValues (logcheck)
ERROR: logger := logger.WithValues("device", deviceID)
ERROR: ^
ERROR: test/integration/apiserver/watchcache_test.go:42:54: function "WithName" should be called through klogr.LoggerWithName (logcheck)
ERROR: etcd0URL, stopEtcd0, err := framework.RunCustomEtcd(klog.FromContext(ctx).WithName("etcd0"), "etcd_watchcache0", etcdArgs)
ERROR: ^
ERROR: test/integration/apiserver/watchcache_test.go:47:54: function "WithName" should be called through klogr.LoggerWithName (logcheck)
ERROR: etcd1URL, stopEtcd1, err := framework.RunCustomEtcd(klog.FromContext(ctx).WithName("etcd1"), "etcd_watchcache1", etcdArgs)
ERROR: ^
ERROR: test/integration/scheduler_perf/scheduler_perf.go:1149:12: function "WithName" should be called through klogr.LoggerWithName (logcheck)
ERROR: logger = logger.WithName(tCtx.Name())
ERROR: ^
73 lines
3.3 KiB
Text
73 lines
3.3 KiB
Text
# hack/logcheck.conf contains regular expressions that are matched against <pkg>/<file>,
|
|
# for example k8s.io/cmd/kube-scheduler/app/config/config.go.
|
|
#
|
|
# By default, structured logging call parameters are checked, but usage of
|
|
# those calls is not required. That is changed on a per-file basis.
|
|
#
|
|
# Remember to clean the golangci-lint cache when changing the configuration and
|
|
# running the verify-golangci-lint.sh script multiple times, otherwise
|
|
# golangci-lint will report stale results:
|
|
# _output/local/bin/golangci-lint cache clean
|
|
|
|
# At this point we don't enforce the usage structured logging calls except in
|
|
# those packages that were migrated. This disables the check for other files.
|
|
-structured .*
|
|
|
|
# Now enable it again for migrated packages.
|
|
structured k8s.io/kubernetes/pkg/kubelet/.*
|
|
structured k8s.io/kubernetes/pkg/proxy/.*
|
|
structured k8s.io/kms/.*
|
|
structured k8s.io/apiserver/pkg/storage/value/.*
|
|
structured k8s.io/apiserver/pkg/server/options/encryptionconfig/.*
|
|
structured k8s.io/kubernetes/pkg/credentialprovider/plugin/.*
|
|
|
|
# The following packages have been migrated to contextual logging.
|
|
# Packages matched here do not have to be listed above because
|
|
# "contextual" implies "structured".
|
|
contextual k8s.io/api/.*
|
|
contextual k8s.io/apimachinery/pkg/util/runtime/.*
|
|
contextual k8s.io/client-go/metadata/.*
|
|
contextual k8s.io/client-go/rest/.*
|
|
contextual k8s.io/client-go/tools/cache/.*
|
|
contextual k8s.io/client-go/tools/events/.*
|
|
contextual k8s.io/client-go/tools/record/.*
|
|
contextual k8s.io/component-base/featuregate/*
|
|
contextual k8s.io/component-helpers/.*
|
|
contextual k8s.io/cri-api/.*
|
|
contextual k8s.io/cri-client/.*
|
|
contextual k8s.io/csi-translation-lib/.*
|
|
contextual k8s.io/dynamic-resource-allocation/.*
|
|
contextual k8s.io/endpointslice/.*
|
|
contextual k8s.io/kms/.*
|
|
contextual k8s.io/kube-controller-manager/.*
|
|
contextual k8s.io/kube-proxy/.*
|
|
contextual k8s.io/kube-scheduler/.*
|
|
contextual k8s.io/sample-apiserver/.*
|
|
contextual k8s.io/sample-cli-plugin/.*
|
|
contextual k8s.io/sample-controller/.*
|
|
contextual k8s.io/kubernetes/cmd/kube-proxy/.*
|
|
contextual k8s.io/kubernetes/cmd/kube-scheduler/.*
|
|
contextual k8s.io/kubernetes/cmd/kubelet/.*
|
|
contextual k8s.io/kubernetes/pkg/api/.*
|
|
contextual k8s.io/kubernetes/pkg/apis/.*
|
|
contextual k8s.io/kubernetes/pkg/capabilities/.*
|
|
contextual k8s.io/kubernetes/pkg/client/.*
|
|
contextual k8s.io/kubernetes/pkg/cluster/.*
|
|
contextual k8s.io/kubernetes/pkg/controller/.*
|
|
contextual k8s.io/kubernetes/pkg/features/.*
|
|
contextual k8s.io/kubernetes/pkg/fieldpath/.*
|
|
contextual k8s.io/kubernetes/pkg/generated/.*
|
|
contextual k8s.io/kubernetes/pkg/printers/.*
|
|
contextual k8s.io/kubernetes/pkg/quota/.*
|
|
contextual k8s.io/kubernetes/pkg/scheduler/.*
|
|
contextual k8s.io/kubernetes/pkg/security/.*
|
|
contextual k8s.io/kubernetes/pkg/securitycontext/.*
|
|
contextual k8s.io/kubernetes/test/e2e/dra/.*
|
|
contextual k8s.io/kubernetes/test/images/sample-device-plugin/.*
|
|
contextual k8s.io/kubernetes/pkg/kubelet/.*
|
|
# Temporary carve-outs for PR1 split safety: these files still have legacy global klog calls.
|
|
# TODO: remove each exclusion as follow-up PRs migrate the file to contextual logging.
|
|
-contextual k8s.io/kubernetes/pkg/kubelet/kubelet_resources.go
|
|
-contextual k8s.io/kubernetes/pkg/kubelet/kubelet_volumes.go
|
|
-contextual k8s.io/kubernetes/pkg/kubelet/pod_container_deletor.go
|
|
-contextual k8s.io/kubernetes/pkg/kubelet/volume_host.go
|