Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable CRI-O stats from cAdvisor #51728

Merged
merged 1 commit into from
Sep 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion cmd/kubelet/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,8 @@ func run(s *options.KubeletServer, kubeDeps *kubelet.Dependencies) (err error) {
}

if kubeDeps.CAdvisorInterface == nil {
kubeDeps.CAdvisorInterface, err = cadvisor.New(s.Address, uint(s.CAdvisorPort), s.ContainerRuntime, s.RootDirectory)
imageFsInfoProvider := cadvisor.NewImageFsInfoProvider(s.ContainerRuntime, s.RemoteRuntimeEndpoint)
kubeDeps.CAdvisorInterface, err = cadvisor.New(s.Address, uint(s.CAdvisorPort), imageFsInfoProvider, s.RootDirectory)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelet/cadvisor/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ go_library(
}),
deps = [
"//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",
Expand All @@ -34,7 +35,6 @@ 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",
Expand Down
26 changes: 9 additions & 17 deletions pkg/kubelet/cadvisor/cadvisor_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"github.com/google/cadvisor/cache/memory"
cadvisormetrics "github.com/google/cadvisor/container"
"github.com/google/cadvisor/events"
cadvisorfs "github.com/google/cadvisor/fs"
cadvisorhttp "github.com/google/cadvisor/http"
cadvisorapi "github.com/google/cadvisor/info/v1"
cadvisorapiv2 "github.com/google/cadvisor/info/v2"
Expand All @@ -44,8 +43,8 @@ import (
)

type cadvisorClient struct {
runtime string
rootPath string
imageFsInfoProvider ImageFsInfoProvider
rootPath string
manager.Manager
}

Expand Down Expand Up @@ -106,7 +105,7 @@ func containerLabels(c *cadvisorapi.ContainerInfo) map[string]string {
}

// New creates a cAdvisor and exports its API on the specified port if port > 0.
func New(address string, port uint, runtime string, rootPath string) (Interface, error) {
func New(address string, port uint, imageFsInfoProvider ImageFsInfoProvider, rootPath string) (Interface, error) {
sysFs := sysfs.NewRealSysFs()

// Create and start the cAdvisor container manager.
Expand All @@ -126,9 +125,9 @@ func New(address string, port uint, runtime string, rootPath string) (Interface,
}

cadvisorClient := &cadvisorClient{
runtime: runtime,
rootPath: rootPath,
Manager: m,
imageFsInfoProvider: imageFsInfoProvider,
rootPath: rootPath,
Manager: m,
}

err = cadvisorClient.exportHTTP(address, port)
Expand Down Expand Up @@ -208,17 +207,10 @@ func (cc *cadvisorClient) MachineInfo() (*cadvisorapi.MachineInfo, error) {
}

func (cc *cadvisorClient) ImagesFsInfo() (cadvisorapiv2.FsInfo, error) {
var label string

switch cc.runtime {
case "docker":
label = cadvisorfs.LabelDockerImages
case "rkt":
label = cadvisorfs.LabelRktImages
default:
return cadvisorapiv2.FsInfo{}, fmt.Errorf("ImagesFsInfo: unknown runtime: %v", cc.runtime)
label, err := cc.imageFsInfoProvider.ImageFsInfoLabel()
if err != nil {
return cadvisorapiv2.FsInfo{}, err
}

return cc.getFsInfo(label)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelet/cadvisor/cadvisor_unsupported.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type cadvisorUnsupported struct {

var _ Interface = new(cadvisorUnsupported)

func New(address string, port uint, runtime string, rootPath string) (Interface, error) {
func New(address string, port uint, imageFsInfoProvider ImageFsInfoProvider, rootPath string) (Interface, error) {
return &cadvisorUnsupported{}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelet/cadvisor/cadvisor_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type cadvisorClient struct {
var _ Interface = new(cadvisorClient)

// New creates a cAdvisor and exports its API on the specified port if port > 0.
func New(address string, port uint, runtime string, rootPath string) (Interface, error) {
func New(address string, port uint, imageFsInfoProvider ImageFsInfoProvider, rootPath string) (Interface, error) {
return &cadvisorClient{}, nil
}

Expand Down
8 changes: 7 additions & 1 deletion pkg/kubelet/cadvisor/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type Interface interface {

VersionInfo() (*cadvisorapi.VersionInfo, error)

// Returns usage information about the filesystem holding Docker images.
// Returns usage information about the filesystem holding container images.
ImagesFsInfo() (cadvisorapiv2.FsInfo, error)

// Returns usage information about the root filesystem.
Expand All @@ -45,3 +45,9 @@ type Interface interface {
// HasDedicatedImageFs returns true iff a dedicated image filesystem exists for storing images.
HasDedicatedImageFs() (bool, error)
}

// ImageFsInfoProvider informs cAdvisor how to find imagefs for container images.
type ImageFsInfoProvider interface {
// ImageFsInfoLabel returns the label cAdvisor should use to find the filesystem holding container images.
ImageFsInfoLabel() (string, error)
}
32 changes: 32 additions & 0 deletions pkg/kubelet/cadvisor/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,44 @@ 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"
"k8s.io/apimachinery/pkg/api/resource"
)

// 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(
Expand Down
2 changes: 1 addition & 1 deletion test/e2e_node/environment/conformance.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func containerRuntime() error {
}

// Setup cadvisor to check the container environment
c, err := cadvisor.New("", 0 /*don't start the http server*/, "docker", "/var/lib/kubelet")
c, err := cadvisor.New("", 0 /*don't start the http server*/, cadvisor.NewImageFsInfoProvider("docker", ""), "/var/lib/kubelet")
if err != nil {
return printError("Container Runtime Check: %s Could not start cadvisor %v", failed, err)
}
Expand Down