-
Notifications
You must be signed in to change notification settings - Fork 210
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
CFE-866: feature: monitoring and handling "single" secret dynamically #1675
CFE-866: feature: monitoring and handling "single" secret dynamically #1675
Conversation
@chiragkyal: This pull request references CFE-866 which is a valid jira issue. Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.16.0" version, but no target version was set. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
/assign @deads2k |
case <-ctx.Done(): | ||
klog.Info("stopping informer due to context cancellation") | ||
if !i.StopInformer() { | ||
klog.Error("failed to stop informer") |
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.
Future-you can tell me if this was a good idea. I'm not sure either way.
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 think we can keep this message for now, later we may drop it.
pkg/secret/monitor.go
Outdated
|
||
klog.Info("starting informer") | ||
i.stopped = false | ||
i.lock.Unlock() |
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.
move to defer unlock
just under the lock. Both your unlocks are at the tail.
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.
Since informer.Run
is a blocking call, we need to unlock before invoking (starting any informer) it. I think moving unlock to defer
will lock this function forever.(after first call)
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.
Since
informer.Run
is a blocking call, we need to unlock before invoking (starting any informer) it. I think moving unlock todefer
will lock this function forever.(after first call)
that line below looks bugged. I explicitly (instead of implicitly) commented this time.
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.
After the latest changes, the StartInformer
is non-blocking. So I've moved it to defer unlock
pkg/secret/monitor.go
Outdated
} | ||
|
||
// StartInformer starts and runs the informer util the provided context is canceled, | ||
// or StopInformer() is called. It will block, so call via goroutine. |
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.
Start*
usually doesn't block in kube. Run
usually does. This looks easier to use if it doesn't block. Is there a use-case for blocking?
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.
This function is ultimately calling informer.Run
which is a blocking call, and for that reason it's also blocking.
If StartInformer()
name is misleading, should we name it RunInformer()
?
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.
This function is ultimately calling
informer.Run
which is a blocking call, and for that reason it's also blocking.
IfStartInformer()
name is misleading, should we name itRunInformer()
?
How about making it non-blocking?
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.
Updated to make it non-blocking
|
||
// RemoveSecretEventHandler removes a secret event handler and stops the informer if no handlers are left. | ||
// If the handler is not found or if there is an issue removing it, an error is returned. | ||
func (s *secretMonitor) RemoveSecretEventHandler(handlerRegistration SecretEventHandlerRegistration) error { |
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.
take context
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 this for future usage? Unlike AddSecretEventHandler()
where we need a context to stop the informer, I'm wondering what the context would do during removal.
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 this for future usage? Unlike
AddSecretEventHandler()
where we need a context to stop the informer, I'm wondering what the context would do during removal.
Cancellation and timeouts. I won't stick on it.
fairly minor comments. Please address and have a teammate check your test coverage. |
/assign @alebedev87 |
Signed-off-by: chiragkyal <ckyal@redhat.com>
ec1c290
to
6d47f52
Compare
/retest |
Reviewed as a cherry picked commit in #1626. /lgtm |
395d885
to
05f70ee
Compare
Signed-off-by: chiragkyal <ckyal@redhat.com>
/lgtm |
- chiragkyal | ||
approvers: | ||
- deads2k | ||
- soltysh |
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.
@soltysh your call
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.
sgtm
pkg/secret/monitor.go
Outdated
i.stopped = false | ||
i.lock.Unlock() | ||
|
||
i.informer.Run(i.stopCh) |
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.informer.Run(i.stopCh) | |
go i.informer.Run(i.stopCh) |
to avoid having your start block.
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.
It's blocking by design, the function's godoc comment states this:
It will block, so call via goroutine.
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.
Updated to make it non-blocking
Signed-off-by: chiragkyal <ckyal@redhat.com>
approvers: | ||
- deads2k | ||
- soltysh | ||
- Miciah |
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.
@Miciah, as discussed, added you also
@chiragkyal: all tests passed! Full PR test history. Your PR dashboard. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: alebedev87, chiragkyal, deads2k, Miciah The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Functionality for monitoring and handling "single" secret dynamically.
Changes in
single_item_monitor.go
:ObjectKey
representing the unique identifier for a resource.singleItemMonitor
responsible for monitoring a single resource using a SharedInformer.Changes in
secret_monitor.go
:SecretEventHandlerRegistration
for registering and unregistering event handlers for secret monitoring.SecretMonitor
for monitoring and handling specific secrets usingsingleItemMonitor
.Related: CFE-866
Implements: openshift/enhancements#1307