Class: Krane::RestartTask
- Inherits:
-
Object
- Object
- Krane::RestartTask
- Defined in:
- lib/krane/restart_task.rb
Overview
Restart the pods in one or more deployments
Defined Under Namespace
Classes: FatalRestartError, RestartAPIError
Constant Summary collapse
- HTTP_OK_RANGE =
200..299
- ANNOTATION =
"shipit.shopify.io/restart"
Instance Attribute Summary collapse
-
#task_config ⇒ Object
readonly
Returns the value of attribute task_config.
Instance Method Summary collapse
-
#initialize(context:, namespace:, logger: nil, global_timeout: nil, kubeconfig: nil) ⇒ RestartTask
constructor
Initializes the restart task.
-
#run(**args) ⇒ Boolean
(also: #perform)
Runs the task, returning a boolean representing success or failure.
-
#run!(deployments: nil, selector: nil, verify_result: true) ⇒ nil
(also: #perform!)
Runs the task, raising exceptions in case of issues.
Constructor Details
#initialize(context:, namespace:, logger: nil, global_timeout: nil, kubeconfig: nil) ⇒ RestartTask
Initializes the restart task
35 36 37 38 39 40 41 |
# File 'lib/krane/restart_task.rb', line 35 def initialize(context:, namespace:, logger: nil, global_timeout: nil, kubeconfig: nil) @logger = logger || Krane::FormattedLogger.build(namespace, context) @task_config = Krane::TaskConfig.new(context, namespace, @logger, kubeconfig) @context = context @namespace = namespace @global_timeout = global_timeout end |
Instance Attribute Details
#task_config ⇒ Object (readonly)
Returns the value of attribute task_config.
25 26 27 |
# File 'lib/krane/restart_task.rb', line 25 def task_config @task_config end |
Instance Method Details
#run(**args) ⇒ Boolean Also known as: perform
Runs the task, returning a boolean representing success or failure
46 47 48 49 50 51 |
# File 'lib/krane/restart_task.rb', line 46 def run(**args) perform!(**args) true rescue FatalDeploymentError false end |
#run!(deployments: nil, selector: nil, verify_result: true) ⇒ nil Also known as: perform!
Runs the task, raising exceptions in case of issues
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 86 87 88 89 90 91 |
# File 'lib/krane/restart_task.rb', line 61 def run!(deployments: nil, selector: nil, verify_result: true) start = Time.now.utc @logger.reset @logger.phase_heading("Initializing restart") verify_config! deployments = identify_target_deployments(deployments, selector: selector) @logger.phase_heading("Triggering restart by touching ENV[RESTARTED_AT]") patch_kubeclient_deployments(deployments) if verify_result @logger.phase_heading("Waiting for rollout") resources = build_watchables(deployments, start) verify_restart(resources) else warning = "Result verification is disabled for this task" @logger.summary.add_paragraph(ColorizedString.new(warning).yellow) end StatsD.client.distribution('restart.duration', StatsD.duration(start), tags: ('success', deployments)) @logger.print_summary(:success) rescue DeploymentTimeoutError StatsD.client.distribution('restart.duration', StatsD.duration(start), tags: ('timeout', deployments)) @logger.print_summary(:timed_out) raise rescue FatalDeploymentError => error StatsD.client.distribution('restart.duration', StatsD.duration(start), tags: ('failure', deployments)) @logger.summary.add_action(error.) if error. != error.class.to_s @logger.print_summary(:failure) raise end |