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

CFE-866: feature: monitoring and handling "single" secret dynamically #1675

Merged

Conversation

chiragkyal
Copy link
Member

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.
  • Defined methods for starting and stopping informers, adding and removing event handlers, and retrieving items from the informer's cache.

Changes in secret_monitor.go:

  • Implemented functionalities to create and manage informers for specific secrets.
  • SecretEventHandlerRegistration for registering and unregistering event handlers for secret monitoring.
  • SecretMonitor for monitoring and handling specific secrets using singleItemMonitor.
  • Added methods for adding and removing secret event handlers, retrieving secret objects from the informer's cache.
  • operations for counting the number of event handlers associated with a secret.

Related: CFE-866
Implements: openshift/enhancements#1307

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Feb 6, 2024
@openshift-ci-robot
Copy link

openshift-ci-robot commented Feb 6, 2024

@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:

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.
  • Defined methods for starting and stopping informers, adding and removing event handlers, and retrieving items from the informer's cache.

Changes in secret_monitor.go:

  • Implemented functionalities to create and manage informers for specific secrets.
  • SecretEventHandlerRegistration for registering and unregistering event handlers for secret monitoring.
  • SecretMonitor for monitoring and handling specific secrets using singleItemMonitor.
  • Added methods for adding and removing secret event handlers, retrieving secret objects from the informer's cache.
  • operations for counting the number of event handlers associated with a secret.

Related: CFE-866
Implements: openshift/enhancements#1307

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.

@chiragkyal
Copy link
Member Author

/assign @deads2k

pkg/secret/monitor.go Outdated Show resolved Hide resolved
case <-ctx.Done():
klog.Info("stopping informer due to context cancellation")
if !i.StopInformer() {
klog.Error("failed to stop informer")
Copy link
Contributor

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.

Copy link
Member Author

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.


klog.Info("starting informer")
i.stopped = false
i.lock.Unlock()
Copy link
Contributor

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.

Copy link
Member Author

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)

Copy link
Contributor

@deads2k deads2k Apr 24, 2024

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)

that line below looks bugged. I explicitly (instead of implicitly) commented this time.

Copy link
Member Author

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

}

// StartInformer starts and runs the informer util the provided context is canceled,
// or StopInformer() is called. It will block, so call via goroutine.
Copy link
Contributor

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?

Copy link
Member Author

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()?

Copy link
Contributor

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()?

How about making it non-blocking?

Copy link
Member Author

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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

take context

Copy link
Member Author

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.

Copy link
Contributor

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.

@deads2k
Copy link
Contributor

deads2k commented Feb 9, 2024

fairly minor comments. Please address and have a teammate check your test coverage.

@chiragkyal
Copy link
Member Author

/assign @alebedev87
FYI: this PR was split from #1626 to have only the secret monitoring piece.

Signed-off-by: chiragkyal <ckyal@redhat.com>
@chiragkyal
Copy link
Member Author

/retest

@alebedev87
Copy link

Reviewed as a cherry picked commit in #1626.

/lgtm
/approve

@openshift-ci openshift-ci bot added lgtm Indicates that a PR is ready to be merged. do-not-merge/invalid-owners-file Indicates that a PR should not merge because it has an invalid OWNERS file in it. and removed lgtm Indicates that a PR is ready to be merged. labels Apr 19, 2024
@openshift-ci openshift-ci bot removed the do-not-merge/invalid-owners-file Indicates that a PR should not merge because it has an invalid OWNERS file in it. label Apr 19, 2024
Signed-off-by: chiragkyal <ckyal@redhat.com>
@Miciah
Copy link
Contributor

Miciah commented Apr 22, 2024

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Apr 22, 2024
- chiragkyal
approvers:
- deads2k
- soltysh
Copy link
Contributor

Choose a reason for hiding this comment

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

@soltysh your call

Copy link
Member

Choose a reason for hiding this comment

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

sgtm

i.stopped = false
i.lock.Unlock()

i.informer.Run(i.stopCh)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
i.informer.Run(i.stopCh)
go i.informer.Run(i.stopCh)

to avoid having your start block.

Copy link

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.

Copy link
Member Author

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

@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Apr 25, 2024
Signed-off-by: chiragkyal <ckyal@redhat.com>
approvers:
- deads2k
- soltysh
- Miciah
Copy link
Member Author

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

Copy link
Contributor

openshift-ci bot commented Apr 25, 2024

@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.

@deads2k
Copy link
Contributor

deads2k commented Apr 25, 2024

/lgtm
/approve

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Apr 25, 2024
Copy link
Contributor

openshift-ci bot commented Apr 25, 2024

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 25, 2024
@openshift-merge-bot openshift-merge-bot bot merged commit 8471efc into openshift:master Apr 25, 2024
4 checks passed
@chiragkyal chiragkyal deleted the feature/single-item-monitor branch April 25, 2024 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants