Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create E2E test suite #26

Merged
merged 6 commits into from
Oct 21, 2019
Merged

Conversation

adamhosier
Copy link
Contributor

@adamhosier adamhosier commented Oct 16, 2019

this pr:

  • Adds an external service definition to allow us to reach the client port from outside the cluster. required for the e2e tests to dial the cluster to verify its health.
  • An e2e test which will
    1. Start a Kind cluster
    2. Deploy CRDs to this cluster
    3. Build the operator image & load it to the kind cluster
    4. Deploy the operator
    5. Deploy the custom resources in example/cluster.yaml
    6. Wait for an etcd cluster to come up

this pr does not:

  • Add the step to CI (coming soon)
  • Add any in-depth testing, just a broad health check

run this yourself with

go test ./internal/test/e2e --kind --repo-root=$(pwd) -v 

@adamhosier
Copy link
Contributor Author

see #7

examples/cluster.yaml Outdated Show resolved Hide resolved
examples/cluster.yaml Outdated Show resolved Hide resolved
examples/cluster.yaml Outdated Show resolved Hide resolved
examples/operator.yaml Outdated Show resolved Hide resolved
examples/operator.yaml Outdated Show resolved Hide resolved
examples/operator.yaml Outdated Show resolved Hide resolved
@JamesLaverack JamesLaverack added the enhancement New feature or request label Oct 17, 2019
@adamhosier
Copy link
Contributor Author

@JamesLaverack @munnerz i've pushed a commit here which consistently uses config/ for all resources. there's a couple fixes bundled which popped up during tests. PTAL

Copy link
Contributor

@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.

@adamhosier This looks really neat.

  • I ran the e2e tests locally and got a failure. See below.
  • I added one or two nits in the comments below.
  • It might be nice to add a new Make target, either here or in a follow up branch.
  • Finally, it'd be nice to add some brief documentation for this, perhaps in the CONTRIBUTING.md doc for now.
 richard   feature/e2e-test  ~  projects  improbable-eng  etcd-cluster-operator  go test ./internal/test/e2e --kind --repo-root=$(pwd) -v 
go: downloading sigs.k8s.io/kind v0.5.1
go: downloading go.etcd.io/etcd v3.3.17+incompatible
go: extracting sigs.k8s.io/kind v0.5.1
go: downloading github.com/sirupsen/logrus v1.4.1
go: downloading sigs.k8s.io/kustomize/v3 v3.1.1-0.20190821175718-4b67a6de1296
go: extracting github.com/sirupsen/logrus v1.4.1
go: extracting sigs.k8s.io/kustomize/v3 v3.1.1-0.20190821175718-4b67a6de1296
go: downloading github.com/go-openapi/spec v0.19.2
go: downloading github.com/emicklei/go-restful v2.9.6+incompatible
go: extracting github.com/emicklei/go-restful v2.9.6+incompatible
go: extracting go.etcd.io/etcd v3.3.17+incompatible
go: extracting github.com/go-openapi/spec v0.19.2
go: downloading github.com/go-openapi/jsonreference v0.19.2
go: downloading github.com/go-openapi/jsonpointer v0.19.2
go: downloading github.com/go-openapi/swag v0.19.2
go: extracting github.com/go-openapi/jsonreference v0.19.2
go: downloading github.com/PuerkitoBio/purell v1.1.1
go: extracting github.com/go-openapi/jsonpointer v0.19.2
go: extracting github.com/go-openapi/swag v0.19.2
go: downloading github.com/mailru/easyjson v0.0.0-20190620125010-da37f6c1e481
go: extracting github.com/PuerkitoBio/purell v1.1.1
go: downloading github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578
go: extracting github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578
go: extracting github.com/mailru/easyjson v0.0.0-20190620125010-da37f6c1e481
go: downloading github.com/coreos/etcd v3.3.17+incompatible
go: extracting github.com/coreos/etcd v3.3.17+incompatible
=== RUN   TestE2E_Kind
 • Ensuring node image (kindest/node:v1.15.3) 🖼  ...
