Skip to content

Commit 7fe000f

Browse files
committed
Add health command to configure HTTP health checks
1 parent 132b48b commit 7fe000f

File tree

5 files changed

+19
-2
lines changed

5 files changed

+19
-2
lines changed

lib/cuber/cli.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
require 'json'
88
require 'shellwords'
99
require 'time'
10+
require 'uri'
1011

1112
module Cuber
1213
class CLI

lib/cuber/cuberfile_parser.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def initialize
1515
@cron = {}
1616
@secrets = {}
1717
@env = {}
18+
@health = nil
1819
@lb = {}
1920
@ingress = nil
2021
@ssl = nil
@@ -75,6 +76,10 @@ def cron name, schedule, cmd
7576
def env key, value, secret: false
7677
secret ? (@secrets[key] = value) : (@env[key] = value)
7778
end
79+
80+
def health url
81+
@health = url
82+
end
7883

7984
def lb key, value
8085
@lb[key] = value

lib/cuber/cuberfile_validator.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def validate
2020
validate_procs
2121
validate_cron
2222
validate_env
23+
validate_health
2324
validate_lb
2425
validate_ingress
2526
validate_ssl
@@ -103,6 +104,11 @@ def validate_env
103104
@errors << "env \"#{key}\" name can only include uppercase letters, digits or underscores" if key !~ /\A[A-Z_]+[A-Z0-9_]*\z/
104105
end
105106
end
107+
108+
def validate_health
109+
return unless @options[:health]
110+
@errors << 'health checks must be an http url' unless URI.parse(@options[:health]).kind_of? URI::HTTP
111+
end
106112

107113
def validate_lb
108114
@options[:lb].each do |key, value|

lib/cuber/templates/deployment.yml.erb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,15 @@ spec:
164164
value: "8080"
165165
ports:
166166
- containerPort: 8080
167+
<%- end -%>
168+
<%- if procname.to_s == 'web' && @options[:health] -%>
167169
readinessProbe:
168170
httpGet:
169-
path: /
171+
path: <%= URI.parse(@options[:health]).path.to_json %>
170172
port: 8080
173+
httpHeaders:
174+
- name: Host
175+
value: <%= URI.parse(@options[:health]).host.to_json %>
171176
<%- end -%>
172177
<%- if @options[:migrate] && @options[:migrate][:check] -%>
173178
initContainers:

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.6.0'.freeze
2+
VERSION = '1.7.0'.freeze
33
end

0 commit comments

Comments
 (0)