diff --git a/lib/cuber/cuberfile_parser.rb b/lib/cuber/cuberfile_parser.rb index 3b5c54e..a684c13 100644 --- a/lib/cuber/cuberfile_parser.rb +++ b/lib/cuber/cuberfile_parser.rb @@ -15,6 +15,7 @@ def initialize @cron = {} @secrets = {} @env = {} + @hostaliases = {} @lb = {} @ingress = nil @ssl = nil @@ -76,6 +77,10 @@ def env key, value, secret: false secret ? (@secrets[key] = value) : (@env[key] = value) end + def hostalias ip, hostnames: [] + @hostaliases[ip] = hostnames + end + def lb key, value @lb[key] = value end diff --git a/lib/cuber/cuberfile_validator.rb b/lib/cuber/cuberfile_validator.rb index 959ec5e..703ff9f 100644 --- a/lib/cuber/cuberfile_validator.rb +++ b/lib/cuber/cuberfile_validator.rb @@ -103,6 +103,16 @@ def validate_env end end + def validate_hostalias + @options[:hostaliases].each do |ip, hostnames| + @errors << "hostalias \"#{ip}\" must be a valid ip address" if ip !~ /\A\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\z/ + @errors << "hostalias \"#{ip}\" must define at least one hostname" if hostnames.empty? + hostnames.each do |hostname| + @errors << "hostalias \"#{ip}\" hostname \"#{hostname}\" can only include lowercase letters, digits, dots or dashes" if hostname !~ /\A[a-z0-9\-\.]+\z/ + end + end + end + def validate_lb @options[:lb].each do |key, value| @errors << "lb \"#{key}\" key can only include letters, digits, underscores, dashes, dots or slash" if key !~ /\A[a-zA-Z0-9_\-\.\/]+\z/ diff --git a/lib/cuber/templates/deployment.yml.erb b/lib/cuber/templates/deployment.yml.erb index c53b79a..272e60b 100644 --- a/lib/cuber/templates/deployment.yml.erb +++ b/lib/cuber/templates/deployment.yml.erb @@ -80,6 +80,16 @@ spec: app.kubernetes.io/version: <%= @options[:release] %> app.kubernetes.io/managed-by: cuber spec: + <%- if @options[:hostaliases].any? -%> + hostAliases: + <%- @options[:hostaliases].each do |ip, hostnames| -%> + - ip: "<%= ip %>" + hostnames: + <%- hostnames.each do |hostname| -%> + - "<%= hostname %>" + <%- end -%> + <%- end -%> + <%- end -%> containers: - name: migration image: <%= @options[:image] %>:<%= @options[:release] %> @@ -127,6 +137,16 @@ spec: app.kubernetes.io/managed-by: cuber app: <%= procname %>-proc spec: + <%- if @options[:hostaliases].any? -%> + hostAliases: + <%- @options[:hostaliases].each do |ip, hostnames| -%> + - ip: "<%= ip %>" + hostnames: + <%- hostnames.each do |hostname| -%> + - "<%= hostname %>" + <%- end -%> + <%- end -%> + <%- end -%> containers: - name: <%= procname %>-proc image: <%= @options[:image] %>:<%= @options[:release] %> @@ -212,6 +232,16 @@ spec: app.kubernetes.io/version: <%= @options[:release] %> app.kubernetes.io/managed-by: cuber spec: + <%- if @options[:hostaliases].any? -%> + hostAliases: + <%- @options[:hostaliases].each do |ip, hostnames| -%> + - ip: "<%= ip %>" + hostnames: + <%- hostnames.each do |hostname| -%> + - "<%= hostname %>" + <%- end -%> + <%- end -%> + <%- end -%> containers: - name: task image: <%= @options[:image] %>:<%= @options[:release] %> diff --git a/lib/cuber/templates/pod.yml.erb b/lib/cuber/templates/pod.yml.erb index e591518..4ffe6b1 100644 --- a/lib/cuber/templates/pod.yml.erb +++ b/lib/cuber/templates/pod.yml.erb @@ -8,6 +8,16 @@ metadata: app.kubernetes.io/version: <%= @options[:release] %> app.kubernetes.io/managed-by: cuber spec: + <%- if @options[:hostaliases].any? -%> + hostAliases: + <%- @options[:hostaliases].each do |ip, hostnames| -%> + - ip: "<%= ip %>" + hostnames: + <%- hostnames.each do |hostname| -%> + - "<%= hostname %>" + <%- end -%> + <%- end -%> + <%- end -%> containers: - name: pod-proc image: <%= @options[:image] %>:<%= @options[:release] %>