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 namespace issue #319

Closed

Conversation

dcarrolloreilly
Copy link

When running popeye from cmd line and passing the -n option to specify a namespace the lint is run for the entire cluster. It appears the namespace is set in context correctly but as we enter the loop to run thru the scrubbers if we encounter a resource that is not namespaced the context is updated to be cluster-wide with a -. This never gets reset back so the next time through the loop we just keep scanning every namespace. This fix grabs the namespace set, stores it in a var and resets it within the loop so that the namespace flag will work correctly limiting the display.

Copy link
Owner

@derailed derailed left a comment

Choose a reason for hiding this comment

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

@dcarrolloreilly Great catch! Thank you for this update!!

pkg/popeye.go Outdated
@@ -256,6 +257,8 @@ func (p *Popeye) lint() (int, int, error) {
continue
}

ctx = context.WithValue(ctx, internal.KeyNamespace, orig_ns)
Copy link
Owner

Choose a reason for hiding this comment

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

Context is immutable. This call will create a brand new context every time.
I think it's best to only alter the original context if we have a clusterwide resource.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks - being new to Go in general I hope I am not heading off in the wrong direction but if I test conditionally within the loop to see if the namespace has been reset in ctx, and only if it has, mutate it using a function like I have included here seems to work. Was this what you had in mind?

Copy link
Owner

@derailed derailed left a comment

Choose a reason for hiding this comment

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

@dcarrolloreilly Thanks for the update. Please see comment below

@@ -256,6 +262,11 @@ func (p *Popeye) lint() (int, int, error) {
continue
}

// mutate ctx for namespace only if resource is clusterwide
Copy link
Owner

Choose a reason for hiding this comment

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

I think we want to keep the original context here and only create a new context with the new namespace when we detect a cluster wide resource.
FYI context in go is immutable ie when you alter a context in any way you will get a new context.
Does this make sense?

Copy link
Owner

Choose a reason for hiding this comment

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

So I was experimenting with this a bit more and I think there is a indeed a bigger bug :(
The issue here is the context switch timing is wrong. We need to alter/reset the context further down the stack.
I'll take a closer peek...

@derailed
Copy link
Owner

@dcarrolloreilly I took a pass on this and think this issue was resolved on v0.21.5. Please reopen if that's not the case.

@derailed derailed closed this Nov 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants