k8s.io/kubernetes@v1.31.0-alpha.0.0.20240520171757-56147500dadc/pkg/kubelet/cadvisor/testing/cadvisor_fake.go (about) 1 /* 2 Copyright 2015 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package testing 18 19 import ( 20 cadvisorapi "github.com/google/cadvisor/info/v1" 21 cadvisorapiv2 "github.com/google/cadvisor/info/v2" 22 "k8s.io/kubernetes/pkg/kubelet/cadvisor" 23 ) 24 25 // Fake cadvisor.Interface implementation. 26 type Fake struct { 27 NodeName string 28 } 29 30 const ( 31 // FakeKernelVersion is a fake kernel version for testing. 32 FakeKernelVersion = "3.16.0-0.bpo.4-amd64" 33 // FakeContainerOSVersion is a fake OS version for testing. 34 FakeContainerOSVersion = "Debian GNU/Linux 7 (wheezy)" 35 36 fakeNumCores = 1 37 fakeMemoryCapacity = 4026531840 38 fakeDockerVersion = "1.13.1" 39 ) 40 41 var _ cadvisor.Interface = new(Fake) 42 43 // Start is a fake implementation of Interface.Start. 44 func (c *Fake) Start() error { 45 return nil 46 } 47 48 // ContainerInfoV2 is a fake implementation of Interface.ContainerInfoV2. 49 func (c *Fake) ContainerInfoV2(name string, options cadvisorapiv2.RequestOptions) (map[string]cadvisorapiv2.ContainerInfo, error) { 50 return map[string]cadvisorapiv2.ContainerInfo{}, nil 51 } 52 53 // GetRequestedContainersInfo is a fake implementation if Interface.GetRequestedContainersInfo 54 func (c *Fake) GetRequestedContainersInfo(containerName string, options cadvisorapiv2.RequestOptions) (map[string]*cadvisorapi.ContainerInfo, error) { 55 return map[string]*cadvisorapi.ContainerInfo{}, nil 56 } 57 58 // MachineInfo is a fake implementation of Interface.MachineInfo. 59 func (c *Fake) MachineInfo() (*cadvisorapi.MachineInfo, error) { 60 // Simulate a machine with 1 core and 3.75GB of memory. 61 // We set it to non-zero values to make non-zero-capacity machines in Kubemark. 62 return &cadvisorapi.MachineInfo{ 63 NumCores: fakeNumCores, 64 InstanceID: cadvisorapi.InstanceID(c.NodeName), 65 MemoryCapacity: fakeMemoryCapacity, 66 }, nil 67 } 68 69 // VersionInfo is a fake implementation of Interface.VersionInfo. 70 func (c *Fake) VersionInfo() (*cadvisorapi.VersionInfo, error) { 71 return &cadvisorapi.VersionInfo{ 72 KernelVersion: FakeKernelVersion, 73 ContainerOsVersion: FakeContainerOSVersion, 74 DockerVersion: fakeDockerVersion, 75 }, nil 76 } 77 78 // ImagesFsInfo is a fake implementation of Interface.ImagesFsInfo. 79 func (c *Fake) ImagesFsInfo() (cadvisorapiv2.FsInfo, error) { 80 return cadvisorapiv2.FsInfo{}, nil 81 } 82 83 // RootFsInfo is a fake implementation of Interface.RootFsInfo. 84 func (c *Fake) RootFsInfo() (cadvisorapiv2.FsInfo, error) { 85 return cadvisorapiv2.FsInfo{}, nil 86 } 87 88 // ContainerFsInfo is a fake implementation of Interface.ContainerFsInfo. 89 func (c *Fake) ContainerFsInfo() (cadvisorapiv2.FsInfo, error) { 90 return cadvisorapiv2.FsInfo{}, nil 91 } 92 93 // GetDirFsInfo is a fake implementation of Interface.GetDirFsInfo. 94 func (c *Fake) GetDirFsInfo(path string) (cadvisorapiv2.FsInfo, error) { 95 return cadvisorapiv2.FsInfo{}, nil 96 }