Sha256: a1efd8f189b4b6036a8a78c4468c17fb036a06646690b2bd6e707a58ff86381d

Contents?: true

Size: 1.46 KB

Versions: 7

Compression:

Stored size: 1.46 KB

Contents

module Seira
  class Helpers
    include Seira::Commands

    class << self
      def rails_env(context:)
        if context[:cluster] == 'internal'
          'production'
        else
          context[:cluster]
        end
      end

      def fetch_pods(filters:, context:)
        filter_string = { app: context[:app] }.merge(filters).map { |k, v| "#{k}=#{v}" }.join(',')
        output = Seira::Commands.kubectl("get pods -o json --selector=#{filter_string}", context: context, return_output: true)
        JSON.parse(output)['items']
      end

      def fetch_pod(name, context:)
        output = Seira::Commands.kubectl("get pod #{name} -o json", context: context, return_output: true)
        JSON.parse(output) unless output.empty?
      end

      def log_link(context:, query:)
        link = context[:settings].log_link_format
        return nil if link.nil?
        link.gsub! 'APP', context[:app]
        link.gsub! 'CLUSTER', context[:cluster]
        link.gsub! 'QUERY', query
        link
      end

      def get_secret(key:, context:)
        Secrets.new(app: context[:app], action: 'get', args: [], context: context).get(key)
      end

      def get_current_replicas(deployment:, context:)
        output = Seira::Commands.kubectl("get deployment #{deployment} -o json", context: context, return_output: true)
        JSON.parse(output)['spec']['replicas']
      end

      def shell_username
        `whoami`
      rescue
        'unknown'
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
seira-0.5.3 lib/helpers.rb
seira-0.5.2 lib/helpers.rb
seira-0.5.1 lib/helpers.rb
seira-0.5.0 lib/helpers.rb
seira-0.4.10 lib/helpers.rb
seira-0.4.9 lib/helpers.rb
seira-0.4.8 lib/helpers.rb