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

fix: reverse order of deployers during cleanup (#7284) #7925

Merged
merged 2 commits into from
Oct 19, 2022

Conversation

chronicc
Copy link
Contributor

@chronicc chronicc commented Oct 6, 2022

Fixes: #7284
Related: Relevant tracking issues, for context
Merge before/after: Dependent or prerequisite PRs

Description

Add a new deployer slice during cleanup function of the DeployerMux which is reversed in it's order. This change should be covered by the existing unittests since no new function was added.

User facing changes (remove if N/A)

Before:
Modules are undeployed in the same order as they are deployed. Visible in the console as

^CCleaning up...
release "postgresql" uninstalled
 - deployment.apps "example-django" deleted
INFO[0016] Cleanup completed in 886.10607ms              subtask=-1 task=DevLoop

After:
Modules are undeployed in reverse order.

^CCleaning up...
 - deployment.apps "example-django" deleted
release "postgresql" uninstalled
INFO[0328] Cleanup completed in 1.038 second             subtask=-1 task=DevLoop

Comment on lines 164 to 169
// Reverse order of deployers for cleanup to ensure resources
// are removed before their definitions are removed.
revDeployers := m.deployers
for i, j := 0, len(revDeployers)-1; i < j; i, j = i+1, j-1 {
revDeployers[i], revDeployers[j] = revDeployers[j], revDeployers[i]
}
Copy link
Member

Choose a reason for hiding this comment

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

Thanks. Was wondering if there is a utility method which already does that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good point. Searching the internet I did not find any lib that does this. I was also supprised the slice type has no internal method since this is such a common task. Searching the skaffold source code for for i, j and for for .*,.*:=.*,len does not give any results.

The golang completion on the other side provides a slice.reverse! method which automatically creates the for loop. Maybe that's why there is no lib or function.

I can put such a function somewhere in the skaffold source code if you wish. I need help finding the location where such a function would be placed best.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looking into this now.

Copy link
Contributor Author

@chronicc chronicc Oct 12, 2022

Choose a reason for hiding this comment

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

@gsquared94 I tried adding a function to the file you suggested. However when I did this, I created a dependency lopp between util.go and deploy.go.

I also tried creating a generic slice reverse function in utils but since the go.mod file says to use at least go 1.17, I could not use generics.

In the end I added it to DeployMux since this is the only place using this function for now.

@codecov
Copy link

codecov bot commented Oct 7, 2022

Codecov Report

Merging #7925 (df4be15) into main (290280e) will decrease coverage by 3.69%.
The diff coverage is 53.94%.

@@            Coverage Diff             @@
##             main    #7925      +/-   ##
==========================================
- Coverage   70.48%   66.78%   -3.70%     
==========================================
  Files         515      594      +79     
  Lines       23150    28773    +5623     
==========================================
+ Hits        16317    19217    +2900     
- Misses       5776     8136    +2360     
- Partials     1057     1420     +363     
Impacted Files Coverage Δ
cmd/skaffold/app/cmd/credits/export.go 0.00% <0.00%> (ø)
cmd/skaffold/app/cmd/deploy.go 40.90% <0.00%> (-12.94%) ⬇️
cmd/skaffold/app/cmd/test.go 44.44% <0.00%> (ø)
cmd/skaffold/skaffold.go 0.00% <0.00%> (ø)
cmd/skaffold/app/cmd/inspect_tests.go 62.50% <14.28%> (-1.14%) ⬇️
cmd/skaffold/app/cmd/render.go 35.48% <18.18%> (-5.90%) ⬇️
cmd/skaffold/app/cmd/lsp.go 28.12% <28.12%> (ø)
cmd/skaffold/app/cmd/run.go 64.28% <33.33%> (-9.63%) ⬇️
cmd/skaffold/app/cmd/fix.go 56.41% <37.50%> (-20.07%) ⬇️
cmd/skaffold/app/cmd/verify.go 41.17% <41.17%> (ø)
... and 366 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@gsquared94
Copy link
Collaborator

@chronicc can you sign the cla?

New Contributors: Update this check after signing the CLA by clicking here.

@chronicc
Copy link
Contributor Author

chronicc commented Oct 14, 2022

Sorry for pushing again. I've rebased to main, fixed the linting erros and added a file to the gitignore for asdf.

@chronicc chronicc force-pushed the reverse-cleanup-order branch 2 times, most recently from ca20879 to 92229a2 Compare October 14, 2022 08:58
.tool-versions is used by asdf (package manager) to set the go version
for this repository
@tejal29 tejal29 merged commit 938500c into GoogleContainerTools:main Oct 19, 2022
@chronicc chronicc deleted the reverse-cleanup-order branch November 21, 2022 07:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Clean up order should be reverse of install order
3 participants