Skip to content
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

API Chunking Support #312

Merged
merged 8 commits into from
Sep 20, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,18 @@ def parse_targeted_inventory(ems, target, inventory)

def fetch_entities(client, entities)
entities.each_with_object({}) do |entity, h|
continue = nil
h[entity[:name].singularize] ||= []

begin
h[entity[:name].singularize] = client.send("get_#{entity[:name]}")
loop do
entities = client.send("get_#{entity[:name]}", :limit => refresher_options.chunk_size, :continue => continue)

h[entity[:name].singularize].concat(entities)
break if entities.last?

continue = entities.continue
end
rescue KubeException => e
raise e if entity[:default].nil?
$log.warn("Unexpected Exception during refresh: #{e}")
Expand Down
1 change: 1 addition & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
:kubernetes:
:refresh_interval: 15.minutes
:streaming_refresh: false
:chunk_size: 1_000
cben marked this conversation as resolved.
Show resolved Hide resolved
:inventory_object_refresh: true
:inventory_collections:
:saver_strategy: batch
Expand Down
2 changes: 1 addition & 1 deletion manageiq-providers-kubernetes.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Gem::Specification.new do |s|

s.add_runtime_dependency("hawkular-client", "~> 4.1")
s.add_runtime_dependency("image-inspector-client", "~> 2.0")
s.add_runtime_dependency("kubeclient", "~> 4.0")
s.add_runtime_dependency("kubeclient", "~> 4.1", ">= 4.1.1")
s.add_runtime_dependency("prometheus-alert-buffer-client", "~> 0.2.0")
s.add_runtime_dependency("prometheus-api-client", "~> 0.6")
s.add_runtime_dependency("more_core_extensions", "~> 3.6")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

describe ManageIQ::Providers::Kubernetes::ContainerManager::RefresherMixin do
let(:client) { double("client") }
let(:dummy) { (Class.new { include ManageIQ::Providers::Kubernetes::ContainerManager::RefresherMixin }).new }
cben marked this conversation as resolved.
Show resolved Hide resolved
let(:ems) { FactoryBot.create(:ems_kubernetes) }
let(:dummy) { ManageIQ::Providers::Kubernetes::ContainerManager::Refresher.new([ems]) }

context 'when an exception is thrown' do
before { allow(client).to receive(:get_pods) { raise KubeException.new(0, 'oh-no', nil) } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@
end

def full_refresh_test(expected_extra_tags: [])
VCR.use_cassette(described_class.name.underscore) do # , :record => :new_episodes) do
# VCR by default matches on :method and the whole :uri
# In this case we are sending :limit in the :query section but we
# want to simulate an older kube API that doesn't respond to that
# param. This can be done by having VCR ignore the :query component
# of the URI and return the legacy style responses.
VCR.use_cassette(described_class.name.underscore, :match_requests_on => [:method, :host, :path]) do # , :record => :new_episodes) do
cben marked this conversation as resolved.
Show resolved Hide resolved
EmsRefresh.refresh(@ems)
end
@ems.reload
Expand Down Expand Up @@ -424,15 +429,15 @@ def tag_in_category_with_description(category, description)
FactoryBot.create(:container_node, :name => "node", :ems_id => @ems.id)
end

let(:container_volumes_count) { 21 }
let(:container_volumes_count) { 68 }
let(:persintent_volumes_count) { 3 }
let(:object_counts) do
# using strings instead of actual model classes for compact rspec diffs
{
'ContainerNode' => 2, # including the fake node
'ContainerGroup' => 9,
'Container' => 9,
'ContainerService' => 12,
'ContainerGroup' => 22,
'Container' => 22,
'ContainerService' => 16,
'ContainerQuota' => 9,
'ContainerQuotaScope' => 9,
'ContainerQuotaItem' => 30,
Expand Down Expand Up @@ -588,7 +593,7 @@ def assert_specific_persistent_volume_claim
end
# ContainerVolume records don't get archived themselves, but some belong to archived pods.
expect(ContainerVolume.where(:type => 'ContainerVolume').count).to eq(container_volumes_count)
expect(@ems.container_volumes.count).to eq(container_volumes_count - 12)
expect(@ems.container_volumes.count).to eq(container_volumes_count - 18)

container0 = Container.find_by(:name => "my-container", :container_group => pod0)
container1 = Container.find_by(:name => "my-container", :container_group => pod1)
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.