Skip to content

Commit ad19aed

Browse files
committed
Add cpu and ram options to proc (resources limits)
1 parent 67b488b commit ad19aed

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

lib/cuber/cuberfile_parser.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ def migrate cmd, check: nil
6464
@migrate = { cmd: cmd, check: check }
6565
end
6666

67-
def proc name, cmd, scale: 1, term: 60, env: {}
68-
@procs[name] = { cmd: cmd, scale: scale, term: term, env: env }
67+
def proc name, cmd, scale: 1, cpu: nil, ram: nil, term: 60, env: {}
68+
@procs[name] = { cmd: cmd, scale: scale, cpu: cpu, ram: ram, term: term, env: env }
6969
end
7070

7171
def cron name, schedule, cmd

lib/cuber/cuberfile_validator.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ def validate_procs
8181
@errors << "proc \"#{procname}\" name can only include lowercase letters" if procname !~ /\A[a-z]+\z/
8282
@errors << "proc \"#{procname}\" command must be present" if proc[:cmd].to_s.strip.empty?
8383
@errors << "proc \"#{procname}\" scale must be a positive number" unless proc[:scale].is_a?(Integer) && proc[:scale] > 0
84+
@errors << "proc \"#{procname}\" cpu must be a positive number" unless proc[:cpu].nil? || proc[:cpu].is_a?(Numeric) && proc[:cpu] > 0
85+
@errors << "proc \"#{procname}\" ram must be a positive number" unless proc[:ram].nil? || proc[:ram].is_a?(Numeric) && proc[:ram] > 0
8486
@errors << "proc \"#{procname}\" term must be a positive number" unless proc[:term].is_a?(Integer) && proc[:term] > 0
8587
proc[:env].each do |key, value|
8688
@errors << "proc \"#{procname}\" env name can only include uppercase letters, digits or underscores" if key !~ /\A[A-Z_]+[A-Z0-9_]*\z/

lib/cuber/templates/deployment.yml.erb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,18 @@ spec:
137137
<%- else -%>
138138
command: <%= proc[:cmd].shellsplit %>
139139
<%- end -%>
140+
resources:
141+
requests:
142+
<%- if proc[:cpu] -%>
143+
cpu: <%= proc[:cpu] %>
144+
<%- end -%>
145+
<%- if proc[:ram] -%>
146+
memory: <%= proc[:ram] %>Gi
147+
<%- end -%>
148+
limits:
149+
<%- if proc[:ram] -%>
150+
memory: <%= proc[:ram] %>Gi
151+
<%- end -%>
140152
envFrom:
141153
- configMapRef:
142154
name: env

lib/cuber/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Cuber
2-
VERSION = '1.4.1'.freeze
2+
VERSION = '1.5.0'.freeze
33
end

0 commit comments

Comments
 (0)