Skip to content
Merged
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
16 changes: 16 additions & 0 deletions pkg/controlloop/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"k8s.io/client-go/kubernetes"

v1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/util/wait"
Expand Down Expand Up @@ -222,6 +223,21 @@ func (pc *PodController) garbageCollectPodIPs(pod *v1.Pod) error {
for _, pool := range pools {
for allocationIndex, allocation := range pool.Spec.Allocations {
if allocation.PodRef == podID(podNamespace, podName) {
logging.Verbosef("Found an existing allocation: %+v", allocation)

// The allocation could belong to a new pod with the same name and namespace. Stateful set scenarios.
// The previous pod should be gone by the time a pod deletion event is received.
if newPod, err := pc.k8sClient.CoreV1().Pods(podNamespace).Get(context.TODO(), podName, metav1.GetOptions{}); err == nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we check if the pod is owned by a statefulset so we dont break the behavior for non stateful deployments?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can check the ownerref of the pod to see if it is part of a statefulset, if it is we release the ip, if not we proceed to use the existing logic

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't apply to non stateful deployments. Pod name is different.

Copy link
Collaborator

@bpickard22 bpickard22 Jul 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maiqueb we can assume the user is following naming conventions i guess

if newPod.DeletionTimestamp == nil {
logging.Verbosef("A pod with the same name and namespace was found and is not marked for deletion. Skipping deallocation")
continue
}

logging.Verbosef("A pod with the same name and namespace was found and is marked for deletion. Cleaning up the stale allocation. DeletionTimestamp: %+v", newPod.DeletionTimestamp)
} else if !apierrors.IsNotFound(err) {
return fmt.Errorf("failed to get pod to verify allocation: %+v", err)
}

logging.Verbosef("stale allocation to cleanup: %+v", allocation)

client := *wbclient.NewKubernetesClient(pc.wbClient, pc.k8sClient)
Expand Down
Loading