-
Notifications
You must be signed in to change notification settings - Fork 81
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 empty secret namespace issue in reconciler #1753
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1753 +/- ##
==========================================
- Coverage 65.11% 65.07% -0.04%
==========================================
Files 174 174
Lines 13137 13142 +5
==========================================
- Hits 8554 8552 -2
- Misses 4018 4025 +7
Partials 565 565 ☔ View full report in Codecov by Sentry. |
pkg/reconciler/reconciler.go
Outdated
// in ReconcileKind this r.secretNS is not set and it is needed when git provider | ||
// is not github. | ||
r.secretNS = repo.GetNamespace() | ||
if repo.Spec.GitProvider != nil && repo.Spec.GitProvider.Secret == nil && r.globalRepo.Spec.GitProvider != nil && r.globalRepo.Spec.GitProvider.Secret != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have the same code in reportFinalStatus. Can we have it in a single place? I mean if we have it in updatePipelineRunToInProgress, is it really needed in reportFinalStatus as well? Is it possible that reportFinalStatus is called without updatePipelineRunToInProgress being called earlier?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible that reportFinalStatus is called without updatePipelineRunToInProgress being called earlier?
@enarha yes it is possible that reportFinalStatus
will be called without updatePipelineRunToInProgress
if concurrency_limit
is not set and all PipelineRuns
are provisioned in STARTED
state by controller.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understood. Isn't there a common path (always executed) where we can move that code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understood. Isn't there a common path (always executed) where we can move that code?
🤔 Yes, at the beginning of ReconcileKind
it can be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But we don't have repo
reference object there in ReconcileKind
, should we fetch repo object there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we fetch repo object there?
@enarha if yes then I will need to fetch repo in ReconcileKind
and change queue_pipelineruns
func signature to pass repo.
pkg/reconciler/reconciler.go
Outdated
@@ -234,6 +234,13 @@ func (r *Reconciler) updatePipelineRunToInProgress(ctx context.Context, logger * | |||
if event.InstallationID > 0 { | |||
event.Provider.WebhookSecret, _ = pac.GetCurrentNSWebhookSecret(ctx, r.kinteract, r.run) | |||
} else { | |||
// in ReconcileKind this r.secretNS is not set and it is needed when git provider | |||
// is not github. | |||
r.secretNS = repo.GetNamespace() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to set this in reconciler field? can't we just pass the value while getting the secret, instead of setting it on reconciler?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@piyush-garg I think r.secretNS
is the field which is meant for fetching secret for PipelineRun, if you see its uses it is used only two times once in reportFinalStatus and in updatePipelineRunToInProgress.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but in case of global repo and all, setting this param can may be have adverse affect on next event etc, i would rather skip it for now like setting in reconciler
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I m not sure about the effect now but when i went through the code i see even r.secretNS is set either by repo.GetNamespace()
or r.secretNS = r.globalRepo.GetNamespace()
for globalRepo
@piyush-garg do you think it cause some issue 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see the point of @piyush-garg even if i don't think it would cause problem but i think @zakisk you can remove that variable being on the struct and instead be scoped to the function that would be at least a saner code.
076fd82
to
e99eb87
Compare
can you explain a bit more the problem statement of what you are solving, i am guessing myself and other reviewers can guess it from your PR but neither the SRVKP or the PR description describe how this bugs occurring and how to replicate it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pr is fine, just a few cleaning comment that would be needed....
pkg/reconciler/reconciler.go
Outdated
@@ -234,6 +234,13 @@ func (r *Reconciler) updatePipelineRunToInProgress(ctx context.Context, logger * | |||
if event.InstallationID > 0 { | |||
event.Provider.WebhookSecret, _ = pac.GetCurrentNSWebhookSecret(ctx, r.kinteract, r.run) | |||
} else { | |||
// in ReconcileKind this r.secretNS is not set and it is needed when git provider | |||
// is not github. | |||
r.secretNS = repo.GetNamespace() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see the point of @piyush-garg even if i don't think it would cause problem but i think @zakisk you can remove that variable being on the struct and instead be scoped to the function that would be at least a saner code.
@chmouel when PRs are acquired in queue_pipelinerun from semaphore and looped, (let assume that I got 5 PR and |
I had encounter this while I was writing gitea tests for SRVKP-5560 (PR link), so if you run tests of this PR without that |
fixed empty secret namespace issue in reconcile when git proivder is not github e.g. gitea, gitlab etc. added E2E tests as well to confirm behaviour. https://issues.redhat.com/browse/SRVKP-5897 Signed-off-by: Zaki Shaikh <zashaikh@redhat.com>
great but can you add this to the PR description, the git commit and the SRVKP ? that will makes easier for everyone to know what the code was doing.. |
yeah just wanted you add this to the PR description to explain to the reviewer like me (or qe engineers) when looking at the PR how to test your PR easily without having to read the code..... |
@chmouel oh, ok I will, I missed that. |
Added reproduction steps to SRVKP. |
LGTM, good work @zakisk |
Fixed empty secret namespace issue in reconcile when git proivder is not github. added E2E tests for gitea as well to confirm this behavior.
What's happening?
Let's take a scenario that I got 5 PipelineRun and I set
concurrency_limit
to 3 so when PRs are acquired in queue_pipelinerun from semaphore (I got 3 PRs in acquired list) and looped, for first PipelineRunr.secretNS
value is empty in the loop at this point when calling updatePipelineRunToInProgress and updatePipelineRunToInProgress returning error from this line saying "an empty namespace may not be set when a resource name is provided" and loop is ending on first PR leaving other two PRs (concurrency_limit - 1 PRs) in queued state and as they are removed from semaphore they aren't no more in acquired list when next time ReconcileKind is called. This PR addresses that bug.https://issues.redhat.com/browse/SRVKP-5897