Skip to content

refactor: Supports cleaning resources for static projects with test-acc-tf-p-keep prefix #3269

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

Merged
merged 5 commits into from
Apr 25, 2025

Conversation

EspenAlbert
Copy link
Collaborator

@EspenAlbert EspenAlbert commented Apr 10, 2025

Description

Related issue: https://jira.mongodb.org/browse/CLOUDP-314965

Supports cleaning projects with "test-acc-tf-p-keep" prefix, that shouldn't be deleted but have resources removed when running the cleanup (the project should be empty after tests).

We have various tests that depend on using specific projects with feature flags enabled.
However, these projects risk having extra resources that are not cleaned.

The only resources found for deletion:

test-acc-tf-p-keep-ear-AWS-private-endpoint (6790e57a9b41416f5c216fee) # 3 stream instances
test-acc-tf-p-keep-ear-private-endpoint (66d83bcc1fe1835125c52422) # no resources
test-acc-tf-p-keep-encryption-at-rest (67810c93a7dcf40b5f0db4c2) # no resources

Sweeper Alternative considered

tl;dr: Uses the same mechanism as go test but with a -sweep={regionName} flag. I consider our current cleanup test to be easier to adapt than adding custom sweepers and a new CI workflow.

Type of change:

  • Bug fix (non-breaking change which fixes an issue). Please, add the "bug" label to the PR.
  • New feature (non-breaking change which adds functionality). Please, add the "enhancement" label to the PR. A migration guide must be created or updated if the new feature will go in a major version.
  • Breaking change (fix or feature that would cause existing functionality to not work as expected). Please, add the "breaking change" label to the PR. A migration guide must be created or updated.
  • This change requires a documentation update
  • Documentation fix/enhancement

Required Checklist:

  • I have signed the MongoDB CLA
  • I have read the contributing guides
  • I have checked that this change does not generate any credentials and that they are NOT accidentally logged anywhere.
  • I have added tests that prove my fix is effective or that my feature works per HashiCorp requirements
  • I have added any necessary documentation (if appropriate)
  • I have run make fmt and formatted my code
  • If changes include deprecations or removals I have added appropriate changelog entries.
  • If changes include removal or addition of 3rd party GitHub actions, I updated our internal document. Reach out to the APIx Integration slack channel to get access to the internal document.

Further comments

@github-actions github-actions bot added the bug label Apr 10, 2025
@@ -37,6 +37,9 @@ var (
keptPrefixes = []string{
"test-acc-tf-p-keep",
}
keepProjectEmptyPrefixes = []string{
"test-acc-tf-p-empty",
Copy link
Member

Choose a reason for hiding this comment

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

is there any case where we want to keep the project without deleting anything in it? are they with prefix test-acc-tf-p-keep? also I can imagine that in keep ones we want to keep some type of resource (e.g. private endpoint) but delete others (like clusters). so not sure if it will be more general to use only one prefix project, e.g. test-acc-tf-p-keep, and then use "keep" in resources we want to keep inside, e.g. cluster "test-acc-tf-c-keep-mycluster would me not to delete that cluster.

Copy link
Member

Choose a reason for hiding this comment

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

Agree we can preserve test-acc-tf-p-keep prefix for all cases.
Not sure how complex it would be to start adding different keep prefixes for each resource type, as for this PR maybe we can stick to test-acc-tf-p-keep (preserves any resources) and test-acc-tf-p-keep-empty (removes all resources)?

Copy link
Member

Choose a reason for hiding this comment

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

@AgustinBettati FYI, see also comments in the doc

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed test-acc-tf-p-keep instead

@@ -37,6 +37,9 @@ var (
keptPrefixes = []string{
"test-acc-tf-p-keep",
}
keepProjectEmptyPrefixes = []string{
Copy link
Member

Choose a reason for hiding this comment

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

changes LGTM, would only double check that for the following projects we don't have any static resources we are relying on that could be deleted. (I dont believe its the case)
EAR-example (6792ac6ceaa5601d0f45dc95)
test-acc-tf-p-keep-ear-AWS-private-endpoint (6790e57a9b41416f5c216fee)
test-acc-tf-p-keep-ear-private-endpoint (66d83bcc1fe1835125c52422)
test-acc-tf-p-keep-encryption-at-rest (67810c93a7dcf40b5f0db4c2)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Checked. Only test-acc-tf-p-keep-ear-AWS-private-endpoint has a few steam_instances, but those are ok to delete

Copy link
Contributor

This PR has gone 7 days without any activity and meets the project’s definition of "stale". This will be auto-closed if there is no new activity over the next 7 days. If the issue is still relevant and active, you can simply comment with a "bump" to keep it open, or add the label "not_stale". Thanks for keeping our repository healthy!

@github-actions github-actions bot added the stale label Apr 17, 2025
@github-actions github-actions bot closed this Apr 20, 2025
@EspenAlbert EspenAlbert added the not_stale Not stale issue or PR label Apr 21, 2025
@EspenAlbert EspenAlbert reopened this Apr 21, 2025
@EspenAlbert EspenAlbert changed the title refactor: Supports empty prefix for projects that shouldn't be deleted but have resources removed refactor: Supports cleaning resources for static projects with test-acc-tf-p-keep prefix Apr 22, 2025
@EspenAlbert EspenAlbert marked this pull request as ready for review April 22, 2025 15:50
@EspenAlbert EspenAlbert requested a review from a team as a code owner April 22, 2025 15:50
@@ -204,11 +211,6 @@ func removeProjectResources(ctx context.Context, t *testing.T, dryRun bool, clie
}

func projectSkipReason(p *admin.Group, skipProjectsAfter time.Time, onlyEmpty bool) string {
Copy link
Member

Choose a reason for hiding this comment

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

what's the difference between projectSkipReason and projectNoDeleteReason?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

projectSkipReason avoids cleaning the project alltogether. (All non bot projects are not cleaned by default)
skipProjectDelete cleans resources but doesn't delete the project.

Copy link
Member

Choose a reason for hiding this comment

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

thanks for the clarification

Copy link
Member

@AgustinBettati AgustinBettati left a comment

Choose a reason for hiding this comment

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

LGTM, just a suggestion for improving clarity

Comment on lines 100 to 105
t.Logf("will try to delete %d projects:", len(projectsToDelete))
slices.Sort(projectInfos)
t.Log(strings.Join(projectInfos, "\n"))
var deleteErrors int
var emptyProjectCount int
for name, projectID := range projectsToDelete {
Copy link
Member

Choose a reason for hiding this comment

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

should we adjust the log to mention the current behaviour? "deleting project resources and optionally delete project"
same for variable projectsToDelete maybe projectsToCleanAndDelete makes it more clear?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good idea. Changed in 975741b

@EspenAlbert EspenAlbert merged commit c51a860 into master Apr 25, 2025
40 checks passed
@EspenAlbert EspenAlbert deleted the clean_project_resources branch April 25, 2025 05:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug not_stale Not stale issue or PR stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants