Skip to content

Commit

Permalink
Filter pods from non-existent node in degraded mode
Browse files Browse the repository at this point in the history
Filter pods from non-existent node in degraded mode
  • Loading branch information
sawsa307 committed Feb 21, 2023
1 parent cc07ce4 commit 66a45e6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/neg/syncers/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,11 +329,20 @@ func (s *transactionSyncer) syncInternalImpl() error {
// it returns false if the pod:
// 1. doesn't exist
// 2. is in terminal state
// 3. corresponds to a non-existent node
func (s *transactionSyncer) isValidPod(pod *apiv1.Pod) bool {
// Terminal Pod means a pod is in PodFailed or PodSucceeded phase
if pod.Status.Phase == corev1.PodFailed || pod.Status.Phase == corev1.PodSucceeded {
return false
}
obj, exists, err := s.nodeLister.GetByKey(pod.Spec.NodeName)
if err != nil || !exists {
return false
}
_, isNode := obj.(*apiv1.Node)
if !isNode {
return false
}
return true
}

Expand Down
32 changes: 32 additions & 0 deletions pkg/neg/syncers/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2352,6 +2352,13 @@ func TestIsValidEPBatch(t *testing.T) {
func TestIsValidPod(t *testing.T) {
t.Parallel()
_, ts := newTestTransactionSyncer(negtypes.NewAdapter(gce.NewFakeGCECloud(gce.DefaultTestClusterValues())), negtypes.VmIpPortEndpointType, false, true)
testNode1 := "node1"
testNodeNonExistent := "node-non-existent"
ts.nodeLister.Add(&corev1.Node{
ObjectMeta: metav1.ObjectMeta{
Name: testNode1,
},
})

testCases := []struct {
desc string
Expand All @@ -2368,6 +2375,9 @@ func TestIsValidPod(t *testing.T) {
Status: corev1.PodStatus{
Phase: corev1.PodRunning,
},
Spec: corev1.PodSpec{
NodeName: testNode1,
},
},
expect: true,
},
Expand All @@ -2381,6 +2391,9 @@ func TestIsValidPod(t *testing.T) {
Status: corev1.PodStatus{
Phase: corev1.PodFailed,
},
Spec: corev1.PodSpec{
NodeName: testNode1,
},
},
expect: false,
},
Expand All @@ -2394,6 +2407,25 @@ func TestIsValidPod(t *testing.T) {
Status: corev1.PodStatus{
Phase: corev1.PodSucceeded,
},
Spec: corev1.PodSpec{
NodeName: testNode1,
},
},
expect: false,
},
{
desc: "pod from non-existent pod",
pod: &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Namespace: testNamespace,
Name: "pod4",
},
Status: corev1.PodStatus{
Phase: corev1.PodSucceeded,
},
Spec: corev1.PodSpec{
NodeName: testNodeNonExistent,
},
},
expect: false,
},
Expand Down

0 comments on commit 66a45e6

Please sign in to comment.