Skip to content

Remove resources when terminating the environment#519

Merged
knative-prow[bot] merged 3 commits intoknative-extensions:mainfrom
pierDipi:remove-resources-when-environment-is-terminated
May 5, 2023
Merged

Remove resources when terminating the environment#519
knative-prow[bot] merged 3 commits intoknative-extensions:mainfrom
pierDipi:remove-resources-when-environment-is-terminated

Conversation

@pierDipi
Copy link
Copy Markdown
Member

@pierDipi pierDipi commented May 4, 2023

When calling env.Finish() the resources that have been created by such environment should be removed.

So far, we were relying on the namespace deletion to clean up resources, however, if a precreated namespace is used for multiple tests and multiple environments, the cluster is full of resources that are not needed anymore since those tests were successfully run.

@knative-prow
Copy link
Copy Markdown

knative-prow bot commented May 4, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: pierDipi

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

The pull request process is described here

Details 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

@knative-prow knative-prow bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 4, 2023
@pierDipi
Copy link
Copy Markdown
Member Author

pierDipi commented May 4, 2023

/cc @maschmid @mgencur

@knative-prow knative-prow bot requested review from maschmid and mgencur May 4, 2023 07:02
@knative-prow knative-prow bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label May 4, 2023
@@ -200,12 +200,25 @@ func (f *Feature) References() []corev1.ObjectReference {
//
// Expected to be used as a StepFn.
func (f *Feature) DeleteResources(ctx context.Context, t T) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This function still has the comment:

// It doesn't fail when a referenced resource couldn't be deleted.
// Use References to get the undeleted resources.

We're now changing the behavior. When some resource couldn't be deleted we're failing the test. Is this intentional?

A few lines below we still assign this but it will be probably unused because we now fail the test with t.Fatal immediately:

f.refs = refFailedDeletion

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

weren't we failing even without this patch?

	err := wait.Poll(time.Second, 4*time.Minute, func() (bool, error) { // ... }
	if err != nil {
		LogReferences(refFailedDeletion...)(ctx, t)
		t.Fatalf("failed to wait for resources to be deleted: %v", err)
	}

https://github.com/knative-sandbox/reconciler-test/blob/dc48d52d7e3cf5b7d2c8078b8907c5df2522c0c1/pkg/feature/feature.go#L229-L260

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hmm. OK. So this condition was broken earlier. And the comment is not valid for a long time. So, now I wonder why f.refs = refFailedDeletion is still there (probably a bug).
Let's remove the invalid comment for now. Not sure what to do about the refs.

defer f.refsMu.Unlock()

f.refs = refFailedDeletion
return refFailedDeletion, nil
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can refFailedDeletion ever be non-nil here? (whenever refFailedDeletion is assigned, an error is returned anyway?)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, that's correct and an existing problem, I'll drop it

@knative-prow-robot knative-prow-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 5, 2023
pierDipi added 3 commits May 5, 2023 10:01
When calling env.Finish() the resources that have been created
by such environment should be removed.

So far, we were relying on the namespace deletion to clean
up resources, however, if a precreated namespace is used
for multiple tests and multiple environments, the cluster
is full of resources that are not needed anymore since
those tests were successfully run.

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>
Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>
Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>
@pierDipi pierDipi force-pushed the remove-resources-when-environment-is-terminated branch from a7f0e65 to 8414e88 Compare May 5, 2023 08:01
@knative-prow-robot knative-prow-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 5, 2023
@pierDipi
Copy link
Copy Markdown
Member Author

pierDipi commented May 5, 2023

@maschmid @mgencur I believe I've addressed your comments in the last commits

@mgencur
Copy link
Copy Markdown
Contributor

mgencur commented May 5, 2023

/lgtm

Thanks!

@knative-prow knative-prow bot added the lgtm Indicates that a PR is ready to be merged. label May 5, 2023
@knative-prow knative-prow bot merged commit 8a5db1b into knative-extensions:main May 5, 2023
@pierDipi pierDipi deleted the remove-resources-when-environment-is-terminated branch May 23, 2023 15:01
@pierDipi
Copy link
Copy Markdown
Member Author

/cherry-pick release-1.10

@pierDipi
Copy link
Copy Markdown
Member Author

/cherry-pick release-1.9

@knative-prow-robot
Copy link
Copy Markdown

@pierDipi: new pull request created: #531

Details

In response to this:

/cherry-pick release-1.10

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.

@knative-prow-robot
Copy link
Copy Markdown

@pierDipi: #519 failed to apply on top of branch "release-1.9":

Patch is empty.
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

Details

In response to this:

/cherry-pick release-1.9

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.

@pierDipi
Copy link
Copy Markdown
Member Author

/cherry-pick release-1.9

pierDipi added a commit to pierDipi/reconciler-test that referenced this pull request May 23, 2023
…#519)

* Remove resources when terminating the environment

When calling env.Finish() the resources that have been created
by such environment should be removed.

So far, we were relying on the namespace deletion to clean
up resources, however, if a precreated namespace is used
for multiple tests and multiple environments, the cluster
is full of resources that are not needed anymore since
those tests were successfully run.

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>

* Remove refFailedDeletion since it's useless

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>

* Remove wrong comment

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>

---------

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>
@knative-prow-robot
Copy link
Copy Markdown

@pierDipi: new pull request created: #532

Details

In response to this:

/cherry-pick release-1.9

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.

@pierDipi pierDipi restored the remove-resources-when-environment-is-terminated branch February 19, 2025 22:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants