55 Commits

Author SHA1 Message Date
Kubernetes Prow Robot
d12fae55d0 Merge pull request #131001 from Chulong-Li/winstats-contextual-logging
Migrate pkg/kubelet/winstats to contextual logging
2025-07-24 17:58:26 -07:00
Kubernetes Prow Robot
9eb462ef4a Merge pull request #131306 from Chulong-Li/volumemanager-contextual-logging
Migrate pkg/kubelet/volumemanager to contextual logging
2025-07-24 10:50:27 -07:00
Chulong Li
bf98e45afb Migrate pkg/kubelet/volumemanager to contextual logging
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
2025-07-24 21:20:12 +08:00
Chulong Li
f626e847e7 Migrate pkg/kubelet/winstats to contextual logging
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
2025-07-22 20:44:53 +08:00
zhangzhifei16
911df655d3 chore: migrate kubelet lifecycle to contextual logging. 2025-07-22 10:14:42 +08:00
Kubernetes Prow Robot
ba35c0613d Merge pull request #132427 from soma00333/kuberuntime-contextual-logging-1
feat(kubelet): migrate kuberuntime to contextual logging
2025-07-21 05:50:36 -07:00
Swati Sehgal
b8758ac31b node: mm-mgr: migrate to contextual logging
Signed-off-by: Swati Sehgal <swsehgal@redhat.com>
2025-07-20 21:50:58 +01:00
soma00333
ab839c93ff feat(kubelet): migrate kuberuntime to contextual logging 2025-07-20 09:47:50 +09:00
soma00333
7ddb042626 feat(cmd/kubelet): support structured and contextual logging 2025-07-19 17:10:37 +09:00
Ed Bartosh
4bc2ad6eea migrate pkg/kubelet/preemption to contextual logging 2025-07-17 10:16:03 +03:00
Ed Bartosh
b96e3cac74 migrate pkg/kubelet/pod to contextual logging 2025-07-17 10:16:03 +03:00
Ed Bartosh
0cb31bc407 migrate pkg/kubelet/nodeshutdown to contextual logging 2025-07-17 10:16:03 +03:00
Ed Bartosh
75ccd69bab migrate pkg/kubelet/kubeletconfig to contextual logging 2025-07-17 10:16:03 +03:00
Ed Bartosh
7dad9e2af6 migrate pkg/kubelet/apis to contextual logging 2025-07-17 10:15:58 +03:00
Chulong Li
d868eeb088 Migrate pkg/kubelet/status to contextual logging
Update with logger from context

