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

Reduce kubelet logs 'Failed to create existing container' when kubelet is using crio #3457

Merged
merged 1 commit into from
Jan 26, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions container/crio/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ import (
// The namespace under which crio aliases are unique.
const CrioNamespace = "crio"

// The namespace suffix under which crio aliases are unique.
const CrioNamespaceSuffix = ".scope"

// The namespace systemd runs components under.
const SystemdNamespace = "system-systemd"

Expand Down Expand Up @@ -114,16 +117,21 @@ func (f *crioFactory) CanHandleAndAccept(name string) (bool, bool, error) {
// TODO(runcom): should we include crio-conmon cgroups?
return false, false, nil
}
if !strings.HasPrefix(path.Base(name), CrioNamespace) {
return false, false, nil
}
if strings.HasPrefix(path.Base(name), SystemdNamespace) {
return true, false, nil
}
if !strings.HasPrefix(path.Base(name), CrioNamespace) {
return false, false, nil
}
// if the container is not associated with CRI-O, we can't handle it or accept it.
if !isContainerName(name) {
return false, false, nil
}

if !strings.HasSuffix(path.Base(name), CrioNamespaceSuffix) {
// this mean it's a sandbox container
return true, false, nil
}
return true, true, nil
}

Expand Down
23 changes: 15 additions & 8 deletions container/crio/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ import (
"github.com/stretchr/testify/assert"
)

type canHandleAndAccept struct {
canHandle bool
canAccept bool
}

func TestCanHandleAndAccept(t *testing.T) {
as := assert.New(t)
f := &crioFactory{
Expand All @@ -31,16 +36,18 @@ func TestCanHandleAndAccept(t *testing.T) {
storageDir: "",
includedMetrics: nil,
}
for k, v := range map[string]bool{
"/kubepods/pod068e8fa0-9213-11e7-a01f-507b9d4141fa/crio-81e5c2990803c383229c9680ce964738d5e566d97f5bd436ac34808d2ec75d5f": true,
"/kubepods/pod068e8fa0-9213-11e7-a01f-507b9d4141fa/crio-81e5c2990803c383229c9680ce964738d5e566d97f5bd436ac34808d2ec75d5f.mount": false,
"/kubepods/pod068e8fa0-9213-11e7-a01f-507b9d4141fa/crio-conmon-81e5c2990803c383229c9680ce964738d5e566d97f5bd436ac34808d2ec75d5f": false,
"/kubepods/pod068e8fa0-9213-11e7-a01f-507b9d4141fa/no-crio-conmon-81e5c2990803c383229c9680ce964738d5e566d97f5bd436ac34808d2ec75d5f": false,
"/kubepods/pod068e8fa0-9213-11e7-a01f-507b9d4141fa/crio-990803c383229c9680ce964738d5e566d97f5bd436ac34808d2ec75": false,
for k, v := range map[string]canHandleAndAccept{
"/kubepods/pod068e8fa0-9213-11e7-a01f-507b9d4141fa/crio-81e5c2990803c383229c9680ce964738d5e566d97f5bd436ac34808d2ec75d5f": {true, false},
"/kubepods/pod068e8fa0-9213-11e7-a01f-507b9d4141fa/crio-81e5c2990803c383229c9680ce964738d5e566d97f5bd436ac34808d2ec75d5f.scope": {true, true},
"/system.slice/system-systemd\\\\x2dcoredump.slice": {true, false},
"/kubepods/pod068e8fa0-9213-11e7-a01f-507b9d4141fa/crio-81e5c2990803c383229c9680ce964738d5e566d97f5bd436ac34808d2ec75d5f.mount": {false, false},
"/kubepods/pod068e8fa0-9213-11e7-a01f-507b9d4141fa/crio-conmon-81e5c2990803c383229c9680ce964738d5e566d97f5bd436ac34808d2ec75d5f": {false, false},
"/kubepods/pod068e8fa0-9213-11e7-a01f-507b9d4141fa/no-crio-conmon-81e5c2990803c383229c9680ce964738d5e566d97f5bd436ac34808d2ec75d5f": {false, false},
"/kubepods/pod068e8fa0-9213-11e7-a01f-507b9d4141fa/crio-990803c383229c9680ce964738d5e566d97f5bd436ac34808d2ec75": {false, false},
} {
b1, b2, err := f.CanHandleAndAccept(k)
as.Nil(err)
as.Equal(b1, v)
as.Equal(b2, v)
as.Equal(b1, v.canHandle)
as.Equal(b2, v.canAccept)
}
}
Loading