Class: Captive::Commands::OneOffSession
- Inherits:
-
Object
- Object
- Captive::Commands::OneOffSession
- Defined in:
- lib/captive/commands/one_off_session.rb
Overview
Exécute une commande dans un Job one-off qui reprend l'image et l'env de l'app, attaché devant un TTY (humain), en suivant ses logs sinon (agent, CI, pipe).
La session est tirée avant tout le reste et remise à l'appelant pour qu'il l'inscrive au fil, puis elle nomme le Job. Un one-off abandonné avant même sa création laisse donc une entrée qui pointe vers un log simplement vide, jamais vers la session d'un autre.
Instance Method Summary collapse
- #attach(app, command) ⇒ Object
-
#initialize(kubectl:, banner: UI::Banner.new, session_id: SessionId, tty: Terminal.method(:interactive?)) ⇒ OneOffSession
constructor
A new instance of OneOffSession.
- #interactive? ⇒ Boolean
-
#run(app, command, ®ister) ⇒ Integer?
Exit code of the one-off command (nil when attached).
Constructor Details
#initialize(kubectl:, banner: UI::Banner.new, session_id: SessionId, tty: Terminal.method(:interactive?)) ⇒ OneOffSession
Returns a new instance of OneOffSession.
17 18 19 20 21 22 |
# File 'lib/captive/commands/one_off_session.rb', line 17 def initialize(kubectl:, banner: UI::Banner.new, session_id: SessionId, tty: Terminal.method(:interactive?)) @kubectl = kubectl @banner = @session_id = session_id @tty = tty end |
Instance Method Details
#attach(app, command) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/captive/commands/one_off_session.rb', line 33 def attach(app, command) session = @session_id.generate.tap { |id| yield id } @banner.show(app) job = create_job(app, command, session, interactive: true) pod = @kubectl.wait_job_pod(app, job) begin @kubectl.wait_pod_ready(app, pod) @kubectl.attach(app, pod) ensure cleanup(app, job, pod) end end |
#interactive? ⇒ Boolean
24 25 26 |
# File 'lib/captive/commands/one_off_session.rb', line 24 def interactive? @tty.call end |
#run(app, command, ®ister) ⇒ Integer?
Returns exit code of the one-off command (nil when attached).
29 30 31 |
# File 'lib/captive/commands/one_off_session.rb', line 29 def run(app, command, ®ister) interactive? ? attach(app, command, ®ister) : stream(app, command, ®ister) end |