Skip to content

Commit

Permalink
Added 2 minute retry limit for zero IP pool allocations check
Browse files Browse the repository at this point in the history
Signed-off-by: nicklesimba <simha.nikhil@gmail.com>
  • Loading branch information
nicklesimba committed Mar 31, 2022
1 parent a61bd94 commit f24ca20
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
run: go vet ./...

- name: Install static check
run: go install honnef.co/go/tools/cmd/staticcheck@latest
run: go install honnef.co/go/tools/cmd/staticcheck@v0.2.2

- name: Test
run: sudo PATH=${PATH}:./bin ./hack/test-go.sh
Expand Down
11 changes: 4 additions & 7 deletions e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,9 @@ func (v envVars) maxReplicas(allPods []core.Pod) int32 {
// Waits for all replicas to be fully removed from replicaset, and checks that there are 0 ip pool allocations
func checkZeroIPPoolAllocationsAndReplicas(clientInfo *ClientInfo, k8sIPAM *kubeClient.KubernetesIPAM) error {
const (
emptyReplicaSet = 0
rsSteadyTimeout = 2 * rsCreateTimeout
emptyReplicaSet = 0
rsSteadyTimeout = 2 * rsCreateTimeout
zeroIPPoolTimeout = 2 * time.Minute
)
var err error

Expand All @@ -474,14 +475,10 @@ func checkZeroIPPoolAllocationsAndReplicas(clientInfo *ClientInfo, k8sIPAM *kube
}

// Check for 0 IP pool allocations
ipPool, err := k8sIPAM.GetIPPool(context.Background(), ipPoolName)
if err != nil {
if err = WaitForZeroIPPoolAllocations(k8sIPAM, ipPoolName, zeroIPPoolTimeout); err != nil {
return err
}

if len(ipPool.Allocations()) != 0 {
return fmt.Errorf("Expected 0 IP pool allocations, got %d instead", len(ipPool.Allocations()))
}
return nil
}

Expand Down
26 changes: 24 additions & 2 deletions e2e/pod_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"time"

kubeClient "github.com/k8snetworkplumbingwg/whereabouts/pkg/storage/kubernetes"
apps "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -92,13 +93,28 @@ func isReplicaSetSynchronized(replicaSet *apps.ReplicaSet, podList *v1.PodList)
return replicaSet.Status.ReadyReplicas == (*replicaSet.Spec.Replicas) && int32(len(podList.Items)) == (*replicaSet.Spec.Replicas)
}

func isIPPoolAllocationsEmpty(k8sIPAM *kubeClient.KubernetesIPAM, ipPoolName string) wait.ConditionFunc {
return func() (bool, error) {
ipPool, err := k8sIPAM.GetIPPool(context.Background(), ipPoolName)
if err != nil {
return false, err
}

if len(ipPool.Allocations()) != 0 {
return false, nil
}

return true, nil
}
}

// WaitForPodReady polls up to timeout seconds for pod to enter steady state (running or succeeded state).
// Returns an error if the pod never enters a steady state.
func WaitForPodReady(cs *kubernetes.Clientset, namespace, podName string, timeout time.Duration) error {
return wait.PollImmediate(time.Second, timeout, isPodRunning(cs, podName, namespace))
}

// WaitForPodToDisappear polls up to timeout seconds for pod to be gone from the Kubernets cluster.
// WaitForPodToDisappear polls up to timeout seconds for pod to be gone from the Kubernetes cluster.
// Returns an error if the pod is never deleted, or if GETing it returns an error other than `NotFound`.
func WaitForPodToDisappear(cs *kubernetes.Clientset, namespace, podName string, timeout time.Duration) error {
return wait.PollImmediate(time.Second, timeout, isPodGone(cs, podName, namespace))
Expand All @@ -110,12 +126,18 @@ func WaitForReplicaSetSteadyState(cs *kubernetes.Clientset, namespace, label str
return wait.PollImmediate(time.Second, timeout, isReplicaSetSteady(cs, replicaSet.Name, namespace, label))
}

// WaitForReplicaSetToDisappear polls up to timeout seconds for replicaset to be gone from the Kubernets cluster.
// WaitForReplicaSetToDisappear polls up to timeout seconds for replicaset to be gone from the Kubernetes cluster.
// Returns an error if the replicaset is never deleted, or if GETing it returns an error other than `NotFound`.
func WaitForReplicaSetToDisappear(cs *kubernetes.Clientset, namespace, rsName string, timeout time.Duration) error {
return wait.PollImmediate(time.Second, timeout, isReplicaSetGone(cs, rsName, namespace))
}

// WaitForZeroIPPoolAllocations polls up to timeout seconds for IP pool allocations to be gone from the Kubernetes cluster.
// Returns an error if any IP pool allocations remain after time limit, or if GETing IP pools causes an error.
func WaitForZeroIPPoolAllocations(k8sIPAM *kubeClient.KubernetesIPAM, ipPoolName string, timeout time.Duration) error {
return wait.PollImmediate(time.Second, timeout, isIPPoolAllocationsEmpty(k8sIPAM, ipPoolName))
}

// ListPods returns the list of currently scheduled or running pods in `namespace` with the given selector
func ListPods(cs *kubernetes.Clientset, namespace, selector string) (*v1.PodList, error) {
listOptions := metav1.ListOptions{LabelSelector: selector}
Expand Down

0 comments on commit f24ca20

Please sign in to comment.