mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-07 11:13:48 +00:00
Match on cri-o socket suffix only
This deals with the case that a user can configure cri-o to use /run/crio/crio.sock and get very confusing behavior. See https://github.com/cri-o/cri-o/issues/7010#issuecomment-1594149469
This commit is contained in:
parent
c51915c1c1
commit
2c5a11a55b
@ -25,6 +25,7 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/google/cadvisor/container/crio"
|
||||
cadvisorfs "github.com/google/cadvisor/fs"
|
||||
)
|
||||
|
||||
@ -37,7 +38,7 @@ func TestImageFsInfoLabel(t *testing.T) {
|
||||
expectedError error
|
||||
}{{
|
||||
description: "LabelCrioImages should be returned",
|
||||
runtimeEndpoint: CrioSocket,
|
||||
runtimeEndpoint: crio.CrioSocket,
|
||||
expectedLabel: cadvisorfs.LabelCrioImages,
|
||||
expectedError: nil,
|
||||
}, {
|
||||
|
@ -21,6 +21,7 @@ package cadvisor
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
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
|
||||
// and should be removed.
|
||||
// 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 "", fmt.Errorf("no imagefs label for configured runtime")
|
||||
|
@ -17,6 +17,8 @@ limitations under the License.
|
||||
package cadvisor
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
cadvisorapi "github.com/google/cadvisor/info/v1"
|
||||
cadvisorapi2 "github.com/google/cadvisor/info/v2"
|
||||
"k8s.io/api/core/v1"
|
||||
@ -25,10 +27,12 @@ import (
|
||||
)
|
||||
|
||||
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:
|
||||
// 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.
|
||||
@ -69,5 +73,5 @@ func EphemeralStorageCapacityFromFsInfo(info cadvisorapi2.FsInfo) v1.ResourceLis
|
||||
// be removed. Related issue:
|
||||
// https://github.com/kubernetes/kubernetes/issues/51798
|
||||
func UsingLegacyCadvisorStats(runtimeEndpoint string) bool {
|
||||
return runtimeEndpoint == CrioSocket || runtimeEndpoint == "unix://"+CrioSocket
|
||||
return strings.HasSuffix(runtimeEndpoint, CrioSocketSuffix)
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ package cadvisor
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/google/cadvisor/container/crio"
|
||||
@ -54,5 +55,5 @@ func TestCapacityFromMachineInfoWithHugePagesEnable(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")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user