kubernetes-deploy 0.9.4 → 0.10.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 +4 -4
- data/.rubocop.yml +1 -4
- data/Gemfile +1 -0
- data/README.md +1 -0
- data/Rakefile +1 -0
- data/kubernetes-deploy.gemspec +3 -0
- data/lib/kubernetes-deploy/deferred_summary_logging.rb +1 -0
- data/lib/kubernetes-deploy/ejson_secret_provisioner.rb +1 -1
- data/lib/kubernetes-deploy/kubeclient_builder/google_friendly_config.rb +1 -1
- data/lib/kubernetes-deploy/kubernetes_resource.rb +4 -4
- data/lib/kubernetes-deploy/kubernetes_resource/cloudsql.rb +2 -2
- data/lib/kubernetes-deploy/kubernetes_resource/deployment.rb +3 -3
- data/lib/kubernetes-deploy/kubernetes_resource/pod.rb +9 -20
- data/lib/kubernetes-deploy/kubernetes_resource/redis.rb +2 -2
- data/lib/kubernetes-deploy/kubernetes_resource/replica_set.rb +1 -1
- data/lib/kubernetes-deploy/resource_watcher.rb +1 -1
- data/lib/kubernetes-deploy/runner.rb +3 -3
- data/lib/kubernetes-deploy/version.rb +2 -1
- metadata +3 -3
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 13bfb87f3f0cd5b833cb6146f91d7ccdfcf50725
         | 
| 4 | 
            +
              data.tar.gz: 3c6cb3d5acf0c405a14759c01444e11244124509
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 3d101d13086cf414cfc08989c9db9f7858dea14ab523c0424bf871a82ca98babc851ff7aea0be04db984e5aba689e5a2ecc5cc80750d2df4525573e5475f74a7
         | 
