Skip to content

Commit

Permalink
Parse and save quota scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
cben committed Dec 19, 2017
1 parent 3345798 commit 29ef338
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ def initialize_inventory_collections
:attributes_blacklist => [:namespace],
)
)
@collections[:container_quota_scopes] = ::ManagerRefresh::InventoryCollection.new(
shared_options.merge(
:model_class => ContainerQuotaScope,
:parent => manager,
:association => :container_quota_scopes,
:manager_ref => [:container_quota, :scope],
)
)
@collections[:container_quota_items] = ::ManagerRefresh::InventoryCollection.new(
shared_options.merge(
:model_class => ContainerQuotaItem,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,17 +320,25 @@ def get_resource_quotas_graph(inv)

h[:container_project] = lazy_find_project(:name => h[:namespace])

scopes = h.delete(:container_quota_scopes)
items = h.delete(:container_quota_items)
get_container_quota_items_graph(h, items)
container_quota = collection.build(h)

collection.build(h)
get_container_quota_scopes_graphs(container_quota, scopes)
get_container_quota_items_graph(container_quota, items)
end
end

def get_container_quota_scopes_graphs(parent, hashes)
hashes.each do |hash|
hash[:container_quota] = parent
@inv_collections[:container_quota_scopes].build(hash)
end
end

def get_container_quota_items_graph(parent, hashes)
container_quota = @inv_collections[:container_quotas].lazy_find(parent[:ems_ref])
hashes.each do |hash|
hash[:container_quota] = container_quota
hash[:container_quota] = parent
@inv_collections[:container_quota_items].build(hash)
end
end
Expand Down Expand Up @@ -910,7 +918,8 @@ def parse_persistent_volume_claim(claim)

def parse_resource_quota(resource_quota)
new_result = parse_base_item(resource_quota)
new_result[:container_quota_items] = parse_resource_quota_items resource_quota
new_result[:container_quota_scopes] = resource_quota.spec.scopes.to_a.collect { |scope| {:scope => scope} }
new_result[:container_quota_items] = parse_resource_quota_items(resource_quota)
new_result
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,11 +438,15 @@
:creationTimestamp => '2015-08-17T09:16:46Z',
},
:spec => {
:hard => {
:hard => {
:cpu => '30',
:pods => '100',
:memory => '10M'
}
},
:scopes => [
"Terminating",
"NotBestEffort"
]
},
:status => {
:hard => {
Expand All @@ -457,12 +461,20 @@
}
}
)
)).to eq(:name => 'test-quota',
:ems_ref => 'af3d1a10-44c0-11e5-b186-0aaeec44370e',
:ems_created_on => '2015-08-17T09:16:46Z',
:resource_version => '165339',
:namespace => 'test-namespace',
:container_quota_items => [
)).to eq(:name => 'test-quota',
:ems_ref => 'af3d1a10-44c0-11e5-b186-0aaeec44370e',
:ems_created_on => '2015-08-17T09:16:46Z',
:resource_version => '165339',
:namespace => 'test-namespace',
:container_quota_scopes => [
{
:scope => "Terminating"
},
{
:scope => "NotBestEffort"
}
],
:container_quota_items => [
{
:resource => "cpu",
:quota_desired => 30,
Expand Down Expand Up @@ -497,12 +509,13 @@
},
:spec => {},
:status => {})))
.to eq(:name => 'test-quota',
:ems_ref => 'af3d1a10-44c0-11e5-b186-0aaeec44370e',
:ems_created_on => '2015-08-17T09:16:46Z',
:resource_version => '165339',
:namespace => 'test-namespace',
:container_quota_items => [])
.to eq(:name => 'test-quota',
:ems_ref => 'af3d1a10-44c0-11e5-b186-0aaeec44370e',
:ems_created_on => '2015-08-17T09:16:46Z',
:resource_version => '165339',
:namespace => 'test-namespace',
:container_quota_scopes => [],
:container_quota_items => [])
end

it "handles quotas with no status" do
Expand All @@ -519,12 +532,13 @@
:cpu => '30'
}},
:status => {})))
.to eq(:name => 'test-quota',
:ems_ref => 'af3d1a10-44c0-11e5-b186-0aaeec44370e',
:ems_created_on => '2015-08-17T09:16:46Z',
:resource_version => '165339',
:namespace => 'test-namespace',
:container_quota_items => [
.to eq(:name => 'test-quota',
:ems_ref => 'af3d1a10-44c0-11e5-b186-0aaeec44370e',
:ems_created_on => '2015-08-17T09:16:46Z',
:resource_version => '165339',
:namespace => 'test-namespace',
:container_quota_scopes => [],
:container_quota_items => [
{
:resource => "cpu",
:quota_desired => 30,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,8 @@ def assert_specific_container_project

def assert_specific_container_quota
container_quota = ContainerQuota.find_by(:name => "quota")
container_quota.ems_created_on.kind_of?(ActiveSupport::TimeWithZone)
expect(container_quota.ems_created_on).to be_a(ActiveSupport::TimeWithZone)
expect(container_quota.container_quota_scopes.count).to eq(0)
expect(container_quota.container_quota_items.count).to eq(8)
cpu_quota = container_quota.container_quota_items.select { |x| x[:resource] == 'cpu' }[0]
expect(cpu_quota).to have_attributes(
Expand Down

0 comments on commit 29ef338

Please sign in to comment.