diff --git a/e2e/client/ippool.go b/e2e/client/ippool.go index 2d3fecf93..f7a56eee3 100644 --- a/e2e/client/ippool.go +++ b/e2e/client/ippool.go @@ -32,14 +32,14 @@ func isIPPoolAllocationsEmpty(ctx context.Context, k8sIPAM *kubeClient.Kubernete } } -func isIPPoolAllocationsEmptyForNodeSlices(k8sIPAM *kubeClient.KubernetesIPAM, ipPoolCIDR string, clientInfo *ClientInfo) wait.ConditionFunc { - return func() (bool, error) { - nodes, err := clientInfo.Client.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{}) +func isIPPoolAllocationsEmptyForNodeSlices(ctx context.Context, k8sIPAM *kubeClient.KubernetesIPAM, ipPoolCIDR string, clientInfo *ClientInfo) wait.ConditionWithContextFunc { + return func(context.Context) (bool, error) { + nodes, err := clientInfo.Client.CoreV1().Nodes().List(ctx, metav1.ListOptions{}) if err != nil { return false, err } for _, node := range nodes.Items { - ipPool, err := k8sIPAM.GetIPPool(context.Background(), kubeClient.PoolIdentifier{NodeName: node.Name, IpRange: ipPoolCIDR, NetworkName: k8sIPAM.Config.NetworkName}) + ipPool, err := k8sIPAM.GetIPPool(ctx, kubeClient.PoolIdentifier{NodeName: node.Name, IpRange: ipPoolCIDR, NetworkName: k8sIPAM.Config.NetworkName}) if err != nil { if err.Error() == "k8s pool initialized" { continue @@ -64,6 +64,6 @@ func WaitForZeroIPPoolAllocations(ctx context.Context, k8sIPAM *kubeClient.Kuber // WaitForZeroIPPoolAllocationsAcrossNodeSlices 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 WaitForZeroIPPoolAllocationsAcrossNodeSlices(k8sIPAM *kubeClient.KubernetesIPAM, ipPoolCIDR string, timeout time.Duration, clientInfo *ClientInfo) error { - return wait.PollImmediate(time.Second, timeout, isIPPoolAllocationsEmptyForNodeSlices(k8sIPAM, ipPoolCIDR, clientInfo)) +func WaitForZeroIPPoolAllocationsAcrossNodeSlices(ctx context.Context, k8sIPAM *kubeClient.KubernetesIPAM, ipPoolCIDR string, timeout time.Duration, clientInfo *ClientInfo) error { + return wait.PollUntilContextTimeout(ctx, time.Second, timeout, true, isIPPoolAllocationsEmptyForNodeSlices(ctx, k8sIPAM, ipPoolCIDR, clientInfo)) } diff --git a/e2e/client/nodeslicepool.go b/e2e/client/nodeslicepool.go index 0b77bce56..0a051d7e5 100644 --- a/e2e/client/nodeslicepool.go +++ b/e2e/client/nodeslicepool.go @@ -3,6 +3,7 @@ package client import ( "context" "fmt" + "k8s.io/apimachinery/pkg/api/errors" "time" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -23,13 +24,16 @@ func GetNodeSubnet(cs *ClientInfo, nodeName, sliceName, namespace string) (strin } func WaitForNodeSliceReady(ctx context.Context, cs *ClientInfo, namespace, nodeSliceName string, timeout time.Duration) error { - return wait.PollUntilContextTimeout(ctx, time.Second, timeout, true, isNodeSliceReady(ctx, cs, nodeSliceName, namespace)) + return wait.PollUntilContextTimeout(ctx, time.Second, timeout, true, isNodeSliceReady(ctx, cs, namespace, nodeSliceName)) } func isNodeSliceReady(ctx context.Context, cs *ClientInfo, namespace, nodeSliceName string) wait.ConditionWithContextFunc { return func(context.Context) (bool, error) { _, err := cs.WbClient.WhereaboutsV1alpha1().NodeSlicePools(namespace).Get(ctx, nodeSliceName, metav1.GetOptions{}) if err != nil { + if errors.IsNotFound(err) { + return false, nil + } return false, err } diff --git a/e2e/e2e_node_slice_test.go b/e2e/e2e_node_slice_test.go index 46e480032..70f2849b5 100644 --- a/e2e/e2e_node_slice_test.go +++ b/e2e/e2e_node_slice_test.go @@ -2,6 +2,7 @@ package whereabouts_e2e import ( "context" + "github.com/k8snetworkplumbingwg/whereabouts/pkg/api/whereabouts.cni.cncf.io/v1alpha1" "testing" "time" @@ -21,7 +22,6 @@ import ( "github.com/k8snetworkplumbingwg/whereabouts/e2e/retrievers" testenv "github.com/k8snetworkplumbingwg/whereabouts/e2e/testenvironment" "github.com/k8snetworkplumbingwg/whereabouts/e2e/util" - "github.com/k8snetworkplumbingwg/whereabouts/pkg/api/whereabouts.cni.cncf.io/v1alpha1" "github.com/k8snetworkplumbingwg/whereabouts/pkg/storage" wbstorage "github.com/k8snetworkplumbingwg/whereabouts/pkg/storage/kubernetes" "github.com/k8snetworkplumbingwg/whereabouts/pkg/types" diff --git a/e2e/poolconsistency/node_slice_checker.go b/e2e/poolconsistency/node_slice_checker.go index 09db1e6cb..651e28779 100644 --- a/e2e/poolconsistency/node_slice_checker.go +++ b/e2e/poolconsistency/node_slice_checker.go @@ -23,10 +23,10 @@ func (pc *NodeSliceChecker) MissingIPs() []string { var mismatchedIPs []string for _, pod := range pc.podList { podIPs, err := retrievers.SecondaryIfaceIPValue(&pod) - podIP := podIPs[len(podIPs)-1] if err != nil { return []string{} } + podIP := podIPs[len(podIPs)-1] var found bool for _, pool := range pc.ipPools { diff --git a/e2e/util/util.go b/e2e/util/util.go index 34b17703d..1840a6085 100644 --- a/e2e/util/util.go +++ b/e2e/util/util.go @@ -122,7 +122,7 @@ func CheckZeroIPPoolAllocationsAndReplicas(ctx context.Context, clientInfo *wbte return err } } else { - if err = wbtestclient.WaitForZeroIPPoolAllocationsAcrossNodeSlices(k8sIPAM, ipPoolCIDR, zeroIPPoolTimeout, clientInfo); err != nil { + if err = wbtestclient.WaitForZeroIPPoolAllocationsAcrossNodeSlices(ctx, k8sIPAM, ipPoolCIDR, zeroIPPoolTimeout, clientInfo); err != nil { return err } } @@ -175,7 +175,6 @@ func MacvlanNetworkWithWhereaboutsIPAMNetwork(networkName string, namespaceName } func MacvlanNetworkWithNodeSlice(networkName, namespaceName, ipRange, poolName, sliceSize string) *nettypes.NetworkAttachmentDefinition { - //TODO: fails without leader timeouts set macvlanConfig := fmt.Sprintf(`{ "cniVersion": "0.3.0", "disableCheck": true, diff --git a/hack/e2e-setup-kind-cluster.sh b/hack/e2e-setup-kind-cluster.sh index 4fa08d334..db5ac739d 100755 --- a/hack/e2e-setup-kind-cluster.sh +++ b/hack/e2e-setup-kind-cluster.sh @@ -98,10 +98,13 @@ trap "rm /tmp/whereabouts-img.tar || true" EXIT kind load image-archive --name "$KIND_CLUSTER_NAME" /tmp/whereabouts-img.tar echo "## install whereabouts" -for file in "daemonset-install.yaml" "whereabouts.cni.cncf.io_ippools.yaml" "whereabouts.cni.cncf.io_overlappingrangeipreservations.yaml" "node-slice-controller.yaml"; do +for file in "daemonset-install.yaml" "whereabouts.cni.cncf.io_ippools.yaml" "whereabouts.cni.cncf.io_overlappingrangeipreservations.yaml" "whereabouts.cni.cncf.io_nodeslicepools.yaml"; do # insert 'imagePullPolicy: Never' under the container 'image' so it is certain that the image used # by the daemonset is the one loaded into KinD and not one pulled from a repo sed '/ image:/a\ imagePullPolicy: Never' "$ROOT/doc/crds/$file" | retry kubectl apply -f - done +# deployment has an extra tab for the sed so doing out of the loop +sed '/ image:/a\ imagePullPolicy: Never' "$ROOT/doc/crds/node-slice-controller.yaml" | retry kubectl apply -f - retry kubectl wait -n kube-system --for=condition=ready -l app=whereabouts pod --timeout=$TIMEOUT_K8 +retry kubectl wait -n kube-system --for=condition=ready -l app=whereabouts-controller pod --timeout=$TIMEOUT_K8 echo "## done" diff --git a/pkg/client/clientset/versioned/typed/whereabouts.cni.cncf.io/v1alpha1/fake/fake_nodeslicepool.go b/pkg/client/clientset/versioned/typed/whereabouts.cni.cncf.io/v1alpha1/fake/fake_nodeslicepool.go index 4f250df4d..a12e4a431 100644 --- a/pkg/client/clientset/versioned/typed/whereabouts.cni.cncf.io/v1alpha1/fake/fake_nodeslicepool.go +++ b/pkg/client/clientset/versioned/typed/whereabouts.cni.cncf.io/v1alpha1/fake/fake_nodeslicepool.go @@ -23,7 +23,6 @@ import ( v1alpha1 "github.com/k8snetworkplumbingwg/whereabouts/pkg/api/whereabouts.cni.cncf.io/v1alpha1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" labels "k8s.io/apimachinery/pkg/labels" - schema "k8s.io/apimachinery/pkg/runtime/schema" types "k8s.io/apimachinery/pkg/types" watch "k8s.io/apimachinery/pkg/watch" testing "k8s.io/client-go/testing" @@ -35,9 +34,9 @@ type FakeNodeSlicePools struct { ns string } -var nodeslicepoolsResource = schema.GroupVersionResource{Group: "whereabouts.cni.cncf.io", Version: "v1alpha1", Resource: "nodeslicepools"} +var nodeslicepoolsResource = v1alpha1.SchemeGroupVersion.WithResource("nodeslicepools") -var nodeslicepoolsKind = schema.GroupVersionKind{Group: "whereabouts.cni.cncf.io", Version: "v1alpha1", Kind: "NodeSlicePool"} +var nodeslicepoolsKind = v1alpha1.SchemeGroupVersion.WithKind("NodeSlicePool") // Get takes name of the nodeSlicePool, and returns the corresponding nodeSlicePool object, and an error if there is any. func (c *FakeNodeSlicePools) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.NodeSlicePool, err error) { diff --git a/pkg/node-controller/controller_test.go b/pkg/node-controller/controller_test.go index 2f8d70d03..7e2e7cfe6 100644 --- a/pkg/node-controller/controller_test.go +++ b/pkg/node-controller/controller_test.go @@ -200,7 +200,6 @@ func (f *fixture) newController(ctx context.Context) (*Controller, informers.Sha f.nadClient, kubeInformerFactory.Core().V1().Nodes(), whereaboutsInformerFactory.Whereabouts().V1alpha1().NodeSlicePools(), - whereaboutsInformerFactory.Whereabouts().V1alpha1().IPPools(), nadInformerFactory.K8sCniCncfIo().V1().NetworkAttachmentDefinitions(), true)