Skip to content

Commit

Permalink
Add health command to configure HTTP health checks
Browse files Browse the repository at this point in the history
  • Loading branch information
collimarco committed Nov 2, 2022
1 parent 132b48b commit 7fe000f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/cuber/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
require 'json'
require 'shellwords'
require 'time'
require 'uri'

module Cuber
class CLI
Expand Down
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 = {}
@health = nil
@lb = {}
@ingress = nil
@ssl = nil
Expand Down Expand Up @@ -75,6 +76,10 @@ def cron name, schedule, cmd
def env key, value, secret: false
secret ? (@secrets[key] = value) : (@env[key] = value)
end

def health url
@health = url
end

def lb key, value
@lb[key] = value
Expand Down
6 changes: 6 additions & 0 deletions lib/cuber/cuberfile_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def validate
validate_procs
validate_cron
validate_env
validate_health
validate_lb
validate_ingress
validate_ssl
Expand Down Expand Up @@ -103,6 +104,11 @@ def validate_env
@errors << "env \"#{key}\" name can only include uppercase letters, digits or underscores" if key !~ /\A[A-Z_]+[A-Z0-9_]*\z/
end
end

def validate_health
return unless @options[:health]
@errors << 'health checks must be an http url' unless URI.parse(@options[:health]).kind_of? URI::HTTP
end

def validate_lb
@options[:lb].each do |key, value|
Expand Down
7 changes: 6 additions & 1 deletion lib/cuber/templates/deployment.yml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,15 @@ spec:
value: "8080"
ports:
- containerPort: 8080
<%- end -%>
<%- if procname.to_s == 'web' && @options[:health] -%>
readinessProbe:
httpGet:
path: /
path: <%= URI.parse(@options[:health]).path.to_json %>
port: 8080
httpHeaders:
- name: Host
value: <%= URI.parse(@options[:health]).host.to_json %>
<%- end -%>
<%- if @options[:migrate] && @options[:migrate][:check] -%>
initContainers:
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.6.0'.freeze
VERSION = '1.7.0'.freeze
end

0 comments on commit 7fe000f

Please sign in to comment.