Skip to content

Commit

Permalink
Add cpu and ram options to proc (resources limits)
Browse files Browse the repository at this point in the history
  • Loading branch information
collimarco committed Oct 31, 2022
1 parent 67b488b commit ad19aed
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/cuber/cuberfile_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ def migrate cmd, check: nil
@migrate = { cmd: cmd, check: check }
end

def proc name, cmd, scale: 1, term: 60, env: {}
@procs[name] = { cmd: cmd, scale: scale, term: term, env: env }
def proc name, cmd, scale: 1, cpu: nil, ram: nil, term: 60, env: {}
@procs[name] = { cmd: cmd, scale: scale, cpu: cpu, ram: ram, term: term, env: env }
end

def cron name, schedule, cmd
Expand Down
2 changes: 2 additions & 0 deletions lib/cuber/cuberfile_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ def validate_procs
@errors << "proc \"#{procname}\" name can only include lowercase letters" if procname !~ /\A[a-z]+\z/
@errors << "proc \"#{procname}\" command must be present" if proc[:cmd].to_s.strip.empty?
@errors << "proc \"#{procname}\" scale must be a positive number" unless proc[:scale].is_a?(Integer) && proc[:scale] > 0
@errors << "proc \"#{procname}\" cpu must be a positive number" unless proc[:cpu].nil? || proc[:cpu].is_a?(Numeric) && proc[:cpu] > 0
@errors << "proc \"#{procname}\" ram must be a positive number" unless proc[:ram].nil? || proc[:ram].is_a?(Numeric) && proc[:ram] > 0
@errors << "proc \"#{procname}\" term must be a positive number" unless proc[:term].is_a?(Integer) && proc[:term] > 0
proc[:env].each do |key, value|
@errors << "proc \"#{procname}\" env name can only include uppercase letters, digits or underscores" if key !~ /\A[A-Z_]+[A-Z0-9_]*\z/
Expand Down
12 changes: 12 additions & 0 deletions lib/cuber/templates/deployment.yml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,18 @@ spec:
<%- else -%>
command: <%= proc[:cmd].shellsplit %>
<%- end -%>
resources:
requests:
<%- if proc[:cpu] -%>
cpu: <%= proc[:cpu] %>
<%- end -%>
<%- if proc[:ram] -%>
memory: <%= proc[:ram] %>Gi
<%- end -%>
limits:
<%- if proc[:ram] -%>
memory: <%= proc[:ram] %>Gi
<%- end -%>
envFrom:
- configMapRef:
name: env
Expand Down
2 changes: 1 addition & 1 deletion lib/cuber/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Cuber
VERSION = '1.4.1'.freeze
VERSION = '1.5.0'.freeze
end

0 comments on commit ad19aed

Please sign in to comment.