Skip to content

Commit

Permalink
fix: bdd cleanup timing bug (#245)
Browse files Browse the repository at this point in the history
* Update main_test.go

Signed-off-by: Eytan Avisror <[email protected]>

* Update main_test.go

Signed-off-by: Eytan Avisror <[email protected]>

* Update main_test.go

Signed-off-by: Eytan Avisror <[email protected]>

* Update DEVELOPER.md

Signed-off-by: Eytan Avisror <[email protected]>
  • Loading branch information
eytan-avisror authored Feb 11, 2021
1 parent 38befaa commit 5fe8b74
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 12 deletions.
7 changes: 5 additions & 2 deletions .github/DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,13 @@ export KUBECONFIG=~/.kube/config

export EKS_CLUSTER=my-eks-cluster
export KEYPAIR_NAME=MyKeyPair
export VPC_ID=vpc-EXAMPLE23dk9
export AMI_ID=ami-EXAMPLEdk93
export SECURITY_GROUPS=sg-EXAMPLE2323,sg-EXAMPLE4433
export SUBNETS=subnet-EXAMPLE223d,subnet-EXAMPLEdkkf,subnet-EXAMPLEkkr9
export NODE_SUBNETS=subnet-EXAMPLE223d,subnet-EXAMPLEdkkf,subnet-EXAMPLEkkr9

# an existing role for nodes
export NODE_ROLE_ARN=arn:aws:iam::123456789012:role/basic-eks-role
export NODE_ROLE=basic-eks-role

$ make bdd

Expand Down
48 changes: 38 additions & 10 deletions test-bdd/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ const (
NodeStateReady = "ready"
NodeStateFound = "found"

DefaultWaiterInterval = time.Second * 30
DefaultWaiterRetries = 40
DefaultWaiterInterval = time.Second * 15
DefaultWaiterRetries = 80
)

var InstanceGroupSchema = schema.GroupVersionResource{
Expand Down Expand Up @@ -437,15 +437,23 @@ func (t *FunctionalTest) deleteAll() error {
return err
}

t.DynamicClient.Resource(gvr.Resource).Namespace(resource.GetNamespace()).Delete(context.Background(), resource.GetName(), metav1.DeleteOptions{})
log.Infof("BDD >> submitted deletion for %v/%v", resource.GetNamespace(), resource.GetName())
var (
namespace = resource.GetNamespace()
name = resource.GetName()
kind = resource.GetKind()
)

if strings.EqualFold(kind, "ConfigMap") {
return nil
}

t.DynamicClient.Resource(gvr.Resource).Namespace(namespace).Delete(context.Background(), name, metav1.DeleteOptions{})
log.Infof("BDD >> submitted deletion for %v %v/%v", kind, namespace, name)
return nil
}

var waitFn = func(path string, info os.FileInfo, err error) error {
var (
counter int
)
var counter int

if info.IsDir() || filepath.Ext(path) != ".yaml" {
return nil
Expand All @@ -456,15 +464,26 @@ func (t *FunctionalTest) deleteAll() error {
return err
}

var (
namespace = resource.GetNamespace()
name = resource.GetName()
kind = resource.GetKind()
)

if strings.EqualFold(kind, "ConfigMap") {
return nil
}

for {
if counter >= DefaultWaiterRetries {
return errors.New("waiter timed out waiting for deletion")
}
log.Infof("BDD >> waiting for resource deletion of %v/%v", resource.GetNamespace(), resource.GetName())
_, err := t.DynamicClient.Resource(gvr.Resource).Namespace(resource.GetNamespace()).Get(context.Background(), resource.GetName(), metav1.GetOptions{})

log.Infof("BDD >> waiting for %v deletion of %v/%v", kind, namespace, name)
_, err := t.DynamicClient.Resource(gvr.Resource).Namespace(namespace).Get(context.Background(), name, metav1.GetOptions{})
if err != nil {
if kerrors.IsNotFound(err) {
log.Infof("BDD >> resource %v/%v is deleted", resource.GetNamespace(), resource.GetName())
log.Infof("BDD >> %v %v/%v is deleted", kind, namespace, name)
break
}
}
Expand All @@ -482,5 +501,14 @@ func (t *FunctionalTest) deleteAll() error {
return err
}

// Delete configmap last
var (
cmName = "instance-manager"
cmNamespace = "instance-manager"
cmKind = "ConfigMap"
)
log.Infof("BDD >> submitted deletion for %v %v/%v", cmKind, cmNamespace, cmName)
t.KubeClient.CoreV1().ConfigMaps(cmNamespace).Delete(context.Background(), cmName, metav1.DeleteOptions{})

return nil
}

0 comments on commit 5fe8b74

Please sign in to comment.