Skip to content

Commit

Permalink
docs for resourceVersion (#258)
Browse files Browse the repository at this point in the history
  • Loading branch information
grosser committed Oct 8, 2020
1 parent f65617d commit 84f66a8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/fluent/plugin/kubernetes_metadata_watch_namespaces.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# TODO: this is mostly copy-paste from kubernetes_metadata_watch_pods.rb unify them
require_relative 'kubernetes_metadata_common'

module KubernetesMetadata
Expand Down Expand Up @@ -89,15 +90,18 @@ def start_namespace_watch
# starting from that resourceVersion.
def get_namespaces_and_start_watcher
options = {
resource_version: '0' # Fetch from API server.
resource_version: '0' # Fetch from API server cache instead of etcd quorum read
}
namespaces = @client.get_namespaces(options)
namespaces[:items].each do |namespace|
cache_key = namespace[:metadata][:uid]
@namespace_cache[cache_key] = parse_namespace_metadata(namespace)
@stats.bump(:namespace_cache_host_updates)
end

# continue watching from most recent resourceVersion
options[:resource_version] = namespaces[:metadata][:resourceVersion]

@client.watch_namespaces(options)
end

Expand Down
5 changes: 4 additions & 1 deletion lib/fluent/plugin/kubernetes_metadata_watch_pods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# TODO: this is mostly copy-paste from kubernetes_metadata_watch_namespaces.rb unify them
require_relative 'kubernetes_metadata_common'

module KubernetesMetadata
Expand Down Expand Up @@ -91,7 +92,7 @@ def start_pod_watch
# from that resourceVersion.
def get_pods_and_start_watcher
options = {
resource_version: '0' # Fetch from API server.
resource_version: '0' # Fetch from API server cache instead of etcd quorum read
}
if ENV['K8S_NODE_NAME']
options[:field_selector] = 'spec.nodeName=' + ENV['K8S_NODE_NAME']
Expand All @@ -105,6 +106,8 @@ def get_pods_and_start_watcher
@cache[cache_key] = parse_pod_metadata(pod)
@stats.bump(:pod_cache_host_updates)
end

# continue watching from most recent resourceVersion
options[:resource_version] = pods[:metadata][:resourceVersion]
end
@client.watch_pods(options)
Expand Down

0 comments on commit 84f66a8

Please sign in to comment.