vidar 0.3.0 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/lib/vidar.rb +1 -0
- data/lib/vidar/cli.rb +12 -19
- data/lib/vidar/config.rb +8 -10
- data/lib/vidar/deploy_status.rb +34 -0
- data/lib/vidar/k8s/pods.rb +1 -3
- data/lib/vidar/slack_notification.rb +27 -11
- data/lib/vidar/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 105e2f348c313725b7a92f6ce260aea96c34a99c4aeeb1027a07b309d1d4448d
|
4
|
+
data.tar.gz: ca750b51ab3e4d8d25f2fc27a742909c3de858f622ffd99354af0a83f58ffc49
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1da1774c90625da8378f25182897c76cb91a5cb7e61663d9fab87ac124892cb476f8e772ebcd9af6a290a187606e37f9af16c75b313ddcd525de2d9ff42349b
|
7
|
+
data.tar.gz: 3332d5453505935187240eaef57c5191f208cb6c057dbce400b6330cc0ee07f4b0a1ce876c225fd3ae821c5d2f2fe49bbd3eb75d4555d1a598974f0cfe845937
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
vidar (0.3.
|
4
|
+
vidar (0.3.2)
|
5
5
|
colorize
|
6
6
|
faraday
|
7
7
|
thor (~> 0.20)
|
@@ -13,7 +13,7 @@ GEM
|
|
13
13
|
coderay (1.1.2)
|
14
14
|
colorize (0.8.1)
|
15
15
|
diff-lcs (1.3)
|
16
|
-
faraday (0.
|
16
|
+
faraday (0.16.2)
|
17
17
|
multipart-post (>= 1.2, < 3)
|
18
18
|
jaro_winkler (1.5.3)
|
19
19
|
method_source (0.9.2)
|
data/lib/vidar.rb
CHANGED
data/lib/vidar/cli.rb
CHANGED
@@ -94,39 +94,32 @@ module Vidar
|
|
94
94
|
end
|
95
95
|
|
96
96
|
desc "monitor_deploy_status", "Checks is deployment has finished and sends post-deploy notification"
|
97
|
+
method_option :success_color, required: false
|
98
|
+
method_option :error_color, required: false
|
97
99
|
def monitor_deploy_status
|
98
100
|
Log.info "Current cluster_name: #{Config.get!(:cluster_name)} ###"
|
99
101
|
Log.info "Checking is all containers on #{Config.get!(:cluster_name)} in #{Config.get!(:namespace)} are ready..."
|
100
102
|
|
101
|
-
sleep(2)
|
102
|
-
error = false
|
103
|
-
tries = 0
|
104
|
-
max_tries = 30
|
105
|
-
until K8s::Pods.new(Config.get!(:namespace)).all_ready?
|
106
|
-
tries += 1
|
107
|
-
sleep(10)
|
108
|
-
if tries > max_tries
|
109
|
-
error = true
|
110
|
-
break
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
103
|
slack_notification = SlackNotification.new(
|
115
104
|
webhook_url: Config.get!(:slack_webhook_url),
|
116
105
|
github: Config.get!(:github),
|
117
106
|
revision: Config.get!(:revision),
|
118
107
|
revision_name: Config.get!(:revision_name),
|
119
|
-
|
120
|
-
cluster_url: Config.get!(:cluster_url)
|
108
|
+
cluster_label: Config.get!(:cluster_label),
|
109
|
+
cluster_url: Config.get!(:cluster_url),
|
110
|
+
success_color: options[:success_color],
|
111
|
+
error_color: options[:error_color],
|
121
112
|
)
|
122
113
|
|
123
|
-
|
114
|
+
ok = Vidar::DeployStatus.new(Config.get!(:namespace)).ok?
|
115
|
+
|
116
|
+
if ok
|
117
|
+
Log.info "OK: All containers are ready."
|
118
|
+
slack_notification.success if slack_notification.configured?
|
119
|
+
else
|
124
120
|
Log.error "ERROR: Some of containers are not ready."
|
125
121
|
slack_notification.error if slack_notification.configured?
|
126
122
|
exit(1)
|
127
|
-
else
|
128
|
-
Log.info "OK: All containers are ready."
|
129
|
-
slack_notification.success if slack_notification.configured?
|
130
123
|
end
|
131
124
|
end
|
132
125
|
end
|
data/lib/vidar/config.rb
CHANGED
@@ -18,6 +18,11 @@ module Vidar
|
|
18
18
|
names_in_context = current_context.scan(Regexp.new(cluster_names))
|
19
19
|
names_in_context.flatten.first || current_context
|
20
20
|
end
|
21
|
+
},
|
22
|
+
cluster_label: -> {
|
23
|
+
labels = get(:cluster_labels) || {}
|
24
|
+
name = get(:cluster_name)
|
25
|
+
labels[name] || name
|
21
26
|
}
|
22
27
|
}.freeze
|
23
28
|
|
@@ -38,19 +43,12 @@ module Vidar
|
|
38
43
|
@loaded
|
39
44
|
end
|
40
45
|
|
41
|
-
def cluster_name
|
42
|
-
cluster_names = get(:cluster_names).to_s
|
43
|
-
current_context = `kubectl config current-context`.strip
|
44
|
-
|
45
|
-
return current_context if cluster_names.empty?
|
46
|
-
|
47
|
-
names_in_context = current_context.scan(Regexp.new(cluster_names))
|
48
|
-
names_in_context.flatten.first || current_context
|
49
|
-
end
|
50
|
-
|
51
46
|
def get(key)
|
52
47
|
load unless loaded?
|
53
48
|
value = @data[key.to_s] || DEFAULT_OPTIONS[key.to_sym]&.call
|
49
|
+
|
50
|
+
return value unless value.is_a?(String)
|
51
|
+
|
54
52
|
Vidar::Interpolation.call(value, self)
|
55
53
|
end
|
56
54
|
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Vidar
|
2
|
+
class DeployStatus
|
3
|
+
INITIAL_SLEEP = 2
|
4
|
+
SLEEP = 10
|
5
|
+
MAX_TRIES = 30
|
6
|
+
|
7
|
+
attr_reader :namespace
|
8
|
+
|
9
|
+
def initialize(namespace)
|
10
|
+
@namespace = namespace
|
11
|
+
end
|
12
|
+
|
13
|
+
def error?
|
14
|
+
any_errors = false
|
15
|
+
|
16
|
+
sleep(INITIAL_SLEEP)
|
17
|
+
|
18
|
+
until K8s::Pods.new(namespace).all_ready?
|
19
|
+
tries += 1
|
20
|
+
sleep(SLEEP)
|
21
|
+
if tries > MAX_TRIES
|
22
|
+
any_errors = true
|
23
|
+
break
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
any_errors
|
28
|
+
end
|
29
|
+
|
30
|
+
def ok?
|
31
|
+
!error?
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/vidar/k8s/pods.rb
CHANGED
@@ -3,14 +3,26 @@ module Vidar
|
|
3
3
|
SUCCESS_COLOR = "good".freeze
|
4
4
|
ERROR_COLOR = "danger".freeze
|
5
5
|
|
6
|
-
def initialize(
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
def initialize(
|
7
|
+
webhook_url:,
|
8
|
+
github:,
|
9
|
+
revision:,
|
10
|
+
revision_name:,
|
11
|
+
cluster_label:,
|
12
|
+
cluster_url:,
|
13
|
+
success_color: nil,
|
14
|
+
error_color: nil
|
15
|
+
)
|
16
|
+
|
17
|
+
@webhook_url = webhook_url
|
18
|
+
@github = github
|
19
|
+
@revision = revision
|
20
|
+
@revision_name = revision_name
|
21
|
+
@cluster_label = cluster_label
|
22
|
+
@cluster_url = cluster_url
|
23
|
+
@success_color = success_color || SUCCESS_COLOR
|
24
|
+
@error_color = error_color || ERROR_COLOR
|
25
|
+
@connection = Faraday.new
|
14
26
|
end
|
15
27
|
|
16
28
|
def configured?
|
@@ -24,7 +36,7 @@ module Vidar
|
|
24
36
|
|
25
37
|
def success
|
26
38
|
message = "Successful deploy of #{github_link} to #{cluster_link}"
|
27
|
-
perform_with data(message: message, color:
|
39
|
+
perform_with data(message: message, color: success_color)
|
28
40
|
end
|
29
41
|
|
30
42
|
def perform_with(data)
|
@@ -37,7 +49,11 @@ module Vidar
|
|
37
49
|
|
38
50
|
private
|
39
51
|
|
40
|
-
attr_reader :webhook_url, :github,
|
52
|
+
attr_reader :webhook_url, :github,
|
53
|
+
:revision, :revision_name,
|
54
|
+
:cluster_label, :cluster_url,
|
55
|
+
:success_color, :error_color,
|
56
|
+
:connection
|
41
57
|
|
42
58
|
def data(message:, color:)
|
43
59
|
{
|
@@ -62,7 +78,7 @@ module Vidar
|
|
62
78
|
end
|
63
79
|
|
64
80
|
def cluster_link
|
65
|
-
"<#{cluster_url}|#{
|
81
|
+
"<#{cluster_url}|#{cluster_label}>"
|
66
82
|
end
|
67
83
|
end
|
68
84
|
end
|
data/lib/vidar/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vidar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Krzysztof Knapik
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-09-
|
12
|
+
date: 2019-09-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: colorize
|
@@ -163,6 +163,7 @@ files:
|
|
163
163
|
- lib/vidar.rb
|
164
164
|
- lib/vidar/cli.rb
|
165
165
|
- lib/vidar/config.rb
|
166
|
+
- lib/vidar/deploy_status.rb
|
166
167
|
- lib/vidar/interpolation.rb
|
167
168
|
- lib/vidar/k8s/container_status.rb
|
168
169
|
- lib/vidar/k8s/pods.rb
|