cadvisor_fake.go 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 implementation.
  21. type Fake struct {
  22. NodeName string
  23. }
  24. const (
  25. FakeNumCores = 1
  26. FakeMemoryCapacity = 4026531840
  27. FakeKernelVersion = "3.16.0-0.bpo.4-amd64"
  28. FakeContainerOsVersion = "Debian GNU/Linux 7 (wheezy)"
  29. FakeDockerVersion = "1.13.1"
  30. )
  31. var _ cadvisor.Interface = new(Fake)
  32. func (c *Fake) Start() error {
  33. return nil
  34. }
  35. func (c *Fake) ContainerInfo(name string, req *cadvisorapi.ContainerInfoRequest) (*cadvisorapi.ContainerInfo, error) {
  36. return new(cadvisorapi.ContainerInfo), nil
  37. }
  38. func (c *Fake) ContainerInfoV2(name string, options cadvisorapiv2.RequestOptions) (map[string]cadvisorapiv2.ContainerInfo, error) {
  39. return map[string]cadvisorapiv2.ContainerInfo{}, nil
  40. }
  41. func (c *Fake) SubcontainerInfo(name string, req *cadvisorapi.ContainerInfoRequest) (map[string]*cadvisorapi.ContainerInfo, error) {
  42. return map[string]*cadvisorapi.ContainerInfo{}, nil
  43. }
  44. func (c *Fake) DockerContainer(name string, req *cadvisorapi.ContainerInfoRequest) (cadvisorapi.ContainerInfo, error) {
  45. return cadvisorapi.ContainerInfo{}, nil
  46. }
  47. func (c *Fake) MachineInfo() (*cadvisorapi.MachineInfo, error) {
  48. // Simulate a machine with 1 core and 3.75GB of memory.
  49. // We set it to non-zero values to make non-zero-capacity machines in Kubemark.
  50. return &cadvisorapi.MachineInfo{
  51. NumCores: FakeNumCores,
  52. InstanceID: cadvisorapi.InstanceID(c.NodeName),
  53. MemoryCapacity: FakeMemoryCapacity,
  54. }, nil
  55. }
  56. func (c *Fake) VersionInfo() (*cadvisorapi.VersionInfo, error) {
  57. return &cadvisorapi.VersionInfo{
  58. KernelVersion: FakeKernelVersion,
  59. ContainerOsVersion: FakeContainerOsVersion,
  60. DockerVersion: FakeDockerVersion,
  61. }, nil
  62. }
  63. func (c *Fake) ImagesFsInfo() (cadvisorapiv2.FsInfo, error) {
  64. return cadvisorapiv2.FsInfo{}, nil
  65. }
  66. func (c *Fake) RootFsInfo() (cadvisorapiv2.FsInfo, error) {
  67. return cadvisorapiv2.FsInfo{}, nil
  68. }
  69. func (c *Fake) WatchEvents(request *events.Request) (*events.EventChannel, error) {
  70. return new(events.EventChannel), nil
  71. }
  72. func (c *Fake) GetDirFsInfo(path string) (cadvisorapiv2.FsInfo, error) {
  73. return cadvisorapiv2.FsInfo{}, nil
  74. }