Skip to content

Commit

Permalink
Merge pull request #408 from hhyasdf/release/v0.8.8
Browse files Browse the repository at this point in the history
[CHERRY PICK] release for v0.8.8
  • Loading branch information
sjtufl authored Oct 10, 2023
2 parents 70a6dcf + d625a13 commit 6edf03f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
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

0 comments on commit 6edf03f

Please sign in to comment.