Fix nil pointer issue in TestUpdateReadiness
2025-03-20 21:58:14 +08:00
Ed Bartosh
71b9114840 kubelet: Migrate pkg/kubelet/sysctl to contextual logging 2025-01-30 10:31:58 +02:00
Kubernetes Prow Robot
8294abc599 Merge pull request #128998 from bart0sh/PR165-migrate-oom-to-contextual-logging
kubelet: Migrate pkg/kubelet/oom to contextual logging
2025-01-28 13:33:22 -08:00
Patrick Ohly
7821abf2ae client-go/rest: finish conversion to contextual logging
The remaining calls can be converted without API changes.
2025-01-22 07:58:18 +01:00
Patrick Ohly
4638ba9716 client-go/tools/cache: add APIs with context parameter
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.
2024-12-18 18:45:02 +01:00
Ed Bartosh
f622be0333 kubelet: Migrate pkg/kubelet/oom to contextual logging 2024-11-28 17:47:02 +02:00
Ed Bartosh
e5cb071c2e kubelet: Migrate CAdvisor to contextual logging 2024-11-06 01:49:20 +02:00
Oksana Baranova
49b88f1d8a kubelet: migrate clustertrustbundle, token to contextual logging
Signed-off-by: Oksana Baranova <oksana.baranova@intel.com>
2024-10-30 17:31:11 +02:00
Oksana Baranova
2474369227 kubelet: migrate pleg to contextual logging
Signed-off-by: Oksana Baranova <oksana.baranova@intel.com>
2024-09-13 12:13:26 +03:00
Ed Bartosh
e1bc8defac kubelet: Migrate DRA Manager to contextual logging
Co-authored-by: Patrick Ohly <patrick.ohly@intel.com>
2024-08-22 11:12:41 +03:00
bells17
1298c8a5fe csi-translation-lib: Support structured and contextual logging 2024-07-18 14:01:27 +09:00
carlory
7149cb9f5a Revert "Revert "remove legacycloudproviders from staging""
This reverts commit d9a0be3b01.
2024-05-15 20:10:09 +08:00
carlory
d9a0be3b01 Revert "remove legacycloudproviders from staging"
This reverts commit 07c8d35681.
2024-05-14 13:39:13 +08:00
carlory
07c8d35681 remove legacycloudproviders from staging 2024-05-09 11:59:43 +08:00
bells17
318ea033d5 Include k8s.io components with contextual logging in logcheck.conf 2024-05-07 20:35:33 +09:00
bells17
1c917aa463 component-helpers: Support structured and contextual logging (#120637) 2024-04-24 03:06:15 -07:00
Patrick Ohly
5a130d2b71 apimachinery runtime: support contextual logging
In contrast to the original HandleError and HandleCrash, the new
HandleErrorWithContext and HandleCrashWithContext functions properly do contextual
logging, so if a problem occurs while e.g. dealing with a certain request and
WithValues was used for that request, then the error log entry will also
contain information about it.

The output changes from unstructured to structured, which might be a breaking
change for users who grep for panics. Care was taken to format panics
as similar as possible to the original output.

For errors, a message string gets added. There was none before, which made it
impossible to find all error output coming from HandleError.

Keeping HandleError and HandleCrash around without deprecating while changing
the signature of callbacks is a compromise between not breaking existing code
and not adding too many special cases that need to be supported. There is some
code which uses PanicHandlers or ErrorHandlers, but less than code that uses
the Handle* calls.

In Kubernetes, we want to replace the calls. logcheck warns about them in code
which is supposed to be contextual. The steps towards that are:
- add TODO remarks as reminder (this commit)
- locally remove " TODO(pohly): " to enable the check with `//logcheck:context`,
  merge fixes for linter warnings
- once there are none, remove the TODO to enable the check permanently
2024-03-26 17:28:45 +01:00
Ziqi Zhao
6b5e973e5f Migrate cmd/kube-proxy to contextual logging (#122197)
* cmd/kube-proxy support contextual logging

Signed-off-by: Ziqi Zhao <zhaoziqi9146@gmail.com>

* use ktesting.NewTestContext(t) in unit test

Signed-off-by: Ziqi Zhao <zhaoziqi9146@gmail.com>

* use ktesting.NewTestContext(t) in unit test

Signed-off-by: Ziqi Zhao <zhaoziqi9146@gmail.com>

* remove unnecessary blank line & add cmd/kube-proxy to contextual section in logcheck.conf

Signed-off-by: Ziqi Zhao <zhaoziqi9146@gmail.com>

* add more contextual logging

Signed-off-by: Ziqi Zhao <zhaoziqi9146@gmail.com>

* new lint yaml

Signed-off-by: Ziqi Zhao <zhaoziqi9146@gmail.com>

---------

Signed-off-by: Ziqi Zhao <zhaoziqi9146@gmail.com>
2024-01-08 17:30:18 +01:00
Patrick Ohly
ced99383d5 logcheck: remove redundant entry for pkg/scheduler
Contextual implies structured, so listing pkg/scheduler as contextual is
enough.
2023-12-14 20:22:04 +01:00
Patrick Ohly
b450224c12 golangci-lint: inline logcheck configuration
This has the advantage that the golangci-lint cache gets invalidated
automatically each time the logcheck config changes.
2023-12-14 20:21:58 +01:00
Ricardo Lopes
86ab185fa1 Migrate client-go/metadata to contextual logging (#122225)
* client-go: migrate metadata to contextual logging

Signed-off-by: Ricardo Lopes <ricardoapl.dev@gmail.com>

* client-go: test for metadata contextual logs

Signed-off-by: Ricardo Lopes <ricardoapl.dev@gmail.com>

* refactor: extract context for table driven testing

Signed-off-by: Ricardo Lopes <ricardoapl.dev@gmail.com>

* refactor: pass context as first parameter

Signed-off-by: Ricardo Lopes <ricardoapl.dev@gmail.com>

---------

Signed-off-by: Ricardo Lopes <ricardoapl.dev@gmail.com>
2023-12-14 07:26:45 +01:00
Mengjiao Liu
2cea51221a hack/logcheck.conf: enable contextual logging in kube-scheduler 2023-10-24 17:56:59 +08:00
Patrick Ohly
27a68aee3a k8s.io/client-go/tools: support context for event recording
Using StartRecordingToSinkWithContext instead of StartRecordingToSink and
StartLogging instead of StartStructuredLogging has several advantages:

- Spawned goroutines no longer get stuck for extended periods of
  time during shutdown when passing in a context that gets canceled.
- Log output can be directed towards a specific logger instead of the global
  default, for example one which writes to a testing.T instance.
- The new methods return an error when something went wrong instead of
  merely recording the error.

That last point is the reason for deprecating the old methods instead of merely
adding new alternatives.

Setting a context when constructing an EventBroadcaster makes calling Shutdown
optional. It can also be used to specify the logger.

Both EventRecorder interfaces in tools/events and tools/record now have a
WithLogger helper. Using that method is optional, but recommended to support
contextual logging properly. Without it, errors that occur while emitting an
event are not associated with the caller.
2023-09-27 09:06:09 +02:00
Patrick Ohly
7d064812bb kube-controller-manager: finish conversion to contextual logging
This removes all exceptions and fixes the remaining unconverted log calls.
2023-07-12 14:57:29 +02:00
Mengjiao Liu
19869478c1 Migrate /pkg/controller/disruption to structured and contextual logging 2023-07-12 11:30:45 +08:00
Naman
09849b09cf migrated pkg/controller/endpointslice to contextual logging
Signed-off-by: Naman <namanlakhwani@gmail.com>
2023-07-11 01:28:22 +05:30
Kubernetes Prow Robot
10a12165de Merge pull request #116755 from my-git9/feat/endpoint/logging
Migrated `pkg/controller/endpoint` to contextual logging
2023-07-10 05:37:05 -07:00
Ziqi Zhao
dfc1838379 Migrated pkg/controller/volume|util|replicaset|nodeipam to contextual logging
Signed-off-by: Ziqi Zhao <zhaoziqi9146@gmail.com>
2023-07-06 07:39:52 +08:00
Kubernetes Prow Robot
91698fe900 Merge pull request #114061 from Octopusjust/k8s-pr15
testutil: use contextual logging
2023-07-05 08:38:57 -07:00
Kubernetes Prow Robot
28296ba59e Merge pull request #113994 from mengjiao-liu/contextual-logging-controller-certificates
certificate controller: use contextual logging
2023-06-21 09:03:42 -07:00
Ziqi Zhao
7bc449d7e0 add contextual logging to job-controller
Signed-off-by: Ziqi Zhao <zhaoziqi9146@gmail.com>
2023-06-14 13:40:02 +08:00
xin.li
325205efb7 Migrated pkg/controller/endpoint to contextual logging
Signed-off-by: xin.li <xin.li@daocloud.io>
2023-06-11 20:12:07 +08:00
ZhangYu
f9ae3e774d testutil: use contextual logging 2023-05-30 10:07:04 +08:00
kerthcet
6b4251c0fd Remove statefulset from logcheck.conf
Signed-off-by: kerthcet <kerthcet@gmail.com>
2023-05-18 16:55:19 +08:00
Mengjiao Liu
5588e8a4cd hack/logcheck.conf: remove certificate controller exception 2023-04-12 15:20:04 +08:00
Patrick Ohly
f26f896128 hack/logcheck.conf: enforce contextual logging in kube-controller-manager
Not all PRs made it into 1.27, but enough that it is now easier to list the
exceptions.
2023-03-14 19:17:31 +01:00