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 unable to delete resource that removed from git for k8s apps #4207

Merged
merged 1 commit into from
Feb 22, 2023

Conversation

khanhtc1202
Copy link
Member

What this PR does / why we need it:

Previously due to this wrong iteration make changed via setNamespace does not returned after loader.LoadManifests run, thus annotation and logic which based on manifest.ResourceKey.Namespace go wrong way

From

ResourceKey: apps/v1:Deployment:default:simple

To

ResourceKey: apps/v1:Deployment:test:simple

Which issue(s) this PR fixes:

Fixes #

Does this PR introduce a user-facing change?:

Fix unable to delete k8s resources which those manifests removed from Git

for _, m := range manifests {
m.Key.Namespace = namespace
for i := range manifests {
manifests[i].Key.Namespace = namespace
Copy link
Member

Choose a reason for hiding this comment

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

I could understand what this wants to do, but originally the manifest is not a pointer, right?

Copy link
Member Author

@khanhtc1202 khanhtc1202 Feb 22, 2023

Choose a reason for hiding this comment

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

basically, this function accepts manifests which of type slice as it input. Go makes all function's input pass by value, thus it copy this manifests slide and manipulate thing inside the function. The point to note here is that even it copy the slide, the underlying array of that slide is remained to be the same, so basically change "that" array will change after function returns. Previously, instead of change the underlying array, m is a temporary var that ref to element of slide and change make on it does not reflect on the underlying array thus the changes are not remained after function end. And it doesn't matter the underlying array is of type pointer or not, this playground is an example.

https://go.dev/play/p/Osr6eY4eh0A

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I totally understand. Thank you.

@khanhtc1202 khanhtc1202 merged commit e395366 into master Feb 22, 2023
@khanhtc1202 khanhtc1202 deleted the fix-annotation-wrong branch February 22, 2023 02:09
@github-actions github-actions bot mentioned this pull request Feb 27, 2023
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.

2 participants