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

Allows to define hostAliases for all pods #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/cuber/cuberfile_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def initialize
@cron = {}
@secrets = {}
@env = {}
@hostaliases = {}
@lb = {}
@ingress = nil
@ssl = nil
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions lib/cuber/cuberfile_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
30 changes: 30 additions & 0 deletions lib/cuber/templates/deployment.yml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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] %>
Expand Down Expand Up @@ -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] %>
Expand Down Expand Up @@ -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] %>
Expand Down
10 changes: 10 additions & 0 deletions lib/cuber/templates/pod.yml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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] %>
Expand Down