vidar 0.7.2 → 0.8.2
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 +4 -4
 - data/Gemfile.lock +1 -1
 - data/README.md +1 -0
 - data/lib/vidar/cli.rb +27 -0
 - data/lib/vidar/k8s/{container_status.rb → container.rb} +11 -2
 - data/lib/vidar/k8s/pod_set.rb +17 -12
 - data/lib/vidar/version.rb +1 -1
 - data/lib/vidar.rb +1 -1
 - metadata +3 -3
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 33c6520a9ed73273478c25d35cad43d5efd3ab267792cfe060ecc1a11bcf6b35
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 1a964a1b01c7b2995e565c52742384b5dadce9f1b0b3721cd38fbaac5871254a
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 5355d26007de445626c0ff60e92ee09941138e0b7a3ea69e3c1c635c24e66ab49639773a8d78bc550ed4d2f14c52f37a3dfd8241649d7906f59d640206c4b6d5
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 17cd01e50418e19badccf8587d1d35a6b221052368169c8bbc0cd2411d8389da42849b6965965aa6f8bec622ac103deb5ec6aa2702c481c9e036f545fafe70be
         
     | 
    
        data/Gemfile.lock
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | 
         @@ -76,6 +76,7 @@ Available commands are: 
     | 
|
| 
       76 
76 
     | 
    
         | 
| 
       77 
77 
     | 
    
         
             
            `vidar monitor_deploy_status` - monitors if all containers are up and running, if slack_webhook_url if defined, sends a noficiation (on both failure and success).
         
     | 
| 
       78 
78 
     | 
    
         | 
| 
      
 79 
     | 
    
         
            +
            `vidar kube_exec --name=web --command='bin/console'` - execute given command (`/bin/ssh` by default) inside the first pod with given name (all pods by default).
         
     | 
| 
       79 
80 
     | 
    
         | 
| 
       80 
81 
     | 
    
         
             
            ## Contributing
         
     | 
| 
       81 
82 
     | 
    
         | 
    
        data/lib/vidar/cli.rb
    CHANGED
    
    | 
         @@ -137,5 +137,32 @@ module Vidar 
     | 
|
| 
       137 
137 
     | 
    
         
             
                    exit(1)
         
     | 
| 
       138 
138 
     | 
    
         
             
                  end
         
     | 
| 
       139 
139 
     | 
    
         
             
                end
         
     | 
| 
      
 140 
     | 
    
         
            +
             
     | 
| 
      
 141 
     | 
    
         
            +
                desc "kube_exec", "Execute given command in running pod"
         
     | 
| 
      
 142 
     | 
    
         
            +
                method_option :command, default: "/bin/sh"
         
     | 
| 
      
 143 
     | 
    
         
            +
                method_option :name, required: false
         
     | 
| 
      
 144 
     | 
    
         
            +
                def kube_exec
         
     | 
| 
      
 145 
     | 
    
         
            +
                  Log.info "Current kubectl context: #{Config.get!(:kubectl_context)}"
         
     | 
| 
      
 146 
     | 
    
         
            +
             
     | 
| 
      
 147 
     | 
    
         
            +
                  deploy_config = Config.deploy_config
         
     | 
| 
      
 148 
     | 
    
         
            +
             
     | 
| 
      
 149 
     | 
    
         
            +
                  Log.error "ERROR: could not find deployment config for #{Config.get!(:kubectl_context)} context" unless deploy_config
         
     | 
| 
      
 150 
     | 
    
         
            +
             
     | 
| 
      
 151 
     | 
    
         
            +
                  pod_set = K8s::PodSet.new(namespace: Config.get!(:namespace), filter: options[:name])
         
     | 
| 
      
 152 
     | 
    
         
            +
                  containers = pod_set.containers.select(&:ready_and_running?).reject(&:istio?)
         
     | 
| 
      
 153 
     | 
    
         
            +
             
     | 
| 
      
 154 
     | 
    
         
            +
                  if containers.empty?
         
     | 
| 
      
 155 
     | 
    
         
            +
                    name = options[:name] || 'any'
         
     | 
| 
      
 156 
     | 
    
         
            +
                    Log.error "No running containers found with *#{name}* name"
         
     | 
| 
      
 157 
     | 
    
         
            +
                    exit(1)
         
     | 
| 
      
 158 
     | 
    
         
            +
                  else
         
     | 
| 
      
 159 
     | 
    
         
            +
                    Log.info "Available containers:"
         
     | 
| 
      
 160 
     | 
    
         
            +
                    containers.each(&:print)
         
     | 
| 
      
 161 
     | 
    
         
            +
                    container = containers.first
         
     | 
| 
      
 162 
     | 
    
         
            +
             
     | 
| 
      
 163 
     | 
    
         
            +
                    Log.info "Running #{options[:command]} in #{container.pod_name}"
         
     | 
| 
      
 164 
     | 
    
         
            +
                    Run.kubectl("exec -it #{container.pod_name} -- #{options[:command]}")
         
     | 
| 
      
 165 
     | 
    
         
            +
                  end
         
     | 
| 
      
 166 
     | 
    
         
            +
                end
         
     | 
| 
       140 
167 
     | 
    
         
             
              end
         
     | 
| 
       141 
168 
     | 
    
         
             
            end
         
     | 
| 
         @@ -1,15 +1,16 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module Vidar
         
     | 
| 
       2 
2 
     | 
    
         
             
              module K8s
         
     | 
| 
       3 
     | 
    
         
            -
                class  
     | 
| 
      
 3 
     | 
    
         
            +
                class Container
         
     | 
| 
       4 
4 
     | 
    
         
             
                  JOB_KIND = "Job".freeze
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
     | 
    
         
            -
                  attr_reader :data, :state, :namespace, :kind
         
     | 
| 
      
 6 
     | 
    
         
            +
                  attr_reader :data, :state, :namespace, :kind, :pod_name
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
8 
     | 
    
         
             
                  def initialize(data)
         
     | 
| 
       9 
9 
     | 
    
         
             
                    @data      = data
         
     | 
| 
       10 
10 
     | 
    
         
             
                    @state     = data["state"]
         
     | 
| 
       11 
11 
     | 
    
         
             
                    @namespace = data["namespace"]
         
     | 
| 
       12 
12 
     | 
    
         
             
                    @kind      = data["kind"]
         
     | 
| 
      
 13 
     | 
    
         
            +
                    @pod_name  = data["pod_name"]
         
     | 
| 
       13 
14 
     | 
    
         
             
                  end
         
     | 
| 
       14 
15 
     | 
    
         | 
| 
       15 
16 
     | 
    
         
             
                  def name
         
     | 
| 
         @@ -25,6 +26,10 @@ module Vidar 
     | 
|
| 
       25 
26 
     | 
    
         
             
                  def success?
         
     | 
| 
       26 
27 
     | 
    
         
             
                    return terminated_completed? if job?
         
     | 
| 
       27 
28 
     | 
    
         | 
| 
      
 29 
     | 
    
         
            +
                    ready_and_running?
         
     | 
| 
      
 30 
     | 
    
         
            +
                  end
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
                  def ready_and_running?
         
     | 
| 
       28 
33 
     | 
    
         
             
                    ready? && running?
         
     | 
| 
       29 
34 
     | 
    
         
             
                  end
         
     | 
| 
       30 
35 
     | 
    
         | 
| 
         @@ -95,6 +100,10 @@ module Vidar 
     | 
|
| 
       95 
100 
     | 
    
         
             
                  def job?
         
     | 
| 
       96 
101 
     | 
    
         
             
                    kind == JOB_KIND
         
     | 
| 
       97 
102 
     | 
    
         
             
                  end
         
     | 
| 
      
 103 
     | 
    
         
            +
             
     | 
| 
      
 104 
     | 
    
         
            +
                  def istio?
         
     | 
| 
      
 105 
     | 
    
         
            +
                    name == "istio-proxy"
         
     | 
| 
      
 106 
     | 
    
         
            +
                  end
         
     | 
| 
       98 
107 
     | 
    
         
             
                end
         
     | 
| 
       99 
108 
     | 
    
         
             
              end
         
     | 
| 
       100 
109 
     | 
    
         
             
            end
         
     | 
    
        data/lib/vidar/k8s/pod_set.rb
    CHANGED
    
    | 
         @@ -14,17 +14,23 @@ module Vidar 
     | 
|
| 
       14 
14 
     | 
    
         | 
| 
       15 
15 
     | 
    
         
             
                    Log.line
         
     | 
| 
       16 
16 
     | 
    
         | 
| 
       17 
     | 
    
         
            -
                     
     | 
| 
      
 17 
     | 
    
         
            +
                    containers.each(&:print)
         
     | 
| 
       18 
18 
     | 
    
         | 
| 
       19 
19 
     | 
    
         
             
                    Log.line
         
     | 
| 
       20 
20 
     | 
    
         | 
| 
       21 
     | 
    
         
            -
                     
     | 
| 
      
 21 
     | 
    
         
            +
                    containers.all?(&:deployed?)
         
     | 
| 
       22 
22 
     | 
    
         
             
                  end
         
     | 
| 
       23 
23 
     | 
    
         | 
| 
       24 
24 
     | 
    
         
             
                  def success?
         
     | 
| 
       25 
     | 
    
         
            -
                    return false if  
     | 
| 
      
 25 
     | 
    
         
            +
                    return false if containers.empty?
         
     | 
| 
       26 
26 
     | 
    
         | 
| 
       27 
     | 
    
         
            -
                     
     | 
| 
      
 27 
     | 
    
         
            +
                    containers.all?(&:success?)
         
     | 
| 
      
 28 
     | 
    
         
            +
                  end
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                  def containers
         
     | 
| 
      
 31 
     | 
    
         
            +
                    return all_containers unless filter
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                    all_containers.select { |cs| cs.name.to_s.include?(filter) }
         
     | 
| 
       28 
34 
     | 
    
         
             
                  end
         
     | 
| 
       29 
35 
     | 
    
         | 
| 
       30 
36 
     | 
    
         
             
                  private
         
     | 
| 
         @@ -46,17 +52,15 @@ module Vidar 
     | 
|
| 
       46 
52 
     | 
    
         
             
                    end
         
     | 
| 
       47 
53 
     | 
    
         
             
                  end
         
     | 
| 
       48 
54 
     | 
    
         | 
| 
       49 
     | 
    
         
            -
                  def  
     | 
| 
       50 
     | 
    
         
            -
                     
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
                    all_container_statuses.select { |cs| cs.name.to_s.include?(filter) }
         
     | 
| 
      
 55 
     | 
    
         
            +
                  def ready_and_running_containers
         
     | 
| 
      
 56 
     | 
    
         
            +
                    containers.select(&:ready_and_running?)
         
     | 
| 
       53 
57 
     | 
    
         
             
                  end
         
     | 
| 
       54 
58 
     | 
    
         | 
| 
       55 
     | 
    
         
            -
                  def  
     | 
| 
       56 
     | 
    
         
            -
                    @ 
     | 
| 
      
 59 
     | 
    
         
            +
                  def all_containers
         
     | 
| 
      
 60 
     | 
    
         
            +
                    @all_containers ||= containers_data.map { |status| Container.new(status) }
         
     | 
| 
       57 
61 
     | 
    
         
             
                  end
         
     | 
| 
       58 
62 
     | 
    
         | 
| 
       59 
     | 
    
         
            -
                  def  
     | 
| 
      
 63 
     | 
    
         
            +
                  def containers_data
         
     | 
| 
       60 
64 
     | 
    
         
             
                    items.map do |i|
         
     | 
| 
       61 
65 
     | 
    
         
             
                      owner_references = i.dig("metadata", "ownerReferences") || []
         
     | 
| 
       62 
66 
     | 
    
         
             
                      kind             = (owner_references[0] || {})["kind"]
         
     | 
| 
         @@ -64,7 +68,8 @@ module Vidar 
     | 
|
| 
       64 
68 
     | 
    
         
             
                      statuses         = i.dig("status", "containerStatuses") || []
         
     | 
| 
       65 
69 
     | 
    
         
             
                      statuses.each do |s|
         
     | 
| 
       66 
70 
     | 
    
         
             
                        s["namespace"] = namespace
         
     | 
| 
       67 
     | 
    
         
            -
                        s["kind"] 
     | 
| 
      
 71 
     | 
    
         
            +
                        s["kind"]      = kind
         
     | 
| 
      
 72 
     | 
    
         
            +
                        s["pod_name"]  = i.dig("metadata", "name")
         
     | 
| 
       68 
73 
     | 
    
         
             
                      end
         
     | 
| 
       69 
74 
     | 
    
         
             
                      statuses
         
     | 
| 
       70 
75 
     | 
    
         
             
                    end.flatten
         
     | 
    
        data/lib/vidar/version.rb
    CHANGED
    
    
    
        data/lib/vidar.rb
    CHANGED
    
    | 
         @@ -14,7 +14,7 @@ require 'vidar/log' 
     | 
|
| 
       14 
14 
     | 
    
         
             
            require 'vidar/run'
         
     | 
| 
       15 
15 
     | 
    
         
             
            require 'vidar/sentry_notification'
         
     | 
| 
       16 
16 
     | 
    
         
             
            require 'vidar/slack_notification'
         
     | 
| 
       17 
     | 
    
         
            -
            require 'vidar/k8s/ 
     | 
| 
      
 17 
     | 
    
         
            +
            require 'vidar/k8s/container'
         
     | 
| 
       18 
18 
     | 
    
         
             
            require 'vidar/k8s/pod_set'
         
     | 
| 
       19 
19 
     | 
    
         
             
            require 'vidar/deploy_config'
         
     | 
| 
       20 
20 
     | 
    
         
             
            require 'vidar/deploy_status'
         
     | 
    
        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 
     | 
    
         
            +
              version: 0.8.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- 
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2019-11-06 00:00:00.000000000 Z
         
     | 
| 
       13 
13 
     | 
    
         
             
            dependencies:
         
     | 
| 
       14 
14 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       15 
15 
     | 
    
         
             
              name: colorize
         
     | 
| 
         @@ -181,7 +181,7 @@ files: 
     | 
|
| 
       181 
181 
     | 
    
         
             
            - lib/vidar/deploy_config.rb
         
     | 
| 
       182 
182 
     | 
    
         
             
            - lib/vidar/deploy_status.rb
         
     | 
| 
       183 
183 
     | 
    
         
             
            - lib/vidar/interpolation.rb
         
     | 
| 
       184 
     | 
    
         
            -
            - lib/vidar/k8s/ 
     | 
| 
      
 184 
     | 
    
         
            +
            - lib/vidar/k8s/container.rb
         
     | 
| 
       185 
185 
     | 
    
         
             
            - lib/vidar/k8s/pod_set.rb
         
     | 
| 
       186 
186 
     | 
    
         
             
            - lib/vidar/log.rb
         
     | 
| 
       187 
187 
     | 
    
         
             
            - lib/vidar/run.rb
         
     |