Skip to content
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
25 changes: 20 additions & 5 deletions test/extended/operators/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ import (
var _ = g.Describe("[Feature:Platform] Managed cluster should", func() {
defer g.GinkgoRecover()

g.It("have no crashlooping pods in core namespaces over two minutes", func() {
g.It("have no crashlooping pods in core namespaces over four minutes", func() {
c, err := e2e.LoadClientset()
o.Expect(err).NotTo(o.HaveOccurred())

restartingContainers := make(map[containerName]int)
podsWithProblems := make(map[string]*corev1.Pod)
var lastPending map[string]*corev1.Pod
wait.PollImmediate(5*time.Second, 2*time.Minute, func() (bool, error) {
Expand Down Expand Up @@ -63,7 +64,7 @@ var _ = g.Describe("[Feature:Platform] Managed cluster should", func() {
case hasCreateContainerError(pod):
case hasImagePullError(pod):
case isCrashLooping(pod):
case hasExcessiveRestarts(pod):
case hasExcessiveRestarts(pod, 2, restartingContainers):
case hasFailingContainer(pod):
default:
continue
Expand Down Expand Up @@ -172,10 +173,24 @@ func isCrashLooping(pod *corev1.Pod) bool {
return false
}

func hasExcessiveRestarts(pod *corev1.Pod) bool {
type containerName struct {
namespace string
name string
container string
}

func hasExcessiveRestarts(pod *corev1.Pod, excessiveCount int, counts map[containerName]int) bool {
for _, status := range append(append([]corev1.ContainerStatus{}, pod.Status.InitContainerStatuses...), pod.Status.ContainerStatuses...) {
if status.RestartCount > 5 {
pod.Status.Message = fmt.Sprintf("container %s has restarted more than 5 times", status.Name)
name := containerName{namespace: pod.Namespace, name: pod.Name, container: status.Name}
count, ok := counts[name]
if !ok {
counts[name] = int(status.RestartCount)
continue
}

current := int(status.RestartCount) - count
if current >= excessiveCount {
pod.Status.Message = fmt.Sprintf("container %s has restarted %d times (>= %d) within the allowed interval", status.Name, current, excessiveCount)
return true
}
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.