| 7 | 
            +
              data.tar.gz: f7b35147c24d8dad169c850de62fe0b8108ec538c5626741404e70bdce86860ce04c4ac332b8fc9561598eabbaa81794af64f16c9978c5ee08b4a6e1fd078d7e
         | 
    
        data/.rubocop.yml
    CHANGED
    
    
    
        data/Gemfile
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | @@ -67,6 +67,7 @@ This repo also includes related tools for [running tasks](#kubernetes-run) and [ | |
| 67 67 |  | 
| 68 68 | 
             
            ## Prerequisites
         | 
| 69 69 |  | 
| 70 | 
            +
            * Ruby 2.3+
         | 
| 70 71 | 
             
            * Your cluster must be running Kubernetes v1.6.0 or higher
         | 
| 71 72 | 
             
            * Each app must have a deploy directory containing its Kubernetes templates (see [Templates](#templates))
         | 
| 72 73 | 
             
            * You must remove the` kubectl.kubernetes.io/last-applied-configuration` annotation from any resources in the namespace that are not included in your deploy directory. This annotation is added automatically when you create resources with `kubectl apply`. `kubernetes-deploy` will prune any resources that have this annotation and are not in the deploy directory.**
         | 
    
        data/Rakefile
    CHANGED
    
    
    
        data/kubernetes-deploy.gemspec
    CHANGED
    
    | @@ -1,4 +1,5 @@ | |
| 1 1 | 
             
            # coding: utf-8
         | 
| 2 | 
            +
            # frozen_string_literal: true
         | 
| 2 3 | 
             
            lib = File.expand_path('../lib', __FILE__)
         | 
| 3 4 | 
             
            $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
         | 
| 4 5 | 
             
            require 'kubernetes-deploy/version'
         | 
| @@ -20,6 +21,8 @@ Gem::Specification.new do |spec| | |
| 20 21 | 
             
              spec.bindir        = "exe"
         | 
| 21 22 | 
             
              spec.executables   = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
         | 
| 22 23 | 
             
              spec.require_paths = ["lib"]
         | 
| 24 | 
            +
             | 
| 25 | 
            +
              spec.required_ruby_version = '>= 2.3.0'
         | 
| 23 26 | 
             
              spec.add_dependency "activesupport", ">= 4.2"
         | 
| 24 27 | 
             
              spec.add_dependency "kubeclient", "~> 2.3"
         | 
| 25 28 | 
             
              spec.add_dependency "googleauth", ">= 0.5"
         | 
| @@ -5,7 +5,7 @@ module KubernetesDeploy | |
| 5 5 | 
             
              module KubeclientBuilder
         | 
| 6 6 | 
             
                class GoogleFriendlyConfig < Kubeclient::Config
         | 
| 7 7 | 
             
                  def fetch_user_auth_options(user)
         | 
| 8 | 
            -
                    if user | 
| 8 | 
            +
                    if user.dig('auth-provider', 'name') == 'gcp'
         | 
| 9 9 | 
             
                      { bearer_token: new_token }
         | 
| 10 10 | 
             
                    else
         | 
| 11 11 | 
             
                      super
         | 
| @@ -13,11 +13,11 @@ module KubernetesDeploy | |
| 13 13 | 
             
                LOG_LINE_COUNT = 250
         | 
| 14 14 |  | 
| 15 15 | 
             
                DEBUG_RESOURCE_NOT_FOUND_MESSAGE = "None found. Please check your usual logging service (e.g. Splunk)."
         | 
| 16 | 
            -
                UNUSUAL_FAILURE_MESSAGE =  | 
| 16 | 
            +
                UNUSUAL_FAILURE_MESSAGE = <<~MSG
         | 
| 17 17 | 
             
                  It is very unusual for this resource type to fail to deploy. Please try the deploy again.
         | 
| 18 18 | 
             
                  If that new deploy also fails, contact your cluster administrator.
         | 
| 19 19 | 
             
                  MSG
         | 
| 20 | 
            -
                STANDARD_TIMEOUT_MESSAGE =  | 
| 20 | 
            +
                STANDARD_TIMEOUT_MESSAGE = <<~MSG
         | 
| 21 21 | 
             
                  Kubernetes will continue to attempt to deploy this resource in the cluster, but at this point it is considered unlikely that it will succeed.
         | 
| 22 22 | 
             
                  If you have reason to believe it will succeed, retry the deploy to continue to monitor the rollout.
         | 
| 23 23 | 
             
                  MSG
         | 
| @@ -44,7 +44,7 @@ module KubernetesDeploy | |
| 44 44 |  | 
| 45 45 | 
             
                def initialize(namespace:, context:, definition:, logger:)
         | 
| 46 46 | 
             
                  # subclasses must also set these if they define their own initializer
         | 
| 47 | 
            -
                  @name = definition. | 
| 47 | 
            +
                  @name = definition.dig("metadata", "name")
         | 
| 48 48 | 
             
                  unless @name.present?
         | 
| 49 49 | 
             
                    logger.summary.add_paragraph("Rendered template content:\n#{definition.to_yaml}")
         | 
| 50 50 | 
             
                    raise FatalDeploymentError, "Template is missing required field metadata.name"
         | 
| @@ -268,7 +268,7 @@ module KubernetesDeploy | |
| 268 268 | 
             
                  file.write(YAML.dump(@definition))
         | 
| 269 269 | 
             
                  file
         | 
| 270 270 | 
             
                ensure
         | 
| 271 | 
            -
                  file | 
| 271 | 
            +
                  file&.close
         | 
| 272 272 | 
             
                end
         | 
| 273 273 |  | 
| 274 274 | 
             
                def statsd_tags
         | 
| @@ -54,7 +54,7 @@ module KubernetesDeploy | |
| 54 54 | 
             
                  if st.success?
         | 
| 55 55 | 
             
                    parsed = JSON.parse(service)
         | 
| 56 56 |  | 
| 57 | 
            -
                    if parsed. | 
| 57 | 
            +
                    if parsed.dig("spec", "clusterIP").present?
         | 
| 58 58 | 
             
                      # the service has an assigned cluster IP and is therefore functioning
         | 
| 59 59 | 
             
                      return true
         | 
| 60 60 | 
             
                    end
         | 
| @@ -70,7 +70,7 @@ module KubernetesDeploy | |
| 70 70 | 
             
                  if st.success?
         | 
| 71 71 | 
             
                    parsed = JSON.parse(redis)
         | 
| 72 72 |  | 
| 73 | 
            -
                    @cloudsql_resource_uuid = parsed. | 
| 73 | 
            +
                    @cloudsql_resource_uuid = parsed.dig("metadata", "uid")
         | 
| 74 74 | 
             
                  end
         | 
| 75 75 | 
             
                end
         | 
| 76 76 | 
             
              end
         | 
| @@ -47,15 +47,15 @@ module KubernetesDeploy | |
| 47 47 | 
             
                end
         | 
| 48 48 |  | 
| 49 49 | 
             
                def failure_message
         | 
| 50 | 
            -
                  @latest_rs | 
| 50 | 
            +
                  @latest_rs&.failure_message
         | 
| 51 51 | 
             
                end
         | 
| 52 52 |  | 
| 53 53 | 
             
                def timeout_message
         | 
| 54 54 | 
             
                  progress_seconds = @definition['spec']['progressDeadlineSeconds']
         | 
| 55 55 | 
             
                  if progress_seconds
         | 
| 56 | 
            -
                    "Deploy timed out due to progressDeadlineSeconds of #{progress_seconds} seconds. #{@latest_rs | 
| 56 | 
            +
                    "Deploy timed out due to progressDeadlineSeconds of #{progress_seconds} seconds. #{@latest_rs&.timeout_message}"
         | 
| 57 57 | 
             
                  else
         | 
| 58 | 
            -
                    @latest_rs | 
| 58 | 
            +
                    @latest_rs&.timeout_message
         | 
| 59 59 | 
             
                  end
         | 
| 60 60 | 
             
                end
         | 
| 61 61 |  | 
| @@ -162,25 +162,14 @@ module KubernetesDeploy | |
| 162 162 | 
             
                end
         | 
| 163 163 |  | 
| 164 164 | 
             
                class Container
         | 
| 165 | 
            -
                  STATUS_SCAFFOLD = {
         | 
| 166 | 
            -
                    "state" => {
         | 
| 167 | 
            -
                      "running" => {},
         | 
| 168 | 
            -
                      "waiting" => {},
         | 
| 169 | 
            -
                      "terminated" => {},
         | 
| 170 | 
            -
                    },
         | 
| 171 | 
            -
                    "lastState" => {
         | 
| 172 | 
            -
                      "terminated" => {}
         | 
| 173 | 
            -
                    }
         | 
| 174 | 
            -
                  }.freeze
         | 
| 175 | 
            -
             | 
| 176 165 | 
             
                  attr_reader :name, :probe_location
         | 
| 177 166 |  | 
| 178 167 | 
             
                  def initialize(definition, init_container: false)
         | 
| 179 168 | 
             
                    @init_container = init_container
         | 
| 180 169 | 
             
                    @name = definition["name"]
         | 
| 181 170 | 
             
                    @image = definition["image"]
         | 
| 182 | 
            -
                    @probe_location = definition. | 
| 183 | 
            -
                    @status =  | 
| 171 | 
            +
                    @probe_location = definition.dig("readinessProbe", "httpGet", "path")
         | 
| 172 | 
            +
                    @status = {}
         | 
| 184 173 | 
             
                  end
         | 
| 185 174 |  | 
| 186 175 | 
             
                  def doomed?
         | 
| @@ -188,14 +177,14 @@ module KubernetesDeploy | |
| 188 177 | 
             
                  end
         | 
| 189 178 |  | 
| 190 179 | 
             
                  def doom_reason
         | 
| 191 | 
            -
                    exit_code = @status | 
| 192 | 
            -
                    last_terminated_reason = @status | 
| 193 | 
            -
                    limbo_reason = @status | 
| 194 | 
            -
                    limbo_message = @status | 
| 180 | 
            +
                    exit_code = @status.dig('lastState', 'terminated', 'exitCode')
         | 
| 181 | 
            +
                    last_terminated_reason = @status.dig("lastState", "terminated", "reason")
         | 
| 182 | 
            +
                    limbo_reason = @status.dig("state", "waiting", "reason")
         | 
| 183 | 
            +
                    limbo_message = @status.dig("state", "waiting", "message")
         | 
| 195 184 |  | 
| 196 185 | 
             
                    if last_terminated_reason == "ContainerCannotRun"
         | 
| 197 186 | 
             
                      # ref: https://github.com/kubernetes/kubernetes/blob/562e721ece8a16e05c7e7d6bdd6334c910733ab2/pkg/kubelet/dockershim/docker_container.go#L353
         | 
| 198 | 
            -
                      "Failed to start (exit #{exit_code}): #{@status | 
| 187 | 
            +
                      "Failed to start (exit #{exit_code}): #{@status.dig('lastState', 'terminated', 'message')}"
         | 
| 199 188 | 
             
                    elsif limbo_reason == "CrashLoopBackOff"
         | 
| 200 189 | 
             
                      "Crashing repeatedly (exit #{exit_code}). See logs for more information."
         | 
| 201 190 | 
             
                    elsif %w(ImagePullBackOff ErrImagePull).include?(limbo_reason) &&
         | 
| @@ -218,11 +207,11 @@ module KubernetesDeploy | |
| 218 207 | 
             
                  end
         | 
| 219 208 |  | 
| 220 209 | 
             
                  def update_status(data)
         | 
| 221 | 
            -
                    @status =  | 
| 210 | 
            +
                    @status = data || {}
         | 
| 222 211 | 
             
                  end
         | 
| 223 212 |  | 
| 224 213 | 
             
                  def reset_status
         | 
| 225 | 
            -
                    @status =  | 
| 214 | 
            +
                    @status = {}
         | 
| 226 215 | 
             
                  end
         | 
| 227 216 | 
             
                end
         | 
| 228 217 | 
             
              end
         | 
| @@ -56,7 +56,7 @@ module KubernetesDeploy | |
| 56 56 | 
             
                  if st.success?
         | 
| 57 57 | 
             
                    parsed = JSON.parse(service)
         | 
| 58 58 |  | 
| 59 | 
            -
                    if parsed. | 
| 59 | 
            +
                    if parsed.dig("spec", "clusterIP").present?
         | 
| 60 60 | 
             
                      return true
         | 
| 61 61 | 
             
                    end
         | 
| 62 62 | 
             
                  end
         | 
| @@ -71,7 +71,7 @@ module KubernetesDeploy | |
| 71 71 | 
             
                  if st.success?
         | 
| 72 72 | 
             
                    parsed = JSON.parse(redis)
         | 
| 73 73 |  | 
| 74 | 
            -
                    @redis_resource_uuid = parsed. | 
| 74 | 
            +
                    @redis_resource_uuid = parsed.dig("metadata", "uid")
         | 
| 75 75 | 
             
                  end
         | 
| 76 76 | 
             
                end
         | 
| 77 77 | 
             
              end
         | 
| @@ -86,7 +86,7 @@ module KubernetesDeploy | |
| 86 86 |  | 
| 87 87 | 
             
                def container_names
         | 
| 88 88 | 
             
                  regular_containers = @definition["spec"]["template"]["spec"]["containers"].map { |c| c["name"] }
         | 
| 89 | 
            -
                  init_containers = @definition["spec"]["template"]["spec"].fetch("initContainers",  | 
| 89 | 
            +
                  init_containers = @definition["spec"]["template"]["spec"].fetch("initContainers", []).map { |c| c["name"] }
         | 
| 90 90 | 
             
                  regular_containers + init_containers
         | 
| 91 91 | 
             
                end
         | 
| 92 92 |  | 
| @@ -3,7 +3,7 @@ module KubernetesDeploy | |
| 3 3 | 
             
              class ResourceWatcher
         | 
| 4 4 | 
             
                def initialize(resources, logger:, deploy_started_at: Time.now.utc)
         | 
| 5 5 | 
             
                  unless resources.is_a?(Enumerable)
         | 
| 6 | 
            -
                    raise ArgumentError,  | 
| 6 | 
            +
                    raise ArgumentError, <<~MSG
         | 
| 7 7 | 
             
                      ResourceWatcher expects Enumerable collection, got `#{resources.class}` instead
         | 
| 8 8 | 
             
                    MSG
         | 
| 9 9 | 
             
                  end
         | 
| @@ -125,7 +125,7 @@ module KubernetesDeploy | |
| 125 125 | 
             
                  else
         | 
| 126 126 | 
             
                    deploy_resources(resources, prune: prune, verify: false)
         | 
| 127 127 | 
             
                    @logger.summary.add_action("deployed #{resources.length} #{'resource'.pluralize(resources.length)}")
         | 
| 128 | 
            -
                    warning =  | 
| 128 | 
            +
                    warning = <<~MSG
         | 
| 129 129 | 
             
                      Deploy result verification is disabled for this deploy.
         | 
| 130 130 | 
             
                      This means the desired changes were communicated to Kubernetes, but the deploy did not make sure they actually succeeded.
         | 
| 131 131 | 
             
                    MSG
         | 
| @@ -245,7 +245,7 @@ module KubernetesDeploy | |
| 245 245 | 
             
                    yield doc unless doc.blank?
         | 
| 246 246 | 
             
                  end
         | 
| 247 247 | 
             
                rescue Psych::SyntaxError => e
         | 
| 248 | 
            -
                  debug_msg =  | 
| 248 | 
            +
                  debug_msg = <<~INFO
         | 
| 249 249 | 
             
                    Error message: #{e}
         | 
| 250 250 |  | 
| 251 251 | 
             
                    Template content:
         | 
| @@ -372,7 +372,7 @@ module KubernetesDeploy | |
| 372 372 | 
             
                    _, err, create_st = kubectl.run("create", "-f", r.file_path, log_failure: false)
         | 
| 373 373 |  | 
| 374 374 | 
             
                    next if create_st.success?
         | 
| 375 | 
            -
                    raise FatalDeploymentError,  | 
| 375 | 
            +
                    raise FatalDeploymentError, <<~MSG
         | 
| 376 376 | 
             
                      Failed to replace or create resource: #{r.id}
         | 
| 377 377 | 
             
                      #{err}
         | 
| 378 378 | 
             
                    MSG
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: kubernetes-deploy
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.10.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Katrina Verey
         | 
| @@ -9,7 +9,7 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: exe
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2017-07- | 
| 12 | 
            +
            date: 2017-07-25 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: activesupport
         | 
| @@ -246,7 +246,7 @@ required_ruby_version: !ruby/object:Gem::Requirement | |
| 246 246 | 
             
              requirements:
         | 
| 247 247 | 
             
              - - ">="
         | 
| 248 248 | 
             
                - !ruby/object:Gem::Version
         | 
| 249 | 
            -
                  version:  | 
| 249 | 
            +
                  version: 2.3.0
         | 
| 250 250 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 251 251 | 
             
              requirements:
         | 
| 252 252 | 
             
              - - ">="
         |