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

api: ignore some pod statuses with allowed errors #110

Merged
merged 1 commit into from
Feb 24, 2022
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: 14 additions & 0 deletions internal/pkg/rpaas/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ const (

var _ RpaasManager = &k8sRpaasManager{}

var podAllowedReasonsToFail = map[string]bool{
"shutdown": true,
"evicted": true,
"nodeaffinity": true,
}

type k8sRpaasManager struct {
cli client.Client
cacheManager CacheManager
Expand Down Expand Up @@ -2034,6 +2040,9 @@ func (m *k8sRpaasManager) getPodStatuses(ctx context.Context, nginx *nginxv1alph

var podStatuses []clientTypes.Pod
for _, pod := range pods {
if podIsAllowedToFail(pod) {
continue
}
ps, err := m.newPodStatus(ctx, &pod)
if err != nil {
return nil, err
Expand Down Expand Up @@ -2343,3 +2352,8 @@ func hasIntersection(a []string, b []string) bool {

return false
}

func podIsAllowedToFail(pod corev1.Pod) bool {
reason := strings.ToLower(pod.Status.Reason)
return pod.Status.Phase == corev1.PodFailed && podAllowedReasonsToFail[reason]
}
40 changes: 38 additions & 2 deletions internal/pkg/rpaas/k8s_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4405,7 +4405,43 @@ func Test_k8sRpaasManager_GetInstanceInfo(t *testing.T) {
},
},
}

pod3 := &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "instance4-6f86f957b7-klmno",
Namespace: instance4.Namespace,
Labels: map[string]string{
"nginx.tsuru.io/app": "nginx",
"nginx.tsuru.io/resource-name": "instance4",
},
CreationTimestamp: metav1.NewTime(t0.Add(time.Hour)),
UID: types.UID("pod3-123"),
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: "nginx",
Ports: []corev1.ContainerPort{
{
Name: "http",
HostPort: int32(30000),
},
{
Name: "https",
HostPort: int32(30001),
},
{
Name: "nginx-metrics",
HostPort: int32(30002),
},
},
},
},
},
Status: corev1.PodStatus{
Phase: corev1.PodFailed,
Reason: "shutdown",
},
}
event1 := &corev1.Event{
ObjectMeta: metav1.ObjectMeta{
Name: pod2.Name + ".1",
Expand Down Expand Up @@ -4506,7 +4542,7 @@ func Test_k8sRpaasManager_GetInstanceInfo(t *testing.T) {
instance1, instance2, instance3, instance4,
nginx3, nginx4,
service3, service4,
pod1, pod2,
pod1, pod2, pod3,
pod2Metrics,
event1, event2, event3, event4, event5,
s1, s2,
Expand Down