Class: KubernetesDeploy::RunnerTask
- Inherits:
-
Object
- Object
- KubernetesDeploy::RunnerTask
- Defined in:
- lib/kubernetes-deploy/runner_task.rb
Overview
Run a pod that exits upon completing a task
Defined Under Namespace
Classes: TaskTemplateMissingError
Instance Attribute Summary collapse
-
#pod_name ⇒ Object
readonly
Returns the value of attribute pod_name.
Instance Method Summary collapse
-
#initialize(namespace:, context:, logger: nil, max_watch_seconds: nil) ⇒ RunnerTask
constructor
Initializes the runner task.
-
#run(*args) ⇒ Boolean
Runs the task, returning a boolean representing success or failure.
-
#run!(task_template:, entrypoint:, args:, env_vars: [], verify_result: true) ⇒ nil
Runs the task, raising exceptions in case of issues.
Constructor Details
#initialize(namespace:, context:, logger: nil, max_watch_seconds: nil) ⇒ RunnerTask
Initializes the runner task
26 27 28 29 30 31 32 |
# File 'lib/kubernetes-deploy/runner_task.rb', line 26 def initialize(namespace:, context:, logger: nil, max_watch_seconds: nil) @logger = logger || KubernetesDeploy::FormattedLogger.build(namespace, context) @task_config = KubernetesDeploy::TaskConfig.new(context, namespace, @logger) @namespace = namespace @context = context @max_watch_seconds = max_watch_seconds end |
Instance Attribute Details
#pod_name ⇒ Object (readonly)
Returns the value of attribute pod_name.
18 19 20 |
# File 'lib/kubernetes-deploy/runner_task.rb', line 18 def pod_name @pod_name end |
Instance Method Details
#run(*args) ⇒ Boolean
Runs the task, returning a boolean representing success or failure
37 38 39 40 41 42 |
# File 'lib/kubernetes-deploy/runner_task.rb', line 37 def run(*args) run!(*args) true rescue DeploymentTimeoutError, FatalDeploymentError false end |
#run!(task_template:, entrypoint:, args:, env_vars: [], verify_result: true) ⇒ nil
Runs the task, raising exceptions in case of issues
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/kubernetes-deploy/runner_task.rb', line 53 def run!(task_template:, entrypoint:, args:, env_vars: [], verify_result: true) start = Time.now.utc @logger.reset @logger.phase_heading("Initializing task") @logger.info("Validating configuration") verify_config!(task_template, args) @logger.info("Using namespace '#{@namespace}' in context '#{@context}'") pod = build_pod(task_template, entrypoint, args, env_vars, verify_result) validate_pod(pod) @logger.phase_heading("Running pod") create_pod(pod) if verify_result @logger.phase_heading("Streaming logs") watch_pod(pod) else record_status_once(pod) end StatsD.distribution('task_runner.duration', StatsD.duration(start), tags: ('success')) @logger.print_summary(:success) rescue DeploymentTimeoutError StatsD.distribution('task_runner.duration', StatsD.duration(start), tags: ('timeout')) @logger.print_summary(:timed_out) raise rescue FatalDeploymentError StatsD.distribution('task_runner.duration', StatsD.duration(start), tags: ('failure')) @logger.print_summary(:failure) raise end |