vidar 0.4.4 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e04340c6ac0bb74c7e4cc02270d82418719e215c2b02a86685753c1da903a1c4
4
- data.tar.gz: 98bad2e981dbb3c97539e4d3c8bd75c94ce31b6307b6b10f8543dc39e9dc016b
3
+ metadata.gz: b4e381c4e8e957cf7e8f758dcf56e38d9a1187377b6f7195f3469fc19ebd0ba8
4
+ data.tar.gz: 6b6da0fca65c144a77aa1fa4b3327f6524335294372b55ce431e7b787452739f
5
5
  SHA512:
6
- metadata.gz: 808e4b08108033a93a750654d86ab1d7c1a6aaeb3727374b82a666a5ca2ca030fcfc1dcc27301d4788ad558ad0fbaaf1894a353ded3dec705af3f9210a1e3952
7
- data.tar.gz: 4cafe1cda4563e5862f8645e03f08845dc5b2f37cfe698d4d71c370a3236d46910ea831ecb2613fa08c62528ee5d2c306ba3cddd7a71357401aa3bd8cab9dfd5
6
+ metadata.gz: d0ac08a8e695030cfb2d995c3284de04245ef7c0f7dc52eec18c8acab3ce580ea2e1366e1d182caaad4eee15e3543d00d2733233a01049635dcf062b5401f880
7
+ data.tar.gz: dffd7ebb7160f55fe4ded5edbe78bd794ef1c481c9ab2b8670cadf96eb257c9bdbc426cab1c534e0ee564e92c0190fd87b0cead978794ce8d397f5a7cb8b2c08
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- vidar (0.4.4)
4
+ vidar (0.5.0)
5
5
  colorize
6
6
  faraday
7
7
  thor (~> 0.20)
@@ -20,7 +20,7 @@ GEM
20
20
  method_source (0.9.2)
21
21
  multipart-post (2.1.1)
22
22
  parallel (1.17.0)
23
- parser (2.6.4.1)
23
+ parser (2.6.5.0)
24
24
  ast (~> 2.4.0)
25
25
  pry (0.12.2)
26
26
  coderay (~> 1.1.0)
@@ -33,21 +33,21 @@ GEM
33
33
  rspec-mocks (~> 3.8.0)
34
34
  rspec-core (3.8.2)
35
35
  rspec-support (~> 3.8.0)
36
- rspec-expectations (3.8.4)
36
+ rspec-expectations (3.8.5)
37
37
  diff-lcs (>= 1.2.0, < 2.0)
38
38
  rspec-support (~> 3.8.0)
39
- rspec-mocks (3.8.1)
39
+ rspec-mocks (3.8.2)
40
40
  diff-lcs (>= 1.2.0, < 2.0)
41
41
  rspec-support (~> 3.8.0)
42
- rspec-support (3.8.2)
43
- rubocop (0.74.0)
42
+ rspec-support (3.8.3)
43
+ rubocop (0.75.0)
44
44
  jaro_winkler (~> 1.5.1)
45
45
  parallel (~> 1.10)
46
46
  parser (>= 2.6)
47
47
  rainbow (>= 2.2.2, < 4.0)
48
48
  ruby-progressbar (~> 1.7)
49
49
  unicode-display_width (>= 1.4.0, < 1.7)
50
- rubocop-performance (1.4.1)
50
+ rubocop-performance (1.5.0)
51
51
  rubocop (>= 0.71.0)
52
52
  ruby-progressbar (1.10.1)
53
53
  thor (0.20.3)
data/README.md CHANGED
@@ -33,18 +33,22 @@ Or install it yourself as:
33
33
  image: gcr.io/renofiinfrastructure/vidar
34
34
  # k8s namespace, required
35
35
  namespace: borrower
36
- # slack webhook url use to send deploy notifications, optional
37
- slack_webhook_url: https://hooks.slack.com/services/....../....../....../
38
- # github name used to conctruct slack notification content, required when slack_webhook_url is set
36
+ # github name used to build deployment notification content
39
37
  github: RenoFi/vidar
40
- # Cluster url, used to conctruct slack notification content.
41
- # Usually it displays k8 workloads filtered to current cluster and namespace.
42
- # Similar to all other values it may contain references to others using mustache-like interpolation.
43
- # Required when slack_webhook_url is set
44
- cluster_url: "https://console.cloud.google.com/kubernetes/workload?cluster={{cluster_name}}&namespace={{namespace}}"
45
- # known k8s cluster_names, used to construct regexp to fetch current cluster from kubectl context
46
- # Required when slack_webhook_url is set
47
- cluster_names: "cluster-A|cluster-B" cluster name from kubectl context
38
+ # deployments config per kubectl context, required for `monitor_deploy_status` command
39
+ deployments:
40
+ gke_project_us-east4_staging:
41
+ # Deployment Name
42
+ name: staging cluster
43
+ # Color of successful notification, default value: 008800
44
+ success_color: "00ff00"
45
+ # Color of failed notification, default value: ff1100
46
+ failure_color: "ff0000"
47
+ # Deployment url, e.g. url to gke cluster workloads filtered by namespace
48
+ # Similar to all other values it may contain references to others using mustache-like interpolation.
49
+ url: "https://console.cloud.google.com/kubernetes/workload?project=project&namespace={{namespace}}"
50
+ # Slack webhook url use to send deploy notifications, optional
51
+ slack_webhook_url: https://hooks.slack.com/services/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
48
52
  # docker-compose file, optional, default value: docker-compose.ci.yml
49
53
  compose_file: docker-compose.ci.yml
50
54
  # default_branch, optional, default value: master
data/bin/release CHANGED
@@ -5,4 +5,3 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
  require 'vidar/version'
6
6
 
7
7
  `bundle && git commit -am "Release #{Vidar::VERSION}" && bundle exec rake build release`
8
-
data/lib/vidar.rb CHANGED
@@ -15,6 +15,7 @@ require 'vidar/run'
15
15
  require 'vidar/slack_notification'
16
16
  require 'vidar/k8s/container_status'
17
17
  require 'vidar/k8s/pod_set'
18
+ require 'vidar/deploy_config'
18
19
  require 'vidar/deploy_status'
19
20
  require 'vidar/cli'
20
21
 
data/lib/vidar/cli.rb CHANGED
@@ -62,7 +62,7 @@ module Vidar
62
62
  method_option :revision, required: false
63
63
  def deploy
64
64
  revision = options[:revision] || Config.get!(:revision)
65
- Log.info "Current cluster_name: #{Config.get!(:cluster_name)} ###"
65
+ Log.info "Current kubectl context: #{Config.get!(:kubectl_context)} ###"
66
66
 
67
67
  Log.info "Looking for deploy hook..."
68
68
  template_name, error, status = Open3.capture3 "kubectl get cronjob deploy-hook-template -n #{Config.get!(:namespace)} -o name --ignore-not-found=true"
@@ -103,21 +103,19 @@ module Vidar
103
103
  end
104
104
 
105
105
  desc "monitor_deploy_status", "Checks is deployment has finished and sends post-deploy notification"
106
- method_option :success_color, required: false
107
- method_option :error_color, required: false
108
106
  def monitor_deploy_status
109
- Log.info "Current cluster_name: #{Config.get!(:cluster_name)}"
110
- Log.info "Checking is all containers on #{Config.get!(:cluster_name)} in #{Config.get!(:namespace)} are ready..."
107
+ Log.info "Current kubectl context: #{Config.get!(:kubectl_context)} ###"
108
+ Log.info "Checking if all containers in #{Config.get!(:namespace)} namespace(s) are ready..."
109
+
110
+ deploy_config = Config.deploy_config
111
+
112
+ Log.error "ERROR: could not find deployment config for #{Config.get!(:kubectl_context)} context" unless deploy_config
111
113
 
112
114
  slack_notification = SlackNotification.new(
113
- webhook_url: Config.get(:slack_webhook_url),
114
115
  github: Config.get!(:github),
115
116
  revision: Config.get!(:revision),
116
117
  revision_name: Config.get!(:revision_name),
117
- cluster_label: Config.get!(:cluster_label),
118
- cluster_url: Config.get!(:cluster_url),
119
- success_color: options[:success_color],
120
- error_color: options[:error_color],
118
+ deploy_config: deploy_config
121
119
  )
122
120
 
123
121
  deploy_status = Vidar::DeployStatus.new(namespace: Config.get!(:namespace))
@@ -129,7 +127,7 @@ module Vidar
129
127
  slack_notification.success if slack_notification.configured?
130
128
  else
131
129
  Log.error "ERROR: Some of containers are errored or not ready"
132
- slack_notification.error if slack_notification.configured?
130
+ slack_notification.failure if slack_notification.configured?
133
131
  exit(1)
134
132
  end
135
133
  end
data/lib/vidar/config.rb CHANGED
@@ -3,27 +3,12 @@ module Vidar
3
3
  DEFAULT_MANIFEST_FILE = "vidar.yml".freeze
4
4
 
5
5
  DEFAULT_OPTIONS = {
6
- compose_file: -> { "docker-compose.ci.yml" },
7
- default_branch: -> { "master" },
8
- current_branch: -> { `git rev-parse --abbrev-ref HEAD`.strip.tr("/", "-") },
9
- revision: -> { `git rev-parse HEAD`.strip },
10
- revision_name: -> { `git show --pretty=format:"%s (%h)" -s HEAD`.strip },
11
- cluster_name: -> {
12
- cluster_names = get(:cluster_names).to_s
13
- current_context = `kubectl config current-context`.strip
14
-
15
- if cluster_names.empty?
16
- current_context
17
- else
18
- names_in_context = current_context.scan(Regexp.new(cluster_names))
19
- names_in_context.flatten.first || current_context
20
- end
21
- },
22
- cluster_label: -> {
23
- labels = get(:cluster_labels) || {}
24
- name = get(:cluster_name)
25
- labels[name] || name
26
- }
6
+ compose_file: -> { "docker-compose.ci.yml" },
7
+ default_branch: -> { "master" },
8
+ current_branch: -> { `git rev-parse --abbrev-ref HEAD`.strip.tr("/", "-") },
9
+ revision: -> { `git rev-parse HEAD`.strip },
10
+ revision_name: -> { `git show --pretty=format:"%s (%h)" -s HEAD`.strip },
11
+ kubectl_context: -> { `kubectl config current-context`.strip },
27
12
  }.freeze
28
13
 
29
14
  class << self
@@ -56,6 +41,18 @@ module Vidar
56
41
  load unless loaded?
57
42
  get(key) || fail(MissingConfigError, key)
58
43
  end
44
+
45
+ def deploy_config
46
+ deployments = get(:deployments) || {}
47
+
48
+ return nil unless deployments.is_a?(Hash)
49
+
50
+ deployment = deployments[get!(:kubectl_context)]
51
+
52
+ return nil unless deployment
53
+
54
+ DeployConfig.new(deployment.transform_keys!(&:to_sym))
55
+ end
59
56
  end
60
57
  end
61
58
  end
@@ -0,0 +1,16 @@
1
+ module Vidar
2
+ class DeployConfig
3
+ SUCCESS_COLOR = "008800".freeze
4
+ FAILURE_COLOR = "ff1100".freeze
5
+
6
+ attr_reader :name, :url, :success_color, :failure_color, :slack_webhook_url
7
+
8
+ def initialize(name:, url:, slack_webhook_url:, success_color: SUCCESS_COLOR, failure_color: FAILURE_COLOR)
9
+ @name = name
10
+ @url = url
11
+ @success_color = success_color
12
+ @failure_color = failure_color
13
+ @slack_webhook_url = slack_webhook_url
14
+ end
15
+ end
16
+ end
@@ -1,27 +1,14 @@
1
1
  module Vidar
2
2
  class SlackNotification
3
- SUCCESS_COLOR = "good".freeze
4
- ERROR_COLOR = "danger".freeze
5
-
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
3
+ def initialize(github:, revision:, revision_name:, deploy_config:)
18
4
  @github = github
19
5
  @revision = revision
20
6
  @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
7
+ @deploy_name = deploy_config.name
8
+ @deploy_url = deploy_config.url
9
+ @success_color = deploy_config.success_color
10
+ @failure_color = deploy_config.failure_color
11
+ @webhook_url = deploy_config.slack_webhook_url
25
12
  @connection = Faraday.new
26
13
  end
27
14
 
@@ -29,13 +16,13 @@ module Vidar
29
16
  !webhook_url.to_s.empty?
30
17
  end
31
18
 
32
- def error
33
- message = "Failed deploy of #{github_link} to #{cluster_link} :fire: <!channel>"
34
- perform_with data(message: message, color: ERROR_COLOR)
19
+ def failure
20
+ message = "Failed deploy of #{github_link} to #{deploy_link} :fire: <!channel>"
21
+ perform_with data(message: message, color: failure_color)
35
22
  end
36
23
 
37
24
  def success
38
- message = "Successful deploy of #{github_link} to #{cluster_link}"
25
+ message = "Successful deploy of #{github_link} to #{deploy_link}"
39
26
  perform_with data(message: message, color: success_color)
40
27
  end
41
28
 
@@ -49,10 +36,9 @@ module Vidar
49
36
 
50
37
  private
51
38
 
52
- attr_reader :webhook_url, :github,
53
- :revision, :revision_name,
54
- :cluster_label, :cluster_url,
55
- :success_color, :error_color,
39
+ attr_reader :github, :revision, :revision_name,
40
+ :deploy_name, :deploy_url, :webhook_url,
41
+ :success_color, :failure_color,
56
42
  :connection
57
43
 
58
44
  def data(message:, color:)
@@ -77,8 +63,8 @@ module Vidar
77
63
  "<#{github_url}|#{revision_name}>"
78
64
  end
79
65
 
80
- def cluster_link
81
- "<#{cluster_url}|#{cluster_label}>"
66
+ def deploy_link
67
+ "<#{deploy_url}|#{deploy_name}>"
82
68
  end
83
69
  end
84
70
  end
data/lib/vidar/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Vidar
2
- VERSION = '0.4.4'.freeze
2
+ VERSION = '0.5.0'.freeze
3
3
  end
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.4.4
4
+ version: 0.5.0
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-10-02 00:00:00.000000000 Z
12
+ date: 2019-10-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: colorize
@@ -178,6 +178,7 @@ files:
178
178
  - lib/vidar.rb
179
179
  - lib/vidar/cli.rb
180
180
  - lib/vidar/config.rb
181
+ - lib/vidar/deploy_config.rb
181
182
  - lib/vidar/deploy_status.rb
182
183
  - lib/vidar/interpolation.rb
183
184
  - lib/vidar/k8s/container_status.rb