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

collect container definition limits #22

Merged
merged 1 commit into from
Jul 30, 2017

Conversation

zeari
Copy link

@zeari zeari commented May 22, 2017

Depends on and completes ManageIQ/manageiq#15180
More info: https://kubernetes.io/docs/tasks/administer-cluster/cpu-memory-limit/

~$ oc describe pod nginx-1-deploy
Name:			nginx-1-deploy
Namespace:		aris-project
Security Policy:	restricted
Node:			---
Start Time:		Sun, 21 May 2017 12:18:34 +0300
Containers:
  deployment:
...
    Limits:      <-------------------------------------
      cpu:	300m
      memory:	200Mi
    Requests:
      cpu:		200m
      memory:		100Mi
    State:		Terminated
      Reason:		Error
      Exit Code:	1
      Started:		Sun, 21 May 2017 12:18:40 +0300
 ...

@simon3z @cben @moolitayer

@zeari zeari force-pushed the get_anon_limits branch from 704418f to 0304e7f Compare May 22, 2017 13:51
@@ -643,6 +643,15 @@ def parse_container_definition(container_def, pod_id)
parse_container_env_var(env_var)
end

limits_hash = container_def.try(:resources).try(:limits).to_h
new_result[:container_limit_items] = limits_hash.to_h.collect do |resource, value|
Copy link
Contributor

@cben cben May 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redundant .to_h, already did it in line above

@simon3z simon3z self-assigned this May 24, 2017
@zeari zeari force-pushed the get_anon_limits branch from 0304e7f to b870dfc Compare May 25, 2017 08:12
@zeari zeari changed the title collect container defninition limits collect container definition limits May 25, 2017
@zeari zeari force-pushed the get_anon_limits branch 4 times, most recently from b202f81 to 25b7caf Compare May 28, 2017 11:53
BINARY_SUFFICES = ["Ki", "Mi", "Gi", "Ti", "Pi", "Ei"].freeze
SI_SUFFICES = ["K", "M", "G", "T", "P", "E"].freeze

def parse_quantity(resource) # convert to bytes\cores
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zeari can't we use iec_60027_2_to_i as for the capacity fields?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@simon3z we can but just for Ki,Mi,Gi...
i can try to get this code into https://github.com/ManageIQ/more_core_extensions instead

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zeari yes let's extend that or anyway implement it in more_core_extensions

@@ -646,6 +650,28 @@ def parse_container_definition(container_def, pod_id)
new_result
end

BINARY_SUFFICES = ["Ki", "Mi", "Gi", "Ti", "Pi", "Ei"].freeze
SI_SUFFICES = ["K", "M", "G", "T", "P", "E"].freeze
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zeari s/SUFFICES/SUFFIXES/ and I think we're missing m (which is different from M) and k is lowercase. Anyway check the quantity.go file.

@zeari zeari force-pushed the get_anon_limits branch 5 times, most recently from 7224621 to c82bc10 Compare June 19, 2017 13:18
@@ -646,6 +655,19 @@ def parse_container_definition(container_def, pod_id)
new_result
end

BINARY_SUFFIXES = ["Ki", "Mi", "Gi", "Ti", "Pi", "Ei"].freeze
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zeari this is spreading the internals of iec_60027_2_to_i. What if iec_60027_2_to_i will add a new suffix?

What if you try to parse iec_60027_2_to_i and on ArgumentError you fallback to decimal_si_to_f?

Or anyway anything that keeps the logic in the iec_60027_2_to_i module. E.g. adding a is_60027_2?
(Now that I think of it this second option seems nicer than the ArgumentError)


# covert to milicores
new_result[:limit_cpu] = (new_result[:limit_cpu] * 1000).to_i unless new_result[:limit_cpu].nil?
new_result[:request_cpu] = (new_result[:request_cpu] * 1000).to_i unless new_result[:request_cpu].nil?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zeari if we parse this with iec_60027_2_to_i which is using floats we won't recover the rounding by multiplying by 1000.

Either we do the entire parsing in integers or we may as well keep these in floats.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i guess youre correct but are we expecting cpu to appear in binary form? thats seems weird to me. '1Mi' cores?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Limits are user-supplied, right?
If user is allowed to write 1Ki, somebody will :-), and we should support it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so we can make a float version (iec_60027_2_to_f) in core_extensions if thats what we want to do there. We can instead add a 'target units' option where we can choose in which units we want the result to be. for example "1.1111Mi".iec_60027_2_to_f("m") would give us the result in milicores(milianything).

@zeari zeari force-pushed the get_anon_limits branch 4 times, most recently from 032ed97 to e3c644c Compare June 22, 2017 14:08
@simon3z
Copy link
Contributor

simon3z commented Jul 8, 2017

LGTM 👍 waiting for the schema ManageIQ/manageiq-schema#25 to get merged.

@zeari zeari force-pushed the get_anon_limits branch from e3c644c to b598b86 Compare July 17, 2017 14:19
@simon3z simon3z closed this Jul 18, 2017
@simon3z simon3z reopened this Jul 18, 2017
:privileged => container_def.securityContext.try(:privileged),
:run_as_user => container_def.securityContext.try(:runAsUser),
:run_as_non_root => container_def.securityContext.try(:runAsNonRoot),
:security_context => parse_security_context(container_def.securityContext),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zeari let's not make this dependent on the container definition removal.

If you just add the limit/request_cpu_cores and limit/request_memory_bytes then we can merge now.

@cben
Copy link
Contributor

cben commented Jul 18, 2017

close-cycling is unlikely to help, Travis fails on bin/setup due to ManageIQ/manageiq#15585 (comment)

@zeari
Copy link
Author

zeari commented Jul 18, 2017

Also, we need a new more_core_extensions that would have decimal_si_to_f ManageIQ/more_core_extensions#43 (comment)

@miq-bot
Copy link
Member

miq-bot commented Jul 26, 2017

This pull request is not mergeable. Please rebase and repush.

@zeari
Copy link
Author

zeari commented Jul 27, 2017

more_core_extensions was updated which makes the tests green :)

@zeari zeari force-pushed the get_anon_limits branch from 5481e7e to 5eb7818 Compare July 27, 2017 11:51
@cben
Copy link
Contributor

cben commented Jul 27, 2017

LGTM but can you add a test?

@zeari zeari force-pushed the get_anon_limits branch from 5eb7818 to e2ddbf6 Compare July 30, 2017 13:07
@zeari
Copy link
Author

zeari commented Jul 30, 2017

LGTM but can you add a test?

Added a test for parse_quantity + parse_container_spec

@miq-bot
Copy link
Member

miq-bot commented Jul 30, 2017

Checked commit zeari@e2ddbf6 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
2 files checked, 0 offenses detected
Everything looks fine. 🍰

Copy link

@moolitayer moolitayer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@moolitayer moolitayer merged commit 0c4e816 into ManageIQ:master Jul 30, 2017
@moolitayer moolitayer added this to the Sprint 66 Ending Aug 7, 2017 milestone Aug 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants