Sha256: 1bca24678737a7984af4a02fb1680e22c4fb812b7b39d17a461300227d5cceef

Contents?: true

Size: 1.12 KB

Versions: 45

Compression:

Stored size: 1.12 KB

Contents

module Kubes::Kubectl::Fetch
  class Deployment < Base
    extend Memoist

    def metadata
      deployment['metadata'] if found
    end

    def spec
      deployment['spec'] if found
    end

    def deployment
      items = fetch(:deployment)
      # Not checking if deployment exists because kubes will error on `kubes get` from missing deployments already
      deployments = items.select { |i| i['kind'] == "Deployment" }

      if !@options[:deployment] && !@options[:pod] && deployments.size > 1
        names = deployments.map { |d| d['metadata']['name'] }
        logger.info <<~EOL
          INFO: More than one deployment found.
          Deployment names: #{names.join(', ')}
          Using #{names.first}
          Note: You can specify the deployment to use with --deployment or -d
        EOL
      end

      find_deployment(deployments)
    end
    memoize :deployment

    def found
      !!deployment
    end

    def find_deployment(deployments)
      if @options[:deployment]
        deployments.find { |d| d['metadata']['name'] == @options[:deployment] }
      else
        deployments.first
      end
    end
  end
end

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
kubes-0.9.3 lib/kubes/kubectl/fetch/deployment.rb
kubes-0.9.2 lib/kubes/kubectl/fetch/deployment.rb
kubes-0.9.1 lib/kubes/kubectl/fetch/deployment.rb
kubes-0.9.0 lib/kubes/kubectl/fetch/deployment.rb
kubes-0.8.10 lib/kubes/kubectl/fetch/deployment.rb
kubes-0.8.9 lib/kubes/kubectl/fetch/deployment.rb
kubes-0.8.8 lib/kubes/kubectl/fetch/deployment.rb
kubes-0.8.7 lib/kubes/kubectl/fetch/deployment.rb
kubes-0.8.6 lib/kubes/kubectl/fetch/deployment.rb
kubes-0.8.5 lib/kubes/kubectl/fetch/deployment.rb
kubes-0.8.4 lib/kubes/kubectl/fetch/deployment.rb
kubes-0.8.3 lib/kubes/kubectl/fetch/deployment.rb
kubes-0.8.2 lib/kubes/kubectl/fetch/deployment.rb
kubes-0.8.1 lib/kubes/kubectl/fetch/deployment.rb
kubes-0.8.0 lib/kubes/kubectl/fetch/deployment.rb
kubes-0.7.10 lib/kubes/kubectl/fetch/deployment.rb
kubes-0.7.9 lib/kubes/kubectl/fetch/deployment.rb
kubes-0.7.8 lib/kubes/kubectl/fetch/deployment.rb
kubes-0.7.7 lib/kubes/kubectl/fetch/deployment.rb
kubes-0.7.6 lib/kubes/kubectl/fetch/deployment.rb