Skip to content

Commit

Permalink
e2e: topologyupdater: wait for deletion
Browse files Browse the repository at this point in the history
It might take time for the CRD to get deleted
and it might cause some falkiness in the tests.

Now before we create the CRD, we make sure to delete
the old object, wait for it deletion to complete
and only then create a new CRD object.

Signed-off-by: Talor Itzhak <[email protected]>
  • Loading branch information
Tal-or committed Nov 21, 2022
1 parent 1b6fad6 commit 546d0c3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
9 changes: 1 addition & 8 deletions test/e2e/topology_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
topologyclientset "github.com/k8stopologyawareschedwg/noderesourcetopology-api/pkg/generated/clientset/versioned"

corev1 "k8s.io/api/core/v1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
extclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
Expand All @@ -45,7 +44,6 @@ var _ = SIGDescribe("Node Feature Discovery topology updater", func() {
var (
extClient *extclient.Clientset
topologyClient *topologyclientset.Clientset
crd *apiextensionsv1.CustomResourceDefinition
topologyUpdaterNode *corev1.Node
workerNodes []corev1.Node
kubeletConfig *kubeletconfig.KubeletConfiguration
Expand Down Expand Up @@ -73,7 +71,7 @@ var _ = SIGDescribe("Node Feature Discovery topology updater", func() {
By(fmt.Sprintf("Using config (%#v)", kcfg))

By("Creating the node resource topologies CRD")
crd, err = testutils.CreateNodeResourceTopologies(extClient)
_, err = testutils.CreateNodeResourceTopologies(extClient)
Expect(err).NotTo(HaveOccurred())

err = testutils.ConfigureRBAC(f.ClientSet, f.Namespace.Name)
Expand Down Expand Up @@ -254,11 +252,6 @@ var _ = SIGDescribe("Node Feature Discovery topology updater", func() {
if err != nil {
framework.Logf("failed to delete RBAC resources: %v", err)
}

err = extClient.ApiextensionsV1().CustomResourceDefinitions().Delete(context.TODO(), crd.Name, metav1.DeleteOptions{})
if err != nil {
framework.Logf("failed to delete node resources topologies CRD: %v", err)
}
})
})

Expand Down
22 changes: 17 additions & 5 deletions test/e2e/utils/noderesourcetopology.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
extclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/kubernetes/scheme"
kubeletconfig "k8s.io/kubernetes/pkg/kubelet/apis/config"
"k8s.io/kubernetes/test/e2e/framework"
Expand Down Expand Up @@ -81,15 +82,26 @@ func CreateNodeResourceTopologies(extClient extclient.Interface) (*apiextensions
return nil, err
}

updatedCrd, err := extClient.ApiextensionsV1().CustomResourceDefinitions().Get(context.TODO(), crd.Name, metav1.GetOptions{})
// Delete existing CRD (if any) with this we also get rid of stale objects
err = extClient.ApiextensionsV1().CustomResourceDefinitions().Delete(context.TODO(), crd.Name, metav1.DeleteOptions{})
if err != nil && !errors.IsNotFound(err) {
return nil, err
return nil, fmt.Errorf("failed to delete NodeResourceTopology CRD: %w", err)
}

if err == nil {
return updatedCrd, nil
}
// It takes time for the delete operation, wait until the CRD completely gone
if err = wait.PollImmediate(5*time.Second, 1*time.Minute, func() (bool, error) {
_, err = extClient.ApiextensionsV1().CustomResourceDefinitions().Get(context.TODO(), crd.Name, metav1.GetOptions{})
if err == nil {
return false, nil
}

if errors.IsNotFound(err) {
return true, nil
}
return false, err
}); err != nil {
return nil, fmt.Errorf("failed to get NodeResourceTopology CRD: %w", err)
}
return extClient.ApiextensionsV1().CustomResourceDefinitions().Create(context.TODO(), crd, metav1.CreateOptions{})
}

Expand Down

0 comments on commit 546d0c3

Please sign in to comment.