Skip to content

Commit

Permalink
Merge pull request #166 from maiqueb/skip-reconciler-pending-pods
Browse files Browse the repository at this point in the history
ip-reconciler: do not reconcile pods in Pending phase
  • Loading branch information
dougbtv authored Nov 17, 2021
2 parents ba2557c + 55be906 commit 2b15ccc
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
38 changes: 38 additions & 0 deletions cmd/reconciler/ip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,37 @@ var _ = Describe("Whereabouts IP reconciler", func() {
Expect(clusterWideIPAllocations.Items).To(HaveLen(expectedClusterWideIPs))
})
})

Context("a pod in pending state, without an IP in its network-status", func() {
const poolName = "pool1"

var pod *v1.Pod
var pool *v1alpha1.IPPool

BeforeEach(func() {
var err error
pod, err = k8sClientSet.CoreV1().Pods(namespace).Create(
context.TODO(),
generatePendingPod(namespace, podName),
metav1.CreateOptions{})
Expect(err).NotTo(HaveOccurred())

pool = generateIPPoolSpec(ipRange, namespace, poolName, pod.Name)
Expect(k8sClient.Create(context.Background(), pool)).NotTo(HaveOccurred())

reconcileLooper, err = reconciler.NewReconcileLooperWithKubeconfig(kubeConfigPath, context.TODO())
Expect(err).NotTo(HaveOccurred())
})

AfterEach(func() {
Expect(k8sClient.Delete(context.Background(), pool)).NotTo(HaveOccurred())
Expect(k8sClientSet.CoreV1().Pods(namespace).Delete(context.TODO(), pod.GetName(), metav1.DeleteOptions{}))
})

It("cannot be reconciled", func() {
Expect(reconcileLooper.ReconcileIPPools()).To(BeEmpty())
})
})
})

func generateIPPoolSpec(ipRange string, namespace string, poolName string, podNames ...string) *v1alpha1.IPPool {
Expand Down Expand Up @@ -300,9 +331,16 @@ func generatePod(namespace string, podName string, ipNetworks ...ipInNetwork) *v
},
},
},
Status: v1.PodStatus{Phase: v1.PodRunning},
}
}

func generatePendingPod(namespace string, podName string, ipNetworks ...ipInNetwork) *v1.Pod {
pod := generatePod(namespace, podName, ipNetworks...)
pod.Status.Phase = v1.PodPending
return pod
}

func generatePodAnnotations(ipNetworks ...ipInNetwork) map[string]string {
var networks []string
for _, ipNetworkInfo := range ipNetworks {
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/iploop.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (rl ReconcileLooper) isPodAlive(podRef string, ip string) bool {
ip,
livePodIPs)
_, isFound := livePodIPs[ip]
return isFound
return isFound || livePod.phase == v1.PodPending
}
}
return false
Expand Down
6 changes: 4 additions & 2 deletions pkg/reconciler/wrappedPod.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package reconciler
import (
"encoding/json"

k8snetworkplumbingwgv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"
"github.com/k8snetworkplumbingwg/whereabouts/pkg/logging"
"github.com/k8snetworkplumbingwg/whereabouts/pkg/storage"
k8snetworkplumbingwgv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"

v1 "k8s.io/api/core/v1"
)
Expand All @@ -18,14 +18,16 @@ const (
)

type podWrapper struct {
ips map[string]void
ips map[string]void
phase v1.PodPhase
}

type void struct{}

func wrapPod(pod v1.Pod) *podWrapper {
return &podWrapper{
ips: getFlatIPSet(pod),
phase: pod.Status.Phase,
}
}

Expand Down

0 comments on commit 2b15ccc

Please sign in to comment.