Skip to content

Commit

Permalink
UPSTREAM: <carry>: ignore not found errors in status messages
Browse files Browse the repository at this point in the history
  • Loading branch information
rphillips committed Feb 8, 2021
1 parent c3cfb81 commit a94d343
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pkg/kubelet/kuberuntime/kuberuntime_manager.go
Expand Up @@ -20,6 +20,7 @@ import (
"errors"
"fmt"
"os"
"regexp"
goruntime "runtime"
"time"

Expand Down Expand Up @@ -72,6 +73,10 @@ const (
var (
// ErrVersionNotSupported is returned when the api version of runtime interface is not supported
ErrVersionNotSupported = errors.New("runtime api version is not supported")
// ignore error regexex for sandbox creation
ignoreSandboxCreateErrorRegex = []*regexp.Regexp{
regexp.MustCompile(`pods\s\"\S+.\"\snot found`),
}
)

// podStateProvider can determine if a pod is deleted ir terminated
Expand Down Expand Up @@ -137,6 +142,9 @@ type kubeGenericRuntimeManager struct {

// Cache last per-container error message to reduce log spam
logReduction *logreduction.LogReduction

// PodState
podStateProvider podStateProvider
}

// KubeGenericRuntime is a interface contains interfaces for container runtime and command.
Expand Down Expand Up @@ -238,6 +246,7 @@ func NewKubeGenericRuntimeManager(
}
}
kubeRuntimeManager.keyring = credentialprovider.NewDockerKeyring()
kubeRuntimeManager.podStateProvider = podStateProvider

kubeRuntimeManager.imagePuller = images.NewImageManager(
kubecontainer.FilterEventRecorder(recorder),
Expand Down Expand Up @@ -757,6 +766,12 @@ func (m *kubeGenericRuntimeManager) SyncPod(pod *v1.Pod, podStatus *kubecontaine
if referr != nil {
klog.Errorf("Couldn't make a ref to pod %q: '%v'", format.Pod(pod), referr)
}
isDeleted := m.podStateProvider.IsPodDeleted(pod.UID)
for _, re := range ignoreSandboxCreateErrorRegex {
if isDeleted && re.MatchString(err.Error()) {
return
}
}
m.recorder.Eventf(ref, v1.EventTypeWarning, events.FailedCreatePodSandBox, "Failed to create pod sandbox: %v", err)
return
}
Expand Down
24 changes: 24 additions & 0 deletions pkg/kubelet/kuberuntime/kuberuntime_manager_test.go
Expand Up @@ -19,6 +19,7 @@ package kuberuntime
import (
"path/filepath"
"reflect"
"regexp"
"sort"
"testing"
"time"
Expand Down Expand Up @@ -1399,3 +1400,26 @@ func makeBasePodAndStatusWithInitAndEphemeralContainers() (*v1.Pod, *kubecontain
})
return pod, status
}

func TestSandboxCreationErrorRegex(t *testing.T) {
reTests := []struct {
testString string
match bool
regex *regexp.Regexp
}{
{
testString: `Multus: [e2e-deployment-7897/webserver-9569696c8-gs6c8]: error setting the networks status, pod was already deleted: SetNetworkStatus: failed to query the pod webserver-9569696c8-gs6c8 in out of cluster comm: pods "webserver-9569696c8-gs6c8" not found`,
match: true,
regex: ignoreSandboxCreateErrorRegex[0],
},
{
testString: `this will not match`,
match: false,
regex: ignoreSandboxCreateErrorRegex[0],
},
}

for _, test := range reTests {
assert.Equal(t, test.match, test.regex.MatchString(test.testString))
}
}

0 comments on commit a94d343

Please sign in to comment.