...

Source file src/k8s.io/kubernetes/pkg/kubelet/cadvisor/helpers_linux.go

Documentation: k8s.io/kubernetes/pkg/kubelet/cadvisor

     1  //go:build linux
     2  // +build linux
     3  
     4  /*
     5  Copyright 2017 The Kubernetes Authors.
     6  
     7  Licensed under the Apache License, Version 2.0 (the "License");
     8  you may not use this file except in compliance with the License.
     9  You may obtain a copy of the License at
    10  
    11      http://www.apache.org/licenses/LICENSE-2.0
    12  
    13  Unless required by applicable law or agreed to in writing, software
    14  distributed under the License is distributed on an "AS IS" BASIS,
    15  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    16  See the License for the specific language governing permissions and
    17  limitations under the License.
    18  */
    19  
    20  package cadvisor
    21  
    22  import (
    23  	"fmt"
    24  	"strings"
    25  
    26  	cadvisorfs "github.com/google/cadvisor/fs"
    27  )
    28  
    29  // imageFsInfoProvider knows how to translate the configured runtime
    30  // to its file system label for images.
    31  type imageFsInfoProvider struct {
    32  	runtimeEndpoint string
    33  }
    34  
    35  // ImageFsInfoLabel returns the image fs label for the configured runtime.
    36  // For remote runtimes, it handles additional runtimes natively understood by cAdvisor.
    37  func (i *imageFsInfoProvider) ImageFsInfoLabel() (string, error) {
    38  	if detectCrioWorkaround(i) {
    39  		return cadvisorfs.LabelCrioImages, nil
    40  	}
    41  	return "", fmt.Errorf("no imagefs label for configured runtime")
    42  }
    43  
    44  // ContainerFsInfoLabel returns the container fs label for the configured runtime.
    45  // For remote runtimes, it handles addition runtimes natively understood by cAdvisor.
    46  func (i *imageFsInfoProvider) ContainerFsInfoLabel() (string, error) {
    47  	if detectCrioWorkaround(i) {
    48  		return cadvisorfs.LabelCrioContainers, nil
    49  	}
    50  	return "", fmt.Errorf("no containerfs label for configured runtime")
    51  }
    52  
    53  // This is a temporary workaround to get stats for cri-o from cadvisor
    54  // and should be removed.
    55  // Related to https://github.com/kubernetes/kubernetes/issues/51798
    56  func detectCrioWorkaround(i *imageFsInfoProvider) bool {
    57  	return strings.HasSuffix(i.runtimeEndpoint, CrioSocketSuffix)
    58  }
    59  
    60  // NewImageFsInfoProvider returns a provider for the specified runtime configuration.
    61  func NewImageFsInfoProvider(runtimeEndpoint string) ImageFsInfoProvider {
    62  	return &imageFsInfoProvider{runtimeEndpoint: runtimeEndpoint}
    63  }
    64  

View as plain text