@@ -38,6 +38,7 @@ def do_work_streaming_refresh
38
38
full_refresh
39
39
start_watch_threads
40
40
else
41
+ ensure_watch_threads
41
42
targeted_refresh
42
43
end
43
44
end
@@ -69,12 +70,6 @@ def targeted_refresh
69
70
_log . info ( "Processing #{ notices . count } Updates...Complete" )
70
71
end
71
72
72
- def save_resource_versions ( inventory )
73
- entity_types . each do |entity_type |
74
- resource_versions [ entity_type ] = inventory . collector . send ( entity_type ) . resourceVersion
75
- end
76
- end
77
-
78
73
def refresh ( collector , parser , persister )
79
74
inventory = ManageIQ ::Providers ::Kubernetes ::Inventory . new ( persister , collector , parser )
80
75
@@ -84,16 +79,35 @@ def refresh(collector, parser, persister)
84
79
inventory
85
80
end
86
81
82
+ def save_resource_versions ( inventory )
83
+ entity_types . each do |entity_type |
84
+ resource_version = inventory . collector . send ( entity_type ) . resourceVersion
85
+ next if resource_version . nil?
86
+
87
+ resource_versions [ entity_type ] = resource_version
88
+ end
89
+ end
90
+
87
91
def start_watch_threads
88
92
_log . info ( "#{ log_header } Starting watch threads..." )
89
93
90
94
entity_types . each do |entity_type |
91
- watch_threads [ entity_type ] = Thread . new { watch_thread ( entity_type ) }
95
+ watch_threads [ entity_type ] = start_watch_thread ( entity_type )
92
96
end
93
97
94
98
_log . info ( "#{ log_header } Starting watch threads...Complete" )
95
99
end
96
100
101
+ def ensure_watch_threads
102
+ entity_types . each do |entity_type |
103
+ next if watch_threads [ entity_type ] . alive?
104
+
105
+ _log . info ( "#{ log_header } Restarting #{ entity_type } watch thread" )
106
+
107
+ watch_threads [ entity_type ] = start_watch_thread ( entity_type )
108
+ end
109
+ end
110
+
97
111
def stop_watch_threads
98
112
safe_log ( "#{ log_header } Stopping watch threads..." )
99
113
@@ -103,14 +117,26 @@ def stop_watch_threads
103
117
safe_log ( "#{ log_header } Stopping watch threads...Complete" )
104
118
end
105
119
120
+ def start_watch_thread ( entity_type )
121
+ Thread . new { watch_thread ( entity_type ) }
122
+ end
123
+
106
124
def watch_thread ( entity_type )
107
125
_log . info ( "#{ log_header } #{ entity_type } watch thread started" )
108
126
109
127
resource_version = resource_versions [ entity_type ] || "0"
110
128
watch_stream = start_watch ( entity_type , resource_version )
111
129
112
- until finish . value
113
- watch_stream . each { |notice | queue . push ( notice ) }
130
+ until finished?
131
+ watch_stream . each do |notice |
132
+ # Update the collection resourceVersion to be the most recent
133
+ # object's resourceVersion so that if this watch has to be restarted
134
+ # it will pick up where it left off.
135
+ resource_version = notice . object . metadata . resourceVersion
136
+ resource_versions [ entity_type ] = resource_version
137
+
138
+ queue . push ( notice )
139
+ end
114
140
end
115
141
116
142
_log . info ( "#{ log_header } #{ entity_type } watch thread exiting" )
@@ -123,6 +149,10 @@ def start_watch(entity_type, resource_version = "0")
123
149
connection_for_entity ( entity_type ) . send ( watch_method , :resource_version => resource_version )
124
150
end
125
151
152
+ def finished?
153
+ finish . value
154
+ end
155
+
126
156
def connection_for_entity ( _entity_type )
127
157
kubernetes_connection
128
158
end
0 commit comments