helpers_linux.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright 2019 Yunion
  2. //
  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. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package cadvisor
  15. import (
  16. cadvisorfs "github.com/google/cadvisor/fs"
  17. "yunion.io/x/pkg/errors"
  18. )
  19. const (
  20. DockerContainerRuntime = "docker"
  21. RemoteContainerRuntime = "remote"
  22. )
  23. const (
  24. // CrioSocket is the path to the CRI-O socket.
  25. // Please keep this in sync with the one in:
  26. // github.com/google/cadvisor/container/crio/client.go
  27. CrioSocket = "/var/run/crio/crio.sock"
  28. )
  29. // imageFsInfoProvider knows how to translate the configured runtime
  30. // to its file system label for images.
  31. type imageFsInfoProvider struct {
  32. runtime string
  33. runtimeEndpoint string
  34. }
  35. func (i *imageFsInfoProvider) ImageFsInfoLabel() (string, error) {
  36. switch i.runtime {
  37. case DockerContainerRuntime:
  38. return cadvisorfs.LabelDockerImages, nil
  39. case RemoteContainerRuntime:
  40. // This is a temporary workaround to get stats for cri-o from cadvisor
  41. // and should be removed.
  42. // Related to https://github.com/kubernetes/kubernetes/issues/51798
  43. if i.runtimeEndpoint == CrioSocket || i.runtimeEndpoint == "unix://"+CrioSocket {
  44. return cadvisorfs.LabelCrioImages, nil
  45. }
  46. }
  47. return "", errors.Errorf("no imagefs label for configured runtime: %s", i.runtime)
  48. }
  49. func NewImageFsInfoProvider(runtime, endpoint string) ImageFsInfoProvider {
  50. return &imageFsInfoProvider{
  51. runtime: runtime,
  52. runtimeEndpoint: endpoint,
  53. }
  54. }