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

[CHERRY PICK] release for v0.8.8 #408

Merged
merged 1 commit into from
Oct 10, 2023
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
8 changes: 4 additions & 4 deletions pkg/controllers/networking/pod_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (r *PodReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result

if strategy.OwnByStatefulWorkload(ownedObj) {
// Before pod terminated, should not reserve ip instance because of pre-stop
if !utils.PodIsTerminated(pod) {
if !utils.PodIsNotRunning(pod) {
return ctrl.Result{}, nil
}

Expand All @@ -167,12 +167,12 @@ func (r *PodReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result
}

if apierrors.IsNotFound(err) || !vm.DeletionTimestamp.IsZero() {
// if vm is deleted, should not reserve pod ips any more
// if vm is deleted, should not reserve pod ips anymore
return ctrl.Result{}, wrapError("unable to remove finalizer", r.removeFinalizer(ctx, pod))
}

// Before pod terminated, should not reserve ip instance because of pre-stop
if !utils.PodIsTerminated(pod) {
// Before pod is not running, should not reserve ip instance because of pre-stop
if !utils.PodIsNotRunning(pod) {
return ctrl.Result{}, nil
}

Expand Down
12 changes: 7 additions & 5 deletions pkg/controllers/networking/pod_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ var _ = Describe("Pod controller integration test suite", func() {
Expect(k8sClient.Delete(context.Background(), pod, client.GracePeriodSeconds(0))).NotTo(HaveOccurred())
})

It("Check ip reserved only after pod terminated", func() {
It("Check ip reserved only after pod is not running", func() {
By("create a stateful pod requiring IPv4 address")
var ipInstanceName string
pod := simplePodRender(podName, node1Name)
Expand Down Expand Up @@ -740,13 +740,15 @@ var _ = Describe("Pod controller integration test suite", func() {
WithPolling(time.Second).
Should(Succeed())

By("update to make sure pod not terminated")
By("update to make sure pod is running")
patch := client.MergeFrom(pod.DeepCopy())
pod.Status.ContainerStatuses = []corev1.ContainerStatus{
{
Name: "test",
State: corev1.ContainerState{
Terminated: nil,
Running: &corev1.ContainerStateRunning{
StartedAt: metav1.Time{Time: time.Now()},
},
},
},
}
Expand All @@ -770,13 +772,13 @@ var _ = Describe("Pod controller integration test suite", func() {
WithPolling(5 * time.Second).
Should(Succeed())

By("update to make sure pod terminated")
By("update to make sure pod is not running")
patch = client.MergeFrom(pod.DeepCopy())
pod.Status.ContainerStatuses = []corev1.ContainerStatus{
{
Name: "test",
State: corev1.ContainerState{
Terminated: &corev1.ContainerStateTerminated{},
Running: nil,
},
},
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/controllers/utils/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ func PodIsScheduled(pod *v1.Pod) bool {
return len(pod.Spec.NodeName) > 0
}

func PodIsTerminated(pod *v1.Pod) bool {
func PodIsNotRunning(pod *v1.Pod) bool {
// check if all the pod containers are not running, if any container is running, pod is still running
for i := range pod.Status.ContainerStatuses {
if pod.Status.ContainerStatuses[i].State.Terminated == nil {
if pod.Status.ContainerStatuses[i].State.Running != nil {
return false
}
}
Expand Down