-
Notifications
You must be signed in to change notification settings - Fork 141
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
fix: 000011_workspace_no_outputs_test test #917
Conversation
666afe1
to
5861a1b
Compare
1. It used the same resource name as 000010 test. 2. We requested resources to be deleted, but we didn't wait them to be deleted. fixes #908 References: * #908 Signed-off-by: Balazs Nadasdi <[email protected]>
5861a1b
to
dbd351c
Compare
Signed-off-by: Balazs Nadasdi <[email protected]>
controllers/cleaner_test.go
Outdated
Object client.Object | ||
} | ||
|
||
func waitResourceToBeDelete(g gomega.Gomega, resource resourceToBeDeleted) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you just get the key from the object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about it, I started to build a Cleaner and just call cleaner.AddResource(object)
and a single defer on cleaner.Cleanup()
. It had some issues because with that I moved the k8sclient.Delete
call too, but it did not like some of the resources on the eventual part (never failed). I'm still trying to do that, but I wanted to put this out to run ci tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean can you just pass client.Object
here (and []client.Object
below), since the other fields in resourceToBeDeleted
can be derived from the client.Object
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's exactly what I try to do, but somehow the k8sClient.Get
call doesn't like that. That's why I'm still trying to do that and not pushed yet.
I wonder if we could rely on namespaces to avoid having to clean up things after we are done with the tests. Having to wait those deletes will slow down our tests quite a bit. |
I do that elsewhere, and clean them up. Tests should in general be able to run in parallel, and using separate namespaces helps with that. (Running in parallel also means doing cleanup on each test doesn't add up to lots of running time) |
3b71235
to
9d2ded5
Compare
I think then we would have to define a lot of namespaces when we create the controller as it does not process resources in namespaces we didn't define in Note: |
I tried to create a `Cleaner` struct like: ```go type Cleaner struct { resources []client.Object } func (c *Cleaner) AddResource(client.Object) {} func (c *Cleaner) Cleanup(gomega) ``` so we could use it like ```go cleaner := NewCleaner() defer cleaner.Cleanup() // ... cleaner.AddResource(&tfresource) ``` But for some reasons, no matter what I tried it stuck on the `client.Get` in `Eventually`. I don't like global variables, but using it in the `waitResourceToBeDelete` instead of an extra argument makes it cleaner to use in tests. Signed-off-by: Balazs Nadasdi <[email protected]>
9d2ded5
to
88f9d21
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Run both tests locally and they passed.
❯ make TARGET="^Test_000010" target-test
/Users/yiannis/projects/github.com/weaveworks/tf-controller/bin/controller-gen rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config="config/crd/bases"
cd api; /Users/yiannis/projects/github.com/weaveworks/tf-controller/bin/controller-gen rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config="../config/crd/bases"
go generate ./...
WARNING: Invoking counterfeiter multiple times from "go generate" is slow.
Consider using counterfeiter:generate directives to speed things up.
See https://github.com/maxbrunsfeld/counterfeiter#step-2b---add-counterfeitergenerate-directives for more information.
Set the "COUNTERFEITER_NO_GENERATE_WARNING" environment variable to suppress this message.
Writing `FakeProvider` to `providerfakes/fake_provider.go`... Done
/Users/yiannis/projects/github.com/weaveworks/tf-controller/bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
cd api; /Users/yiannis/projects/github.com/weaveworks/tf-controller/bin/controller-gen object:headerFile="../hack/boilerplate.go.txt" paths="./..."
curl -s https://raw.githubusercontent.com/fluxcd/source-controller/v1.0.0-rc.1/config/crd/bases/source.toolkit.fluxcd.io_gitrepositories.yaml > config/crd/bases/gitrepositories.yaml
curl -s https://raw.githubusercontent.com/fluxcd/source-controller/v1.0.0-rc.1/config/crd/bases/source.toolkit.fluxcd.io_buckets.yaml > config/crd/bases/buckets.yaml
curl -s https://raw.githubusercontent.com/fluxcd/source-controller/v1.0.0-rc.1/config/crd/bases/source.toolkit.fluxcd.io_ocirepositories.yaml > config/crd/bases/ocirepositories.yaml
go fmt ./...
go vet ./...
/Users/yiannis/projects/github.com/weaveworks/tf-controller/bin/gen-crd-api-reference-docs -api-dir=./api/v1alpha2 -config=./hack/api-docs/config.json -template-dir=./hack/api-docs/template -out-file=./docs/References/terraform.md
I0906 12:56:54.629619 40060 main.go:129] parsing go packages in directory ./api/v1alpha2
I0906 12:56:58.057845 40060 main.go:231] using package=./api/v1alpha2
I0906 12:56:58.085765 40060 main.go:167] written to ./docs/References/terraform.md
INSECURE_LOCAL_RUNNER=1 DISABLE_K8S_LOGS=1 DISABLE_TF_LOGS=1 DISABLE_TF_K8S_BACKEND=1 DISABLE_WEBHOOK_TLS_VERIFY=1 KUBEBUILDER_ASSETS="/Users/yiannis/projects/github.com/weaveworks/tf-controller/testbin/k8s/1.28.0-darwin-amd64" go test ./controllers -coverprofile cover.out -v -run ^Test_000010
=== RUN Test_000010_no_outputs_test
SPEC: This spec describes the behaviour of a Terraform resource with no backend, and `auto` approve.
IT should be reconciled to have available outputs.
GIVEN: a GitRepository
BY: defining a new GitRepository resource.
BY: creating the GitRepository resource in the cluster.
IT should be created successfully.
GIVEN: the GitRepository's reconciled status.
BY: setting the GitRepository's status, with the downloadable BLOB's URL, and the correct checksum.
IT should be updated successfully.
GIVEN: a Terraform resource with auto approve, attached to the given GitRepository resource.
BY: creating a new TF resource and attaching to the repo via `sourceRef`.
IT should be created and attached successfully.
BY: checking that the TF resource existed inside the cluster.
IT should be reconciled and contain some status conditions.
BY: checking that the TF resource's status conditions has some elements.
IT should be planned.
BY: checking that the Plan's reason of the TF resource become `TerraformPlannedWithChanges`.
IT should generate the Secret containing the plan named with branch and commit id.
BY: checking that the Secret contains plan-master-b8e362c206e3d0cbb7ed22ced771a0056455a2fb in its labels.
IT should contain an Apply condition saying that the plan were apply successfully.
BY: checking that the reason of the Apply condition is TerraformAppliedSucceed, and the LastAppliedPlan is the plan.
IT should have an available output.
BY: checking that the Terraform resource's .status.availableOutputs contains hello_world as an output name.
IT should not produce a Secret because the controller runs locally, outside Kubernetes.
BY: checking there are no secret generated by default.
--- PASS: Test_000010_no_outputs_test (2.55s)
PASS
coverage: 28.4% of statements
failed waiting for all runnables to end within grace period of 30s: context deadline exceeded
ok github.com/weaveworks/tf-controller/controllers 37.053s coverage: 28.4% of statements
❯ make TARGET="^Test_000011" target-test
/Users/yiannis/projects/github.com/weaveworks/tf-controller/bin/controller-gen rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config="config/crd/bases"
cd api; /Users/yiannis/projects/github.com/weaveworks/tf-controller/bin/controller-gen rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config="../config/crd/bases"
go generate ./...
WARNING: Invoking counterfeiter multiple times from "go generate" is slow.
Consider using counterfeiter:generate directives to speed things up.
See https://github.com/maxbrunsfeld/counterfeiter#step-2b---add-counterfeitergenerate-directives for more information.
Set the "COUNTERFEITER_NO_GENERATE_WARNING" environment variable to suppress this message.
Writing `FakeProvider` to `providerfakes/fake_provider.go`... Done
/Users/yiannis/projects/github.com/weaveworks/tf-controller/bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
cd api; /Users/yiannis/projects/github.com/weaveworks/tf-controller/bin/controller-gen object:headerFile="../hack/boilerplate.go.txt" paths="./..."
curl -s https://raw.githubusercontent.com/fluxcd/source-controller/v1.0.0-rc.1/config/crd/bases/source.toolkit.fluxcd.io_gitrepositories.yaml > config/crd/bases/gitrepositories.yaml
curl -s https://raw.githubusercontent.com/fluxcd/source-controller/v1.0.0-rc.1/config/crd/bases/source.toolkit.fluxcd.io_buckets.yaml > config/crd/bases/buckets.yaml
curl -s https://raw.githubusercontent.com/fluxcd/source-controller/v1.0.0-rc.1/config/crd/bases/source.toolkit.fluxcd.io_ocirepositories.yaml > config/crd/bases/ocirepositories.yaml
go fmt ./...
go vet ./...
/Users/yiannis/projects/github.com/weaveworks/tf-controller/bin/gen-crd-api-reference-docs -api-dir=./api/v1alpha2 -config=./hack/api-docs/config.json -template-dir=./hack/api-docs/template -out-file=./docs/References/terraform.md
I0906 13:03:26.060631 40870 main.go:129] parsing go packages in directory ./api/v1alpha2
I0906 13:03:29.669792 40870 main.go:231] using package=./api/v1alpha2
I0906 13:03:29.696252 40870 main.go:167] written to ./docs/References/terraform.md
INSECURE_LOCAL_RUNNER=1 DISABLE_K8S_LOGS=1 DISABLE_TF_LOGS=1 DISABLE_TF_K8S_BACKEND=1 DISABLE_WEBHOOK_TLS_VERIFY=1 KUBEBUILDER_ASSETS="/Users/yiannis/projects/github.com/weaveworks/tf-controller/testbin/k8s/1.28.0-darwin-amd64" go test ./controllers -coverprofile cover.out -v -run ^Test_000011
=== RUN Test_000011_bad_tar_gz_no_outputs_test
SPEC: This spec describes the behaviour of a Terraform resource that obtains a bad tar.gz file blob from its Source reference.
IT should report the error and stop reconcile.
GIVEN: a GitRepository
BY: defining a new GitRepository resource
BY: creating the GitRepository resource in the cluster.
IT should be created successfully.
GIVEN: the GitRepository's reconciled status.
BY: setting the GitRepository's status, with the downloadable *bad* BLOB's URL, with the correct checksum.
IT should be updated successfully.
GIVEN: a Terraform object with auto approve, and attaching it to the bad GitRepository resource.
BY: creating a new TF resource and attaching to the bad repo via `sourceRef`.
IT should be created and attached successfully.
BY: checking that the TF resource existed inside the cluster.
IT should be reconciled and contain some status conditions.
BY: checking that the TF resource's status conditions has 1 element.
IT should be an error
BY: checking that the Ready's reason of the TF resource become `ArtifactFailed`.
--- PASS: Test_000011_bad_tar_gz_no_outputs_test (17.14s)
PASS
coverage: 17.7% of statements
ok github.com/weaveworks/tf-controller/controllers 21.536s coverage: 17.7% of statements
fixes #908
References: