cadvisor_fake.go 3.7 KB

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