Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/kubeclient/informer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,17 @@ def fill_cache
end

def watch_to_update_cache
watcher = @client.watch_entities(@resource_name, watch: true, resource_version: @started)
@watcher = @client.watch_entities(@resource_name, watch: true, resource_version: @started)
Copy link
Collaborator

@cben cben Nov 28, 2022

Choose a reason for hiding this comment

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

Is it worth adding @watcher = nil in #initialize ? It'd be purely cosmetic, to "announce" to reader what attrs will be used. However being internal to this method, maybe actually this one is not interesting to "announce"? 🤷 Fine either way.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Similar question for @worker which is shared across 2 methods, so there I'd say worth "announcing".

stop_reason = 'disconnect'

# stop watcher without using timeout
Thread.new do
sleep(@reconcile_timeout)
stop_reason = 'reconcile'
watcher.finish
@watcher.finish
end

watcher.each do |notice|
@watcher.each do |notice|
case notice[:type]
when 'ADDED', 'MODIFIED' then @cache[cache_key(notice[:object])] = notice[:object]
when 'DELETED' then @cache.delete(cache_key(notice[:object]))
Expand Down
3 changes: 2 additions & 1 deletion test/test_informer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ def test_timeout

def with_worker
informer.start_worker
sleep(0.03) # wait for worker to watch
sleep(0.01) until informer.instance_variable_get(:@watcher) # wait for worker to watch
sleep(0.01) # give some time for threads to store
yield
ensure
informer.stop_worker
Expand Down