time="2019-10-18T11:16:08+01:00" level=info msg="Image: kindest/node:v1.15.3 present locally"
 ✓ Ensuring node image (kindest/node:v1.15.3) 🖼
 • Preparing nodes 📦  ...
 ✓ Preparing nodes 📦
 • Creating kubeadm config 📜  ...
 ✓ Creating kubeadm config 📜
 • Starting control-plane 🕹️  ...
 ✓ Starting control-plane 🕹️
 • Installing CNI 🔌  ...
 ✓ Installing CNI 🔌
 • Installing StorageClass 💾  ...
 ✓ Installing StorageClass 💾
Cluster creation complete. You can now use the cluster with:

export KUBECONFIG="$(kind get kubeconfig-path --name="etcd-e2e")"
kubectl cluster-info



--- FAIL: TestE2E_Kind (319.15s)
    e2e_test.go:159: Starting Kind cluster
    e2e_test.go:63: Applying CRDs
    kubectl.go:17: Running kubectl apply --kustomize /home/richard/projects/improbable-eng/etcd-cluster-operator/config/crd
    kubectl.go:26: customresourcedefinition.apiextensions.k8s.io/etcdclusters.etcd.improbable.io created
        customresourcedefinition.apiextensions.k8s.io/etcdpeers.etcd.improbable.io created
        
    e2e_test.go:68: Building operator image
    e2e_test.go:86: Loading image in to Kind cluster
    e2e_test.go:95: Applying operator
    kubectl.go:17: Running kubectl apply --kustomize /home/richard/projects/improbable-eng/etcd-cluster-operator/config/rbac
    kubectl.go:26: role.rbac.authorization.k8s.io/leader-election-role created
        clusterrole.rbac.authorization.k8s.io/manager-role created
        clusterrole.rbac.authorization.k8s.io/proxy-role created
        rolebinding.rbac.authorization.k8s.io/leader-election-rolebinding created
        clusterrolebinding.rbac.authorization.k8s.io/manager-rolebinding created
        clusterrolebinding.rbac.authorization.k8s.io/proxy-rolebinding created
        service/controller-manager-metrics-service created
        
    kubectl.go:17: Running kubectl apply --kustomize /home/richard/projects/improbable-eng/etcd-cluster-operator/config/manager
    kubectl.go:26: deployment.apps/etcd-cluster-operator created
        
    kubectl.go:17: Running kubectl patch --kustomize /home/richard/projects/improbable-eng/etcd-cluster-operator/config/manager --type json --patch [
        			{
        				"op": "replace", 
        				"path": "/spec/template/spec/containers/0/image", 
        				"value": "etcd-cluster-operator:test",
        			},
        			{
        				"op": "replace", 
        				"path": "/spec/template/spec/containers/0/imagePullPolicy", 
        				"value": "Never",
        			},
        		]
    kubectl.go:33: deployment.apps/etcd-cluster-operator patched
        
    kubectl.go:17: Running kubectl get deploy etcd-cluster-operator -o=jsonpath='{.status.readyReplicas}'
    e2e_test.go:133: Running tests
    kubectl.go:17: Running kubectl apply --filename /home/richard/projects/improbable-eng/etcd-cluster-operator/internal/test/e2e/fixtures/cluster-client-service.yaml
    kubectl.go:26: service/my-cluster-external created
        
    kubectl.go:17: Running kubectl apply --filename /home/richard/projects/improbable-eng/etcd-cluster-operator/config/samples/etcd_v1alpha1_etcdcluster.yaml
    kubectl.go:26: etcdcluster.etcd.improbable.io/my-cluster created
        
    e2e_test.go:213: Checking if ETCD is available
    e2e_test.go:213: Checking if ETCD is available
    e2e_test.go:213: Checking if ETCD is available
    e2e_test.go:213: Checking if ETCD is available
    e2e_test.go:213: Checking if ETCD is available
    e2e_test.go:213: Checking if ETCD is available
    e2e_test.go:213: Checking if ETCD is available
    e2e_test.go:213: Checking if ETCD is available
    e2e_test.go:213: Checking if ETCD is available
    e2e_test.go:213: Checking if ETCD is available
    e2e_test.go:213: Checking if ETCD is available
    require.go:794: 
        	Error Trace:	e2e_test.go:224
        	            				e2e_test.go:134
        	Error:      	Received unexpected error:
        	            	client: etcd cluster is unavailable or misconfigured; error #0: client: endpoint http://127.0.0.1:2379 exceeded header timeout
        	Test:       	TestE2E_Kind
    e2e_test.go:185: Stopping Kind cluster
