Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Add ginkgo e2e testing framework #242

Closed
wants to merge 9 commits into from
Closed

Conversation

munnerz
Copy link
Contributor

@munnerz munnerz commented Feb 6, 2018

What this PR does / why we need it:

Adds a ginkgo based e2e testing framework, and updates the Elasticsearch e2e tests to be written with it.

fixes #32, fixes #156

Special notes for your reviewer:

Stacked on #241, #240 and #239

Release note:

NONE

@munnerz
Copy link
Contributor Author

munnerz commented Feb 6, 2018

/test e2e

@munnerz munnerz force-pushed the ginkgo-e2e branch 3 times, most recently from 5e4219f to b365878 Compare February 6, 2018 16:55
@munnerz
Copy link
Contributor Author

munnerz commented Feb 6, 2018

/hold

@jetstack-ci-bot
Copy link
Contributor

@munnerz PR needs rebase

Skip not found errors in DeleteAllStatefulSets
@munnerz
Copy link
Contributor Author

munnerz commented Mar 1, 2018

/hold cancel

Copy link
Contributor

@kragniz kragniz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a great move, I'll be glad to write less bash!

Some things:

  • This needs a rebase (the cassandra e2e tests no longer use helm)
  • It'd be great if the code added from k/k (eg in test/e2e/framework) could have a note about where it was sourced from to help with maintenance in the future (I think it'd be best to try and keep them in sync rather than diverging)

@jetstack-ci-bot
Copy link
Contributor

@munnerz PR needs rebase

@jetstack-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To fully approve this pull request, please assign additional approvers.
We suggest the following additional approver: munnerz

Assign the PR to them by writing /assign @munnerz in a comment when ready.

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@munnerz
Copy link
Contributor Author

munnerz commented Mar 21, 2018

/retest

Copy link
Member

@wallrj wallrj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @munnerz

I've taken a first look through and left some comments.

  • I can see that this is probably going to be more easily maintainable than the bash script.
  • But I'm going to miss the clarity and debugability of the bash script.
  • Also going to miss the verbose xtrace output which shows exactly what kubectl command are being run so that I can dive in and run those commands myself if they fail.
  • I got the following error when I tried running the tests on my dind cluster:
make e2e-test REGISTRY=gcr.io/jetstack-richard IMAGE_TAGS=build > e2e.stdout 2>e2e.stderr
...
==> e2e.stdout <==                   
# Execute e2e tests                  
./e2e-tests \                        
        -kubeconfig=$HOME/.kube/config \                                   
        -context=$HOSTNAME \         
        -elasticsearch-pilot-image-repo="gcr.io/jetstack-richard/navigator-pilot-elasticsearch" \                                                     
        -elasticsearch-pilot-image-tag="build" \                           
        -clean-start=true \          
        -report-dir=./_artifacts     

==> e2e.stderr <==                   
I0322 09:28:18.242017   26104 e2e.go:178] Starting e2e run "5ae8c698-2db3-11e8-829e-42010a8c0002" on Ginkgo node 1                                    

==> e2e.stdout <==                   
Running Suite: Navigator e2e suite   
==================================   
Random Seed: 1521710898 - Will randomize all specs                         
Will run 4 of 4 specs                

Mar 22 09:28:18.242: INFO: >>> kubeConfig: /home/richard/.kube/config      
Mar 22 09:28:18.243: INFO: >>> kubeContext: pet-instance-1                 

==> e2e.stderr <==                   
F0322 09:28:18.243381   26104 e2e.go:35] Error loading client: error creating client: invalid configuration: [context was not found for specified context: pet-instance-1, cluster has no server defined]

==> e2e.stdout <==                   
Makefile:37: recipe for target '.run_e2e' failed                           

==> e2e.stderr <==                   
make: *** [.run_e2e] Error 255  
richard@pet-instance-1:~/go/src/github.com/jetstack/navigator$ cat /home/richard/.kube/config
apiVersion: v1
clusters:
- cluster:
    insecure-skip-tls-verify: true
    server: http://localhost:8080
  name: dind
contexts:
- context:
    cluster: dind
    namespace: default
    user: ""
  name: dind
current-context: dind
kind: Config
preferences: {}
users: []

-context=$$HOSTNAME \
-elasticsearch-pilot-image-repo="${REGISTRY}/navigator-pilot-elasticsearch" \
-elasticsearch-pilot-image-tag="${BUILD_TAG}" \
-clean-start=true \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The command line flags for -clean-start say that it cleans out all namespaces except default and system.
So do the ginkgo tests re-install navigator?

  -clean-start
    	If true, purge all namespaces except default and system before running tests. This serves to Cleanup test namespaces from failed/interrupted e2e runs in a long-lived cluster.

@@ -43,7 +43,7 @@ function retry() {

function kube_create_namespace_with_quota() {
local namespace=$1
kubectl create namespace "${namespace}"
kubectl create namespace "${namespace}" || true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this added to handle the case where the namespace already exists?
And in that case it sounds like a problem with the logic in the scripts.
And if the namespace already exists then the presumably the quota may also exist and needs a similar || true

@@ -0,0 +1,181 @@
package e2e
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this copied from Kubernetes project?
Is there a copyright header missing?
And if we've modified it, is it clear what we've modified?
Perhaps add a few comments at the top of this file.

metav1.NamespaceSystem,
metav1.NamespaceDefault,
metav1.NamespacePublic,
framework.TestContext.NavigatorNamespace,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, so this answers my previous point.
Maybe add a comment and update the command line help?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the shell script we do delete namespace XXX --now. Which speeds up the deletion somewhat. Does this framework do the same?


// Similar to SynchornizedBeforeSuite, we want to run some operations only once (such as collecting cluster logs).
// Here, the order of functions is reversed; first, the function which runs everywhere,
// and then the function that only runs on the first Ginkgo node.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo SynchornizedBeforeSuite

// whole test being terminated. This allows arbitrary pieces of the overall
// test to hook into SynchronizedAfterSuite().
func AddCleanupAction(fn func()) CleanupActionHandle {
p := CleanupActionHandle(new(int))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does new(int) do here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creates a pointer to an int with the default value (0). It's basically ptr.Int(0)

es := &esList.Items[i]
Logf("Deleting elasticsearchcluster %v", es.Name)
// Use OrphanDependents=false so it's deleted synchronously.
// We already made sure the Pods are gone inside Scale().
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this comment. The AfterEach blocks above seem to run DeleteAllElasticsearchClusters before deleting statefulsets.
Do you mean that when deleting a statefulset it will first be scaled to zero to remove all the pods?

Failf("Node pool %q not found in ElasticsearchCluster %q", pool, es.Name)
}
By("Scaling node pool " + es.Name + "/" + pool + " in namespace " + es.Namespace)
es, err = e.navClient.NavigatorV1alpha1().ElasticsearchClusters(es.Namespace).Update(es)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this susceptible to conflict errors? If Navigator has since updated the status of the ES cluster resource?
Does this need RetryOnConflict handling?

"involvedObject.namespace": ns,
"source": "navigator-controller",
}.AsSelector().String()
options := metav1.ListOptions{FieldSelector: selector}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's cool. Can you use field selectors with the Lister API too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep I'm pretty sure the listers take the same metav1.ListOptions struct 😄

@@ -0,0 +1,60 @@
package framework
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll assume that all the rest of the framework files are copied from Kubernetes. But note that not all of them have Kubernetes copyright headings.
Maybe add a oneline comment to the files that have been copied showing where from, what version (git hash) and if modified a summary of the changes.

@munnerz
Copy link
Contributor Author

munnerz commented Mar 22, 2018

I got the following error when I tried running the tests on my dind cluster:

You've got --context=$HOSTNAME on your e2e test command, hence the error about missing context 😄

@wallrj
Copy link
Member

wallrj commented Mar 27, 2018

You've got --context=$HOSTNAME on your e2e test command, hence the error about missing context

Sure, but I think I should be able to run make e2e-tests on my local cluster and it should just use the default context.

@munnerz munnerz added this to the v0.1 milestone Mar 27, 2018
@munnerz munnerz self-assigned this Mar 27, 2018
@jetstack-bot
Copy link
Collaborator

@munnerz: PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ElasticSearch E2E tests fail on non-minikube cluster Switch e2e tests to use ginkgo
5 participants