Skip to content

Commit 6c64593

Browse files
authored
Merge pull request kubernetes#120616 from kannon92/kubelet-disk-api-changes
Kubelet disk api changes
2 parents 1f69e12 + 26923b9 commit 6c64593

39 files changed

+3533
-764
lines changed

pkg/features/kube_features.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,12 @@ const (
454454
// Enable POD resources API to return allocatable resources
455455
KubeletPodResourcesGetAllocatable featuregate.Feature = "KubeletPodResourcesGetAllocatable"
456456

457+
// KubeletSeparateDiskGC enables Kubelet to garbage collection images/containers on different filesystems
458+
// owner: @kannon92
459+
// kep: https://kep.k8s.io/4191
460+
// alpha: v1.29
461+
KubeletSeparateDiskGC featuregate.Feature = "KubeletSeparateDiskGC"
462+
457463
// owner: @sallyom
458464
// kep: https://kep.k8s.io/2832
459465
// alpha: v1.25
@@ -1088,6 +1094,8 @@ var defaultKubernetesFeatureGates = map[featuregate.Feature]featuregate.FeatureS
10881094

10891095
KubeletPodResourcesGetAllocatable: {Default: true, PreRelease: featuregate.GA, LockToDefault: true}, // GA in 1.28, remove in 1.30
10901096

1097+
KubeletSeparateDiskGC: {Default: false, PreRelease: featuregate.Alpha},
1098+
10911099
KubeletTracing: {Default: true, PreRelease: featuregate.Beta},
10921100

10931101
KubeProxyDrainingTerminatingNodes: {Default: false, PreRelease: featuregate.Alpha},

pkg/kubelet/cadvisor/cadvisor_linux.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,14 @@ func (cc *cadvisorClient) getFsInfo(label string) (cadvisorapiv2.FsInfo, error)
186186
return res[0], nil
187187
}
188188

189+
func (cc *cadvisorClient) ContainerFsInfo() (cadvisorapiv2.FsInfo, error) {
190+
label, err := cc.imageFsInfoProvider.ContainerFsInfoLabel()
191+
if err != nil {
192+
return cadvisorapiv2.FsInfo{}, err
193+
}
194+
return cc.getFsInfo(label)
195+
}
196+
189197
func (cc *cadvisorClient) WatchEvents(request *events.Request) (*events.EventChannel, error) {
190198
return cc.WatchForEvents(request)
191199
}

pkg/kubelet/cadvisor/cadvisor_linux_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,32 @@ func TestImageFsInfoLabel(t *testing.T) {
5757
})
5858
}
5959
}
60+
61+
func TestContainerFsInfoLabel(t *testing.T) {
62+
testcases := []struct {
63+
description string
64+
runtime string
65+
runtimeEndpoint string
66+
expectedLabel string
67+
expectedError error
68+
}{{
69+
description: "LabelCrioWriteableImages should be returned",
70+
runtimeEndpoint: crio.CrioSocket,
71+
expectedLabel: LabelCrioContainers,
72+
expectedError: nil,
73+
}, {
74+
description: "Cannot find valid imagefs label",
75+
runtimeEndpoint: "",
76+
expectedLabel: "",
77+
expectedError: fmt.Errorf("no containerfs label for configured runtime"),
78+
}}
79+
80+
for _, tc := range testcases {
81+
t.Run(tc.description, func(t *testing.T) {
82+
infoProvider := NewImageFsInfoProvider(tc.runtimeEndpoint)
83+
label, err := infoProvider.ContainerFsInfoLabel()
84+
assert.Equal(t, tc.expectedLabel, label)
85+
assert.Equal(t, tc.expectedError, err)
86+
})
87+
}
88+
}

pkg/kubelet/cadvisor/cadvisor_unsupported.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ func (cu *cadvisorUnsupported) RootFsInfo() (cadvisorapiv2.FsInfo, error) {
7979
return cadvisorapiv2.FsInfo{}, errUnsupported
8080
}
8181

82+
func (cu *cadvisorUnsupported) ContainerFsInfo() (cadvisorapiv2.FsInfo, error) {
83+
return cadvisorapiv2.FsInfo{}, errUnsupported
84+
}
85+
8286
func (cu *cadvisorUnsupported) WatchEvents(request *events.Request) (*events.EventChannel, error) {
8387
return nil, errUnsupported
8488
}

pkg/kubelet/cadvisor/cadvisor_windows.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ func (cu *cadvisorClient) ImagesFsInfo() (cadvisorapiv2.FsInfo, error) {
7979
return cadvisorapiv2.FsInfo{}, nil
8080
}
8181

82+
func (cu *cadvisorClient) ContainerFsInfo() (cadvisorapiv2.FsInfo, error) {
83+
return cadvisorapiv2.FsInfo{}, nil
84+
}
85+
8286
func (cu *cadvisorClient) RootFsInfo() (cadvisorapiv2.FsInfo, error) {
8387
return cu.GetDirFsInfo(cu.rootPath)
8488
}

