Skip to content

Commit 0edef5a

Browse files
authored
Merge pull request kubernetes#128447 from bart0sh/PR164-migrate-cadvisor-to-contextual-logging
kubelet: Migrate CAdvisor to contextual logging
2 parents 198ec57 + e5cb071 commit 0edef5a

15 files changed

+82
-64
lines changed

hack/golangci-hints.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ linters-settings: # please keep this alphabetized
167167
contextual k8s.io/kubernetes/pkg/kubelet/pleg/.*
168168
contextual k8s.io/kubernetes/pkg/kubelet/clustertrustbundle/.*
169169
contextual k8s.io/kubernetes/pkg/kubelet/token/.*
170+
contextual k8s.io/kubernetes/pkg/kubelet/cadvisor/.*
170171
171172
# As long as contextual logging is alpha or beta, all WithName, WithValues,
172173
# NewContext calls have to go through klog. Once it is GA, we can lift

hack/golangci-strict.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ linters-settings: # please keep this alphabetized
213213
contextual k8s.io/kubernetes/pkg/kubelet/pleg/.*
214214
contextual k8s.io/kubernetes/pkg/kubelet/clustertrustbundle/.*
215215
contextual k8s.io/kubernetes/pkg/kubelet/token/.*
216+
contextual k8s.io/kubernetes/pkg/kubelet/cadvisor/.*
216217
217218
# As long as contextual logging is alpha or beta, all WithName, WithValues,
218219
# NewContext calls have to go through klog. Once it is GA, we can lift

hack/golangci.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ linters-settings: # please keep this alphabetized
215215
contextual k8s.io/kubernetes/pkg/kubelet/pleg/.*
216216
contextual k8s.io/kubernetes/pkg/kubelet/clustertrustbundle/.*
217217
contextual k8s.io/kubernetes/pkg/kubelet/token/.*
218+
contextual k8s.io/kubernetes/pkg/kubelet/cadvisor/.*
218219
219220
# As long as contextual logging is alpha or beta, all WithName, WithValues,
220221
# NewContext calls have to go through klog. Once it is GA, we can lift

hack/logcheck.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ contextual k8s.io/kubernetes/pkg/kubelet/cm/dra/.*
5151
contextual k8s.io/kubernetes/pkg/kubelet/pleg/.*
5252
contextual k8s.io/kubernetes/pkg/kubelet/clustertrustbundle/.*
5353
contextual k8s.io/kubernetes/pkg/kubelet/token/.*
54+
contextual k8s.io/kubernetes/pkg/kubelet/cadvisor/.*
5455

5556
# As long as contextual logging is alpha or beta, all WithName, WithValues,
5657
# NewContext calls have to go through klog. Once it is GA, we can lift

pkg/kubelet/cadvisor/cadvisor_linux.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ limitations under the License.
2020
package cadvisor
2121

2222
import (
23+
"context"
2324
"flag"
2425
"fmt"
2526
"net/http"
@@ -71,7 +72,8 @@ func init() {
7172
f.DefValue = defaultValue
7273
f.Value.Set(defaultValue)
7374
} else {
74-
klog.ErrorS(nil, "Expected cAdvisor flag not found", "flag", name)
75+
ctx := context.Background()
76+
klog.FromContext(ctx).Error(nil, "Expected cAdvisor flag not found", "flag", name)
7577
}
7678
}
7779
}
@@ -140,19 +142,19 @@ func (cc *cadvisorClient) MachineInfo() (*cadvisorapi.MachineInfo, error) {
140142
return cc.GetMachineInfo()
141143
}
142144

143-
func (cc *cadvisorClient) ImagesFsInfo() (cadvisorapiv2.FsInfo, error) {
145+
func (cc *cadvisorClient) ImagesFsInfo(ctx context.Context) (cadvisorapiv2.FsInfo, error) {
144146
label, err := cc.imageFsInfoProvider.ImageFsInfoLabel()
145147
if err != nil {
146148
return cadvisorapiv2.FsInfo{}, err
147149
}
148-
return cc.getFsInfo(label)
150+
return cc.getFsInfo(ctx, label)
149151
}
150152

151153
func (cc *cadvisorClient) RootFsInfo() (cadvisorapiv2.FsInfo, error) {
152154
return cc.GetDirFsInfo(cc.rootPath)
153155
}
154156

155-
func (cc *cadvisorClient) getFsInfo(label string) (cadvisorapiv2.FsInfo, error) {
157+
func (cc *cadvisorClient) getFsInfo(ctx context.Context, label string) (cadvisorapiv2.FsInfo, error) {
156158
res, err := cc.GetFsInfo(label)
157159
if err != nil {
158160
return cadvisorapiv2.FsInfo{}, err
@@ -162,16 +164,16 @@ func (cc *cadvisorClient) getFsInfo(label string) (cadvisorapiv2.FsInfo, error)
162164
}
163165
// TODO(vmarmol): Handle this better when a label has more than one image filesystem.
164166
if len(res) > 1 {
165-
klog.InfoS("More than one filesystem labeled. Only using the first one", "label", label, "fileSystem", res)
167+
klog.FromContext(ctx).Info("More than one filesystem labeled. Only using the first one", "label", label, "fileSystem", res)
166168
}
167169

168170
return res[0], nil
169171
}
170172

171-
func (cc *cadvisorClient) ContainerFsInfo() (cadvisorapiv2.FsInfo, error) {
173+
func (cc *cadvisorClient) ContainerFsInfo(ctx context.Context) (cadvisorapiv2.FsInfo, error) {
172174
label, err := cc.imageFsInfoProvider.ContainerFsInfoLabel()
173175
if err != nil {
174176
return cadvisorapiv2.FsInfo{}, err
175177
}
176-
return cc.getFsInfo(label)
178+
return cc.getFsInfo(ctx, label)
177179
}

pkg/kubelet/cadvisor/cadvisor_unsupported.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ limitations under the License.
2020
package cadvisor
2121

2222
import (
23+
"context"
2324
"errors"
2425

2526
cadvisorapi "github.com/google/cadvisor/info/v1"
@@ -58,15 +59,15 @@ func (cu *cadvisorUnsupported) VersionInfo() (*cadvisorapi.VersionInfo, error) {
5859
return nil, errUnsupported
5960
}
6061

61-
func (cu *cadvisorUnsupported) ImagesFsInfo() (cadvisorapiv2.FsInfo, error) {
62+
func (cu *cadvisorUnsupported) ImagesFsInfo(context.Context) (cadvisorapiv2.FsInfo, error) {
6263
return cadvisorapiv2.FsInfo{}, errUnsupported
6364
}
6465

6566
func (cu *cadvisorUnsupported) RootFsInfo() (cadvisorapiv2.FsInfo, error) {
6667
return cadvisorapiv2.FsInfo{}, errUnsupported
6768
}
6869

69-
func (cu *cadvisorUnsupported) ContainerFsInfo() (cadvisorapiv2.FsInfo, error) {
70+
func (cu *cadvisorUnsupported) ContainerFsInfo(context.Context) (cadvisorapiv2.FsInfo, error) {
7071
return cadvisorapiv2.FsInfo{}, errUnsupported
7172
}
7273

pkg/kubelet/cadvisor/cadvisor_windows.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ limitations under the License.
2020
package cadvisor
2121

2222
import (
23+
"context"
24+
2325
cadvisorapi "github.com/google/cadvisor/info/v1"
2426
cadvisorapiv2 "github.com/google/cadvisor/info/v2"
2527
"k8s.io/kubernetes/pkg/kubelet/winstats"
@@ -62,11 +64,11 @@ func (cu *cadvisorClient) VersionInfo() (*cadvisorapi.VersionInfo, error) {
6264
return cu.winStatsClient.WinVersionInfo()
6365
}
6466

65-
func (cu *cadvisorClient) ImagesFsInfo() (cadvisorapiv2.FsInfo, error) {
67+
func (cu *cadvisorClient) ImagesFsInfo(context.Context) (cadvisorapiv2.FsInfo, error) {
6668
return cadvisorapiv2.FsInfo{}, nil
6769
}
6870

69-
func (cu *cadvisorClient) ContainerFsInfo() (cadvisorapiv2.FsInfo, error) {
71+
func (cu *cadvisorClient) ContainerFsInfo(context.Context) (cadvisorapiv2.FsInfo, error) {
7072
return cadvisorapiv2.FsInfo{}, nil
7173
}
7274

pkg/kubelet/cadvisor/testing/cadvisor_fake.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717
package testing
1818

1919
import (
20+
"context"
21+
2022
cadvisorapi "github.com/google/cadvisor/info/v1"
2123
cadvisorapiv2 "github.com/google/cadvisor/info/v2"
2224
"k8s.io/kubernetes/pkg/kubelet/cadvisor"
@@ -76,7 +78,7 @@ func (c *Fake) VersionInfo() (*cadvisorapi.VersionInfo, error) {
7678
}
7779

7880
// ImagesFsInfo is a fake implementation of Interface.ImagesFsInfo.
79-
func (c *Fake) ImagesFsInfo() (cadvisorapiv2.FsInfo, error) {
81+
func (c *Fake) ImagesFsInfo(context.Context) (cadvisorapiv2.FsInfo, error) {
8082
return cadvisorapiv2.FsInfo{}, nil
8183
}
8284

@@ -86,7 +88,7 @@ func (c *Fake) RootFsInfo() (cadvisorapiv2.FsInfo, error) {
8688
}
8789

8890
// ContainerFsInfo is a fake implementation of Interface.ContainerFsInfo.
89-
func (c *Fake) ContainerFsInfo() (cadvisorapiv2.FsInfo, error) {
91+
func (c *Fake) ContainerFsInfo(context.Context) (cadvisorapiv2.FsInfo, error) {
9092
return cadvisorapiv2.FsInfo{}, nil
9193
}
9294

pkg/kubelet/cadvisor/testing/cadvisor_mock.go

Lines changed: 32 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/kubelet/cadvisor/types.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ limitations under the License.
1818
package cadvisor
1919

2020
import (
21+
"context"
22+
2123
cadvisorapi "github.com/google/cadvisor/info/v1"
2224
cadvisorapiv2 "github.com/google/cadvisor/info/v2"
2325
)
@@ -32,14 +34,14 @@ type Interface interface {
3234
VersionInfo() (*cadvisorapi.VersionInfo, error)
3335

3436
// Returns usage information about the filesystem holding container images.
35-
ImagesFsInfo() (cadvisorapiv2.FsInfo, error)
37+
ImagesFsInfo(context.Context) (cadvisorapiv2.FsInfo, error)
3638

3739
// Returns usage information about the root filesystem.
3840
RootFsInfo() (cadvisorapiv2.FsInfo, error)
3941

4042
// Returns usage information about the writeable layer.
4143
// KEP 4191 can separate the image filesystem
42-
ContainerFsInfo() (cadvisorapiv2.FsInfo, error)
44+
ContainerFsInfo(context.Context) (cadvisorapiv2.FsInfo, error)
4345

4446
// Get filesystem information for the filesystem that contains the given file.
4547
GetDirFsInfo(path string) (cadvisorapiv2.FsInfo, error)

0 commit comments

Comments
 (0)