helpers_linux.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // +build linux
  2. /*
  3. Copyright 2017 The Kubernetes Authors.
  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. http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. */
  14. package cadvisor
  15. import (
  16. "fmt"
  17. cadvisorfs "github.com/google/cadvisor/fs"
  18. "k8s.io/kubernetes/pkg/kubelet/types"
  19. )
  20. // imageFsInfoProvider knows how to translate the configured runtime
  21. // to its file system label for images.
  22. type imageFsInfoProvider struct {
  23. runtime string
  24. runtimeEndpoint string
  25. }
  26. // ImageFsInfoLabel returns the image fs label for the configured runtime.
  27. // For remote runtimes, it handles additional runtimes natively understood by cAdvisor.
  28. func (i *imageFsInfoProvider) ImageFsInfoLabel() (string, error) {
  29. switch i.runtime {
  30. case types.DockerContainerRuntime:
  31. return cadvisorfs.LabelDockerImages, nil
  32. case types.RemoteContainerRuntime:
  33. // This is a temporary workaround to get stats for cri-o from cadvisor
  34. // and should be removed.
  35. // Related to https://github.com/kubernetes/kubernetes/issues/51798
  36. if i.runtimeEndpoint == CrioSocket || i.runtimeEndpoint == "unix://"+CrioSocket {
  37. return cadvisorfs.LabelCrioImages, nil
  38. }
  39. }
  40. return "", fmt.Errorf("no imagefs label for configured runtime")
  41. }
  42. // NewImageFsInfoProvider returns a provider for the specified runtime configuration.
  43. func NewImageFsInfoProvider(runtime, runtimeEndpoint string) ImageFsInfoProvider {
  44. return &imageFsInfoProvider{runtime: runtime, runtimeEndpoint: runtimeEndpoint}
  45. }