=== RUN   TestE2E_CurrentContext
--- SKIP: TestE2E_CurrentContext (0.00s)
    e2e_test.go:139: 
FAIL
FAIL	github.com/improbable-eng/etcd-cluster-operator/internal/test/e2e	319.204s
FAIL

I'll spend a few minutes digging into that e2e test failure.

require.NoError(t, err)

// Ensure the operator starts.
err = try.Eventually(func() error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Unrelated to this branch, but I noticed that testify has its own Eventually, so perhaps we can use that in future:

internal/test/e2e/e2e_test.go Show resolved Hide resolved
labels:
control-plane: controller-manager
name: system
---
Copy link
Contributor

Choose a reason for hiding this comment

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

I see why this is a problem, but I think the kubebuilder uses this namespace intentionally with the expectation that you will add a kustomization which adds a namespace prefix. e.g.

# Adds namespace to all resources.
namespace: e2e

# Value of this field is prepended to the
# names of all resources, e.g. a deployment named
# "wordpress" becomes "alices-wordpress".
# Note that it should also match with the prefix (text before '-') of the namespace
# field above.
namePrefix: e2e-

# Labels to add to all resources and selectors.
#commonLabels:

See:

Copy link
Contributor

Choose a reason for hiding this comment

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

So consider just updating the kustomization.yaml flie instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i found it puzzling why the default value was not default

config/manager/manager.yaml Outdated Show resolved Hide resolved
internal/test/e2e/e2e_test.go Outdated Show resolved Hide resolved
internal/test/e2e/e2e_test.go Show resolved Hide resolved
@wallrj
Copy link
Contributor

wallrj commented Oct 18, 2019

It's quite frustrating that the logged progress messages (via t.Log) only show up at the end of the test run.
Others have asked for a -test.streamlogs flag but it hasn't been implemented yet: golang/go#24929
Consider using logging those messages with logr too.

@wallrj
Copy link
Contributor

wallrj commented Oct 18, 2019

Ignore my comment (above) about the tests failing. I'd forgotten that this branch hasn't got a EtcdCluster controller which creates peers, so it was never going to pass.
I merged in #27 branch and then encountered a bug in that branch.

It'd be nice if this E2E would grab the logs from the operator in case of test failures, but that can be a future improvement.

@wallrj
Copy link
Contributor

wallrj commented Oct 18, 2019

I also notice that the test leaves behind internal/test/e2e/.kube/ containing various cache files.
It'd be nice if it didn't do this,
Perhaps you need to pass through the $HOME variable when you run kubectl so that it uses the standard ~/.kube directory.

@adamhosier
Copy link
Contributor Author

@wallrj thanks for the review. i've set the homedir in the kubectl helpers & that seems to avoid building the cache inside the repo. on logs, my strategy has been to include high level checkpoints in the test's logs, which will allow people to dig in to the more specific logs of the failing component. agree that streaming logs would be a nice feature

@adamhosier adamhosier merged commit e22d7a7 into improbable-eng:master Oct 21, 2019
@adamhosier adamhosier deleted the feature/e2e-test branch October 21, 2019 09:40
gottwald pushed a commit to digitalocean/etcd-cluster-operator that referenced this pull request Jun 9, 2022
…ler-gen-update

Revert "update controller gen and kustomize versions"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants