Skip to content

nfd-worker: Watch features.d changes #2156

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ozhuraki
Copy link
Contributor

Closes: #2075

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label May 12, 2025
Copy link

netlify bot commented May 12, 2025

Deploy Preview for kubernetes-sigs-nfd ready!

Name Link
🔨 Latest commit b3b1c64
🔍 Latest deploy log https://app.netlify.com/projects/kubernetes-sigs-nfd/deploys/682f27651fa7c800085bdff6
😎 Deploy Preview https://deploy-preview-2156--kubernetes-sigs-nfd.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: ozhuraki
Once this PR has been reviewed and has the lgtm label, please assign marquiz for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label May 12, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @ozhuraki. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label May 12, 2025
Copy link
Contributor

@marquiz marquiz left a comment

Choose a reason for hiding this comment

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

Thanks @ozhuraki for taking a stab at this.

I think we should refactor the code and re-architecture this more to make the code more maintainable. There might be other sources we'd also make react to events in a similar way. Basically, it should be the source (source/local in this case) which should be able to notify the main event loop that features have been updated. Also, no need to run re-discovery of all features.

@ozhuraki
Copy link
Contributor Author

@marquiz

Thanks, makes sense. I will move this into source/local.

Signed-off-by: Oleg Zhurakivskyy <[email protected]>
@ozhuraki
Copy link
Contributor Author

@marquiz

Moved into source/local, please take a look

@ArangoGutierrez ArangoGutierrez requested a review from Copilot May 28, 2025 05:58
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Adds file system watching for changes under the features.d directory so that nfd-worker can re-run feature discovery on create/write/remove/rename/chmod events.

  • Introduces a global FSWatcher and watch() function in local.go to set up an fsnotify watcher.
  • Switches the local source import to non-blank in nfd-worker.go and hooks its FSWatcher into the worker's Run() loop.
  • Adds new struct fields for the watcher in nfd-worker.go.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
source/local/local.go Add fsnotify import, global FSWatcher, and watch() setup logic
pkg/nfd-worker/nfd-worker.go Import local package, add watcher fields, and handle fsnotify events in the run loop
Comments suppressed due to low confidence (2)

source/local/local.go:67

  • Exporting FSWatcher as a global var makes it part of the package API unintentionally. Consider making it unexported (fsWatcher) or encapsulating it within your localSource struct.
FSWatcher       *fsnotify.Watcher

source/local/local.go:131

  • The new watcher initialization logic in Discover() isn’t covered by tests. Consider adding a unit or integration test to verify that watch() is called and that FSWatcher is set.
if FSWatcher == nil {

@@ -318,6 +327,30 @@ func getFileContent(fileName string) ([][]byte, error) {
return lines, nil
}

func watch(s *localSource) error {
Copy link
Preview

Copilot AI May 28, 2025

Choose a reason for hiding this comment

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

The parameter s is never used in watch(). Remove it to avoid unused-parameter warnings and clarify the function's intent.

Suggested change
func watch(s *localSource) error {
func watch() error {

Copilot uses AI. Check for mistakes.

@@ -121,6 +122,8 @@ type nfdWorker struct {
k8sClient k8sclient.Interface
nfdClient nfdclient.Interface
stop chan struct{} // channel for signaling stop
fsEvent chan fsnotify.Event
Copy link
Preview

Copilot AI May 28, 2025

Choose a reason for hiding this comment

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

The struct field fsEvent is declared but never used. Remove it or wire it into the select loop to avoid dead code.

Copilot uses AI. Check for mistakes.

@@ -341,6 +351,13 @@ func (w *nfdWorker) Run() error {
return err
}

case event := <-w.fsWatcher.Events:
Copy link
Preview

Copilot AI May 28, 2025

Choose a reason for hiding this comment

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

Errors from the watcher (w.fsWatcher.Errors) are not handled. It's recommended to add a case to log or handle w.fsWatcher.Errors to avoid silent failures.

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Watch features.d changes
3 participants