class DockerRailsProxy::Kubectl::Bash
Constants
- UNNEEDED_ATTRIBUTES
Attributes
data[RW]
Public Instance Methods
process()
click to toggle source
# File lib/docker_rails_proxy/commands/kubectl/bash.rb, line 20 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
Private Instance Methods
cloned_pod_name()
click to toggle source
# File lib/docker_rails_proxy/commands/kubectl/bash.rb, line 65 def cloned_pod_name @cloned_pod_name ||= begin pods = kubectl_output(<<-GET_PODS).split(" ") get pods -o jsonpath='{range .items[*]}{.metadata.name},{.status.phase}{" "}{end}'} GET_PODS pods = pods.map do |values| name, phase = values.split(',') phase == 'Running' ? name : nil end.compact until_get_option(pods, "Choose a pod and press [ENTER]") end end
container()
click to toggle source
# File lib/docker_rails_proxy/commands/kubectl/bash.rb, line 80 def container @container ||= begin containers = data.dig('spec', 'containers') if containers.size > 1 names = containers.map { |container| container['name'] } name = until_get_option(names, "Choose a container and press [ENTER]") containers.find { |container| container['name'] == name } else containers.first end end end