diff --git a/pkg/kubelet/cadvisor/BUILD b/pkg/kubelet/cadvisor/BUILD index 7e4c11cfb5..29c45eb2b8 100644 --- a/pkg/kubelet/cadvisor/BUILD +++ b/pkg/kubelet/cadvisor/BUILD @@ -11,11 +11,13 @@ go_library( srcs = [ "cadvisor_unsupported.go", "doc.go", + "helpers_unsupported.go", "types.go", "util.go", ] + select({ "@io_bazel_rules_go//go/platform:linux_amd64": [ "cadvisor_linux.go", + "helpers_linux.go", ], "@io_bazel_rules_go//go/platform:windows_amd64": [ "cadvisor_windows.go", @@ -26,7 +28,6 @@ go_library( "//pkg/api/v1/helper:go_default_library", "//pkg/features:go_default_library", "//vendor/github.com/google/cadvisor/events:go_default_library", - "//vendor/github.com/google/cadvisor/fs:go_default_library", "//vendor/github.com/google/cadvisor/info/v1:go_default_library", "//vendor/github.com/google/cadvisor/info/v2:go_default_library", "//vendor/k8s.io/api/core/v1:go_default_library", @@ -38,6 +39,7 @@ go_library( "//vendor/github.com/golang/glog:go_default_library", "//vendor/github.com/google/cadvisor/cache/memory:go_default_library", "//vendor/github.com/google/cadvisor/container:go_default_library", + "//vendor/github.com/google/cadvisor/fs:go_default_library", "//vendor/github.com/google/cadvisor/http:go_default_library", "//vendor/github.com/google/cadvisor/manager:go_default_library", "//vendor/github.com/google/cadvisor/metrics:go_default_library", diff --git a/pkg/kubelet/cadvisor/cadvisor_unsupported.go b/pkg/kubelet/cadvisor/cadvisor_unsupported.go index ef21e8c86e..0b653e69e6 100644 --- a/pkg/kubelet/cadvisor/cadvisor_unsupported.go +++ b/pkg/kubelet/cadvisor/cadvisor_unsupported.go @@ -80,3 +80,7 @@ func (cu *cadvisorUnsupported) WatchEvents(request *events.Request) (*events.Eve func (cu *cadvisorUnsupported) HasDedicatedImageFs() (bool, error) { return false, unsupportedErr } + +func (c *cadvisorUnsupported) GetFsInfoByFsUUID(uuid string) (cadvisorapiv2.FsInfo, error) { + return cadvisorapiv2.FsInfo{}, nil +} diff --git a/pkg/kubelet/cadvisor/cadvisor_windows.go b/pkg/kubelet/cadvisor/cadvisor_windows.go index ec0764293b..b663c372fd 100644 --- a/pkg/kubelet/cadvisor/cadvisor_windows.go +++ b/pkg/kubelet/cadvisor/cadvisor_windows.go @@ -77,3 +77,7 @@ func (cu *cadvisorClient) WatchEvents(request *events.Request) (*events.EventCha func (cu *cadvisorClient) HasDedicatedImageFs() (bool, error) { return false, nil } + +func (c *cadvisorClient) GetFsInfoByFsUUID(uuid string) (cadvisorapiv2.FsInfo, error) { + return cadvisorapiv2.FsInfo{}, nil +} diff --git a/pkg/kubelet/cadvisor/helpers_linux.go b/pkg/kubelet/cadvisor/helpers_linux.go new file mode 100644 index 0000000000..a9e88b5bf8 --- /dev/null +++ b/pkg/kubelet/cadvisor/helpers_linux.go @@ -0,0 +1,54 @@ +// +build cgo,linux + +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package cadvisor + +import ( + "fmt" + + cadvisorfs "github.com/google/cadvisor/fs" +) + +// imageFsInfoProvider knows how to translate the configured runtime +// to its file system label for images. +type imageFsInfoProvider struct { + runtime string + runtimeEndpoint string +} + +// ImageFsInfoLabel returns the image fs label for the configured runtime. +// For remote runtimes, it handles additional runtimes natively understood by cAdvisor. +func (i *imageFsInfoProvider) ImageFsInfoLabel() (string, error) { + switch i.runtime { + case "docker": + return cadvisorfs.LabelDockerImages, nil + case "rkt": + return cadvisorfs.LabelRktImages, nil + case "remote": + // TODO: pending rebase including https://github.com/google/cadvisor/pull/1741 + if i.runtimeEndpoint == "/var/run/crio.sock" { + return "crio-images", nil + } + } + return "", fmt.Errorf("no imagefs label for configured runtime") +} + +// NewImageFsInfoProvider returns a provider for the specified runtime configuration. +func NewImageFsInfoProvider(runtime, runtimeEndpoint string) ImageFsInfoProvider { + return &imageFsInfoProvider{runtime: runtime, runtimeEndpoint: runtimeEndpoint} +} diff --git a/pkg/kubelet/cadvisor/helpers_unsupported.go b/pkg/kubelet/cadvisor/helpers_unsupported.go new file mode 100644 index 0000000000..af90f150c1 --- /dev/null +++ b/pkg/kubelet/cadvisor/helpers_unsupported.go @@ -0,0 +1,34 @@ +// +build !linux linux,!cgo + +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package cadvisor + +import "errors" + +type unsupportedImageFsInfoProvider struct{} + +// ImageFsInfoLabel returns the image fs label for the configured runtime. +// For remote runtimes, it handles additional runtimes natively understood by cAdvisor. +func (i *unsupportedImageFsInfoProvider) ImageFsInfoLabel() (string, error) { + return "", errors.New("unsupported") +} + +// NewImageFsInfoProvider returns a provider for the specified runtime configuration. +func NewImageFsInfoProvider(runtime, runtimeEndpoint string) ImageFsInfoProvider { + return &unsupportedImageFsInfoProvider{} +} diff --git a/pkg/kubelet/cadvisor/util.go b/pkg/kubelet/cadvisor/util.go index 9c8643c581..dd4d7c4b1f 100644 --- a/pkg/kubelet/cadvisor/util.go +++ b/pkg/kubelet/cadvisor/util.go @@ -17,9 +17,6 @@ limitations under the License. package cadvisor import ( - "fmt" - - cadvisorfs "github.com/google/cadvisor/fs" cadvisorapi "github.com/google/cadvisor/info/v1" cadvisorapi2 "github.com/google/cadvisor/info/v2" "k8s.io/api/core/v1" @@ -29,35 +26,6 @@ import ( "k8s.io/kubernetes/pkg/features" ) -// imageFsInfoProvider knows how to translate the configured runtime -// to its file system label for images. -type imageFsInfoProvider struct { - runtime string - runtimeEndpoint string -} - -// ImageFsInfoLabel returns the image fs label for the configured runtime. -// For remote runtimes, it handles additional runtimes natively understood by cAdvisor. -func (i *imageFsInfoProvider) ImageFsInfoLabel() (string, error) { - switch i.runtime { - case "docker": - return cadvisorfs.LabelDockerImages, nil - case "rkt": - return cadvisorfs.LabelRktImages, nil - case "remote": - // TODO: pending rebase including https://github.com/google/cadvisor/pull/1741 - if i.runtimeEndpoint == "/var/run/crio.sock" { - return "crio-images", nil - } - } - return "", fmt.Errorf("no imagefs label for configured runtime") -} - -// NewImageFsInfoProvider returns a provider for the specified runtime configuration. -func NewImageFsInfoProvider(runtime, runtimeEndpoint string) ImageFsInfoProvider { - return &imageFsInfoProvider{runtime: runtime, runtimeEndpoint: runtimeEndpoint} -} - func CapacityFromMachineInfo(info *cadvisorapi.MachineInfo) v1.ResourceList { c := v1.ResourceList{ v1.ResourceCPU: *resource.NewMilliQuantity(