Skip to content

Commit

Permalink
nfd-updater: events: enable timer-only flow
Browse files Browse the repository at this point in the history
By default the nfd-topology-updater has state-directories
notification enabled by default. In theory, we can have only
timer-based updates, but if the option is given to disable the
state-directories event source, then all the update mechanism
is mistakenly disabled, including the timer-based updates.

The two updaters mechanism should be decoupled.
So this PR changes this to make sure we can enable just and only
the timer-based updates.

Signed-off-by: Francesco Romani <[email protected]>
  • Loading branch information
ffromani committed Sep 1, 2023
1 parent 48f3707 commit c41df1f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
17 changes: 12 additions & 5 deletions pkg/nfd-topology-updater/kubeletnotifier/kubeletnotifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,14 @@ type Info struct {
}

func New(sleepInterval time.Duration, dest chan<- Info, kubeletStateDir string) (*Notifier, error) {
devicePluginsDir := path.Join(kubeletStateDir, devicePluginsDirName)
ch, err := createFSWatcherEvent([]string{kubeletStateDir, devicePluginsDir})
if err != nil {
return nil, err
if kubeletStateDir != "" {
devicePluginsDir := path.Join(kubeletStateDir, devicePluginsDirName)
ch, err := createFSWatcherEvent([]string{kubeletStateDir, devicePluginsDir})
if err != nil {
return nil, err
}
}

return &Notifier{
sleepInterval: sleepInterval,
dest: dest,
Expand All @@ -67,13 +70,17 @@ func New(sleepInterval time.Duration, dest chan<- Info, kubeletStateDir string)
}

func (n *Notifier) Run() {
timeEvents := make(<-chan time.Time)
var timeEvents <-chan time.Time

if n.sleepInterval > 0 {
ticker := time.NewTicker(n.sleepInterval)
defer ticker.Stop()
timeEvents = ticker.C
}

// it's safe to keep the channels we don't need nil:
// https://dave.cheney.net/2014/03/19/channel-axioms
// "A receive from a nil channel blocks forever"
for {
select {
case <-timeEvents:
Expand Down
11 changes: 5 additions & 6 deletions pkg/nfd-topology-updater/nfd-topology-updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,12 @@ type nfdTopologyUpdater struct {
// NewTopologyUpdater creates a new NfdTopologyUpdater instance.
func NewTopologyUpdater(args Args, resourcemonitorArgs resourcemonitor.Args) (NfdTopologyUpdater, error) {
eventSource := make(chan kubeletnotifier.Info)
if args.KubeletStateDir != "" {
ntf, err := kubeletnotifier.New(resourcemonitorArgs.SleepInterval, eventSource, args.KubeletStateDir)
if err != nil {
return nil, err
}
go ntf.Run()

ntf, err := kubeletnotifier.New(resourcemonitorArgs.SleepInterval, eventSource, args.KubeletStateDir)
if err != nil {
return nil, err
}
go ntf.Run()

kubeletConfigFunc, err := getKubeletConfigFunc(resourcemonitorArgs.KubeletConfigURI, resourcemonitorArgs.APIAuthTokenFile)
if err != nil {
Expand Down

0 comments on commit c41df1f

Please sign in to comment.