Sha256: f2a155d6d3679d92a7dbd1dc25eb8ee4bf2b9f4f2697eddefca06f4efd6caf57

Contents?: true

Size: 1.34 KB

Versions: 7

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

module Kubec
  module Status
    # :nodoc:
    class Deployment < Base
      fields ['Name', 'Desire', 'Current', 'Up to date', 'Available', 'Age']

      # :nodoc:
      class Item < Hash
        FIELDS = %i[name desire current up_to_date available age].freeze

        attr_reader :spec, :metadata, :status

        def initialize(data)
          @data = data
          @metadata = data.dig('metadata')
          @spec = data.dig('spec')
          @status = data.dig('status')

          FIELDS.each { |field| send("setup_#{field}") }
        end

        protected

        def setup_name
          self['Name'] = metadata['name']
        end

        def setup_desire
          self['Desire'] = spec['replicas'] || 1
        end

        def setup_current
          self['Current'] = status['readyReplicas'] || 0
        end

        def setup_up_to_date
          self['Up to date'] = status['updatedReplicas'] || 0
        end

        def setup_available
          self['Available'] = status['availableReplicas'] || 0
        end

        def setup_age
          created_at = DateTime.parse(metadata['creationTimestamp']).to_time
          secs = (Time.now - created_at).ceil
          self['Age'] =
            Utils::HumanizeTime
            .humanize(secs, short: true, join: false).first
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
kubec-0.6.1 lib/kubec/status/deployment.rb
kubec-0.6.0 lib/kubec/status/deployment.rb
kubec-0.5.0 lib/kubec/status/deployment.rb
kubec-0.4.1 lib/kubec/status/deployment.rb
kubec-0.4.0 lib/kubec/status/deployment.rb
kubec-0.3.6 lib/kubec/status/deployment.rb
kubec-0.3.5 lib/kubec/status/deployment.rb