pkg/kubelet/cadvisor/helpers_linux.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ import (
2626
cadvisorfs "github.com/google/cadvisor/fs"
2727
)
2828

29+
// LabelCrioContainers is a label to allow for cadvisor to track writeable layers
30+
// separately from read-only layers.
31+
// Once CAdvisor upstream changes are merged, we should remove this constant
32+
const LabelCrioContainers string = "crio-containers"
33+
2934
// imageFsInfoProvider knows how to translate the configured runtime
3035
// to its file system label for images.
3136
type imageFsInfoProvider struct {
@@ -35,15 +40,28 @@ type imageFsInfoProvider struct {
3540
// ImageFsInfoLabel returns the image fs label for the configured runtime.
3641
// For remote runtimes, it handles additional runtimes natively understood by cAdvisor.
3742
func (i *imageFsInfoProvider) ImageFsInfoLabel() (string, error) {
38-
// This is a temporary workaround to get stats for cri-o from cadvisor
39-
// and should be removed.
40-
// Related to https://github.com/kubernetes/kubernetes/issues/51798
41-
if strings.HasSuffix(i.runtimeEndpoint, CrioSocketSuffix) {
43+
if detectCrioWorkaround(i) {
4244
return cadvisorfs.LabelCrioImages, nil
4345
}
4446
return "", fmt.Errorf("no imagefs label for configured runtime")
4547
}
4648

49+
// ContainerFsInfoLabel returns the container fs label for the configured runtime.
50+
// For remote runtimes, it handles addition runtimes natively understood by cAdvisor.
51+
func (i *imageFsInfoProvider) ContainerFsInfoLabel() (string, error) {
52+
if detectCrioWorkaround(i) {
53+
return LabelCrioContainers, nil
54+
}
55+
return "", fmt.Errorf("no containerfs label for configured runtime")
56+
}
57+
58+
// This is a temporary workaround to get stats for cri-o from cadvisor
59+
// and should be removed.
60+
// Related to https://github.com/kubernetes/kubernetes/issues/51798
61+
func detectCrioWorkaround(i *imageFsInfoProvider) bool {
62+
return strings.HasSuffix(i.runtimeEndpoint, CrioSocketSuffix)
63+
}
64+
4765
// NewImageFsInfoProvider returns a provider for the specified runtime configuration.
4866
func NewImageFsInfoProvider(runtimeEndpoint string) ImageFsInfoProvider {
4967
return &imageFsInfoProvider{runtimeEndpoint: runtimeEndpoint}

pkg/kubelet/cadvisor/helpers_unsupported.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ func (i *unsupportedImageFsInfoProvider) ImageFsInfoLabel() (string, error) {
2929
return "", errors.New("unsupported")
3030
}
3131

32+
func (i *unsupportedImageFsInfoProvider) ContainerFsInfoLabel() (string, error) {
33+
return "", errors.New("unsupported")
34+
}
35+
3236
// NewImageFsInfoProvider returns a provider for the specified runtime configuration.
3337
func NewImageFsInfoProvider(runtimeEndpoint string) ImageFsInfoProvider {
3438
return &unsupportedImageFsInfoProvider{}

pkg/kubelet/cadvisor/testing/cadvisor_fake.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ func (c *Fake) RootFsInfo() (cadvisorapiv2.FsInfo, error) {
101101
return cadvisorapiv2.FsInfo{}, nil
102102
}
103103

104+
// ContainerFsInfo is a fake implementation of Interface.ContainerFsInfo.
105+
func (c *Fake) ContainerFsInfo() (cadvisorapiv2.FsInfo, error) {
106+
return cadvisorapiv2.FsInfo{}, nil
107+
}
108+
104109
// WatchEvents is a fake implementation of Interface.WatchEvents.
105110
func (c *Fake) WatchEvents(request *events.Request) (*events.EventChannel, error) {
106111
return new(events.EventChannel), nil

pkg/kubelet/cadvisor/testing/cadvisor_mock.go

Lines changed: 30 additions & 0 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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ type Interface interface {
4141
// Returns usage information about the root filesystem.
4242
RootFsInfo() (cadvisorapiv2.FsInfo, error)
4343

44+
// Returns usage information about the writeable layer.
45+
// KEP 4191 can separate the image filesystem
46+
ContainerFsInfo() (cadvisorapiv2.FsInfo, error)
47+
4448
// Get events streamed through passedChannel that fit the request.
4549
WatchEvents(request *events.Request) (*events.EventChannel, error)
4650

@@ -52,4 +56,6 @@ type Interface interface {
5256
type ImageFsInfoProvider interface {
5357
// ImageFsInfoLabel returns the label cAdvisor should use to find the filesystem holding container images.
5458
ImageFsInfoLabel() (string, error)
59+
// In split image filesystem this will be different from ImageFsInfoLabel
60+
ContainerFsInfoLabel() (string, error)
5561
}

0 commit comments

Comments
 (0)