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

Convert Container quotas to numeric values #15639

Merged
merged 1 commit into from
Oct 2, 2017
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
22 changes: 22 additions & 0 deletions app/models/container_quota_item.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
class ContainerQuotaItem < ApplicationRecord
belongs_to :container_quota

virtual_column :quota_desired_display, :type => :string
virtual_column :quota_enforced_display, :type => :string
virtual_column :quota_observed_display, :type => :string

def quota_desired_display
quota_display(quota_desired)
end

def quota_enforced_display
quota_display(quota_enforced)
end

def quota_observed_display
quota_display(quota_observed)
end

private

def quota_display(quota)
(quota % 1).zero? ? quota.to_i.to_s : quota.to_s
end
end
23 changes: 23 additions & 0 deletions spec/models/container_quota_item_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
describe ContainerQuotaItem do
it "converts float to string" do
quota_item = ContainerQuotaItem.new(:resource => 'cpu',
:quota_desired => 4.2,
:quota_enforced => 1.99,
:quota_observed => 0.01)

expect(quota_item).to have_attributes(:quota_desired_display => '4.2',
:quota_enforced_display => '1.99',
:quota_observed_display => '0.01')
end

it "rounds float to int" do
quota_item = ContainerQuotaItem.new(:resource => 'pods',
:quota_desired => 42.0,
:quota_enforced => 1.0,
:quota_observed => 0.0)

expect(quota_item).to have_attributes(:quota_desired_display => '42',
:quota_enforced_display => '1',
:quota_observed_display => '0')
end
end