Merge pull request #118704 from dgl/crio-socket-fix

Match on cri-o socket suffix only
This commit is contained in:
Kubernetes Prow Robot 2023-10-17 20:07:52 +02:00 committed by GitHub
commit 3d77b95bcf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 6 deletions

View File

@ -25,6 +25,7 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/google/cadvisor/container/crio"
cadvisorfs "github.com/google/cadvisor/fs" cadvisorfs "github.com/google/cadvisor/fs"
) )
@ -37,7 +38,7 @@ func TestImageFsInfoLabel(t *testing.T) {
expectedError error expectedError error
}{{ }{{
description: "LabelCrioImages should be returned", description: "LabelCrioImages should be returned",
runtimeEndpoint: CrioSocket, runtimeEndpoint: crio.CrioSocket,
expectedLabel: cadvisorfs.LabelCrioImages, expectedLabel: cadvisorfs.LabelCrioImages,
expectedError: nil, expectedError: nil,
}, { }, {

View File

@ -21,6 +21,7 @@ package cadvisor
import ( import (
"fmt" "fmt"
"strings"
cadvisorfs "github.com/google/cadvisor/fs" cadvisorfs "github.com/google/cadvisor/fs"
) )
@ -37,7 +38,7 @@ func (i *imageFsInfoProvider) ImageFsInfoLabel() (string, error) {
// This is a temporary workaround to get stats for cri-o from cadvisor // This is a temporary workaround to get stats for cri-o from cadvisor
// and should be removed. // and should be removed.
// Related to https://github.com/kubernetes/kubernetes/issues/51798 // Related to https://github.com/kubernetes/kubernetes/issues/51798
if i.runtimeEndpoint == CrioSocket || i.runtimeEndpoint == "unix://"+CrioSocket { if strings.HasSuffix(i.runtimeEndpoint, CrioSocketSuffix) {
return cadvisorfs.LabelCrioImages, nil return cadvisorfs.LabelCrioImages, nil
} }
return "", fmt.Errorf("no imagefs label for configured runtime") return "", fmt.Errorf("no imagefs label for configured runtime")

View File

@ -17,6 +17,8 @@ limitations under the License.
package cadvisor package cadvisor
import ( import (
"strings"
cadvisorapi "github.com/google/cadvisor/info/v1" cadvisorapi "github.com/google/cadvisor/info/v1"
cadvisorapi2 "github.com/google/cadvisor/info/v2" cadvisorapi2 "github.com/google/cadvisor/info/v2"
"k8s.io/api/core/v1" "k8s.io/api/core/v1"
@ -25,10 +27,12 @@ import (
) )
const ( const (
// CrioSocket is the path to the CRI-O socket. // CrioSocketSuffix is the path to the CRI-O socket.
// Please keep this in sync with the one in: // Please keep this in sync with the one in:
// github.com/google/cadvisor/tree/master/container/crio/client.go // github.com/google/cadvisor/tree/master/container/crio/client.go
CrioSocket = "/var/run/crio/crio.sock" // Note that however we only match on the suffix, as /var/run is often a
// symlink to /run, so the user can specify either path.
CrioSocketSuffix = "run/crio/crio.sock"
) )
// CapacityFromMachineInfo returns the capacity of the resources from the machine info. // CapacityFromMachineInfo returns the capacity of the resources from the machine info.
@ -69,5 +73,5 @@ func EphemeralStorageCapacityFromFsInfo(info cadvisorapi2.FsInfo) v1.ResourceLis
// be removed. Related issue: // be removed. Related issue:
// https://github.com/kubernetes/kubernetes/issues/51798 // https://github.com/kubernetes/kubernetes/issues/51798
func UsingLegacyCadvisorStats(runtimeEndpoint string) bool { func UsingLegacyCadvisorStats(runtimeEndpoint string) bool {
return runtimeEndpoint == CrioSocket || runtimeEndpoint == "unix://"+CrioSocket return strings.HasSuffix(runtimeEndpoint, CrioSocketSuffix)
} }

View File

@ -21,6 +21,7 @@ package cadvisor
import ( import (
"reflect" "reflect"
"strings"
"testing" "testing"
"github.com/google/cadvisor/container/crio" "github.com/google/cadvisor/container/crio"
@ -54,5 +55,5 @@ func TestCapacityFromMachineInfoWithHugePagesEnable(t *testing.T) {
} }
func TestCrioSocket(t *testing.T) { func TestCrioSocket(t *testing.T) {
assert.EqualValues(t, CrioSocket, crio.CrioSocket, "CrioSocket in this package must equal the one in github.com/google/cadvisor/container/crio/client.go") assert.True(t, strings.HasSuffix(crio.CrioSocket, CrioSocketSuffix), "CrioSocketSuffix in this package must be a suffix of the one in github.com/google/cadvisor/container/crio/client.go")
} }