From ad19aedad457078347a69d4600f42b57b4daa647 Mon Sep 17 00:00:00 2001 From: Marco Colli Date: Mon, 31 Oct 2022 21:18:22 +0100 Subject: [PATCH] Add cpu and ram options to proc (resources limits) --- lib/cuber/cuberfile_parser.rb | 4 ++-- lib/cuber/cuberfile_validator.rb | 2 ++ lib/cuber/templates/deployment.yml.erb | 12 ++++++++++++ lib/cuber/version.rb | 2 +- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/cuber/cuberfile_parser.rb b/lib/cuber/cuberfile_parser.rb index 6c33d59..02cb967 100644 --- a/lib/cuber/cuberfile_parser.rb +++ b/lib/cuber/cuberfile_parser.rb @@ -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 diff --git a/lib/cuber/cuberfile_validator.rb b/lib/cuber/cuberfile_validator.rb index cd8b2b0..cf58dd3 100644 --- a/lib/cuber/cuberfile_validator.rb +++ b/lib/cuber/cuberfile_validator.rb @@ -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/ diff --git a/lib/cuber/templates/deployment.yml.erb b/lib/cuber/templates/deployment.yml.erb index 6ad9563..f302bf8 100644 --- a/lib/cuber/templates/deployment.yml.erb +++ b/lib/cuber/templates/deployment.yml.erb @@ -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 diff --git a/lib/cuber/version.rb b/lib/cuber/version.rb index 095379e..d9cf66f 100644 --- a/lib/cuber/version.rb +++ b/lib/cuber/version.rb @@ -1,3 +1,3 @@ module Cuber - VERSION = '1.4.1'.freeze + VERSION = '1.5.0'.freeze end