Class: DockerRailsProxy::Kubectl::Bash

Inherits:
DockerRailsProxy::Kubectl show all
Defined in:
lib/docker_rails_proxy/commands/kubectl/bash.rb

Constant Summary collapse

UNNEEDED_ATTRIBUTES =
%w[livenessProbe readinessProbe command lifecycle].freeze
ACCEPTED_STATUSES =
%w[Running Failed].freeze

Constants inherited from DockerRailsProxy::Kubectl

KUBECONFIG_PATH

Constants included from Callbacks

Callbacks::INHERITABLE_CALLBACKS, Callbacks::UNINHERITABLE_CALLBACKS

Instance Attribute Summary collapse

Attributes inherited from Base

#additional_arguments, #additional_arguments_options, #arguments

Instance Method Summary collapse

Methods inherited from Base

build_path, call, command, execute, #initialize

Methods included from Logger

included, #logger

Methods included from Rsync

included, #sync

Methods included from Callbacks

included

Methods included from InheritableAttributes

included

Constructor Details

This class inherits a constructor from DockerRailsProxy::Base

Instance Attribute Details

#dataObject

Returns the value of attribute data.



9
10
11
# File 'lib/docker_rails_proxy/commands/kubectl/bash.rb', line 9

def data
  @data
end

Instance Method Details

#processObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/docker_rails_proxy/commands/kubectl/bash.rb', line 21

def process
  overrides = {
    metadata: {
      annotations: {
        'iam.amazonaws.com/role' => data.dig('metadata', 'annotations', 'iam.amazonaws.com/role')
      }
    },
    spec: {
      volumes: data.dig('spec', 'volumes'),
      imagePullSecrets: data.dig('spec', 'imagePullSecrets'),
      securityContext: data.dig('spec', 'securityContext'),
      serviceAccount: data.dig('spec', 'serviceAccount'),
      serviceAccountName: data.dig('spec', 'serviceAccountName'),
      nodeSelector: data.dig('spec', 'nodeSelector'),
      tolerations: data.dig('spec', 'tolerations'),
      affinity: data.dig('spec', 'affinity'),
      containers: [
        container.merge!({
          args: %w[bash],
          stdin: true,
          stdinOnce: true,
          tty: true,
          resources: {
            requests: {
              cpu: '250m',
              memory: '500Mi',
            }
          }
        })
      ]
    }
  }

  pod_name = "#{container['name']}-bash-#{Time.now.strftime '%Y%m%d%H%M%S'}"
  puts "Starting #{pod_name} pod ..."

  kubectl <<-RUN_COMMAND
    run #{pod_name} --rm -i --tty \
      --image='#{container['image']}' \
      --overrides='#{overrides.to_json}'
  RUN_COMMAND
end