Skip to content

Commit cc47bc8

Browse files
committed
Preserve Pod Phase when stripping down object for IsPodNetworkReady to work correctly.
1 parent b81925d commit cc47bc8

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

pkg/k8s/pod_utils.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ func stripDownPodObject(pod *corev1.Pod) *corev1.Pod {
9090
HostIPs: pod.Status.HostIPs,
9191
PodIP: pod.Status.PodIP,
9292
PodIPs: pod.Status.PodIPs,
93+
Phase: pod.Status.Phase,
9394
}
9495
return pod
9596
}

pkg/k8s/pod_utils_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,3 +239,55 @@ func TestIsPodNetworkReady(t *testing.T) {
239239
})
240240
}
241241
}
242+
243+
func TestStripDownPodObject(t *testing.T) {
244+
succeededPod := &corev1.Pod{
245+
ObjectMeta: metav1.ObjectMeta{
246+
Name: "succeeded-pod",
247+
Namespace: "test-ns",
248+
Labels: map[string]string{"app": "test"},
249+
},
250+
Spec: corev1.PodSpec{
251+
Containers: []corev1.Container{
252+
{Name: "container1", Ports: []corev1.ContainerPort{{ContainerPort: 80}}},
253+
},
254+
},
255+
Status: corev1.PodStatus{
256+
Phase: corev1.PodSucceeded,
257+
PodIP: "10.0.0.1",
258+
HostIP: "10.0.1.1",
259+
PodIPs: []corev1.PodIP{{IP: "10.0.0.1"}},
260+
HostIPs: []corev1.HostIP{{IP: "10.0.1.1"}},
261+
},
262+
}
263+
264+
runningPod := &corev1.Pod{
265+
ObjectMeta: metav1.ObjectMeta{
266+
Name: "running-pod",
267+
Namespace: "test-ns",
268+
Labels: map[string]string{"app": "test"},
269+
},
270+
Spec: corev1.PodSpec{
271+
Containers: []corev1.Container{
272+
{Name: "container1", Ports: []corev1.ContainerPort{{ContainerPort: 80}}},
273+
},
274+
},
275+
Status: corev1.PodStatus{
276+
Phase: corev1.PodRunning,
277+
PodIP: "10.0.0.2",
278+
HostIP: "10.0.1.1",
279+
PodIPs: []corev1.PodIP{{IP: "10.0.0.2"}},
280+
HostIPs: []corev1.HostIP{{IP: "10.0.1.1"}},
281+
},
282+
}
283+
284+
// Test succeeded pod
285+
strippedSucceeded := stripDownPodObject(succeededPod)
286+
assert.Equal(t, corev1.PodSucceeded, strippedSucceeded.Status.Phase, "Phase field must be preserved for succeeded pod")
287+
assert.False(t, IsPodNetworkReady(strippedSucceeded), "IsPodNetworkReady should return false for succeeded pod")
288+
289+
// Test running pod
290+
strippedRunning := stripDownPodObject(runningPod)
291+
assert.Equal(t, corev1.PodRunning, strippedRunning.Status.Phase, "Phase field must be preserved for running pod")
292+
assert.True(t, IsPodNetworkReady(strippedRunning), "IsPodNetworkReady should return true for running pod")
293+
}

0 commit comments

Comments
 (0)