Class: KubernetesDeploy::RestartTask
- Inherits:
-
Object
- Object
- KubernetesDeploy::RestartTask
- Defined in:
- lib/kubernetes-deploy/restart_task.rb
Defined Under Namespace
Classes: FatalRestartError, RestartAPIError
Constant Summary collapse
- HTTP_OK_RANGE =
200..299
- ANNOTATION =
"shipit.shopify.io/restart"
Instance Method Summary collapse
-
#initialize(context:, namespace:, logger: nil, max_watch_seconds: nil) ⇒ RestartTask
constructor
A new instance of RestartTask.
- #run(*args) ⇒ Object (also: #perform)
- #run!(deployments_names = nil, selector: nil, verify_result: true) ⇒ Object (also: #perform!)
Constructor Details
#initialize(context:, namespace:, logger: nil, max_watch_seconds: nil) ⇒ RestartTask
Returns a new instance of RestartTask.
24 25 26 27 28 29 30 |
# File 'lib/kubernetes-deploy/restart_task.rb', line 24 def initialize(context:, namespace:, logger: nil, max_watch_seconds: nil) @logger = logger || KubernetesDeploy::FormattedLogger.build(namespace, context) @task_config = KubernetesDeploy::TaskConfig.new(context, namespace, @logger) @context = context @namespace = namespace @max_watch_seconds = max_watch_seconds end |
Instance Method Details
#run(*args) ⇒ Object Also known as: perform
32 33 34 35 36 37 |
# File 'lib/kubernetes-deploy/restart_task.rb', line 32 def run(*args) perform!(*args) true rescue FatalDeploymentError false end |
#run!(deployments_names = nil, selector: nil, verify_result: true) ⇒ Object Also known as: perform!
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/kubernetes-deploy/restart_task.rb', line 40 def run!(deployments_names = nil, selector: nil, verify_result: true) start = Time.now.utc @logger.reset @logger.phase_heading("Initializing restart") verify_config! deployments = identify_target_deployments(deployments_names, 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.distribution('restart.duration', StatsD.duration(start), tags: ('success', deployments)) @logger.print_summary(:success) rescue DeploymentTimeoutError StatsD.distribution('restart.duration', StatsD.duration(start), tags: ('timeout', deployments)) @logger.print_summary(:timed_out) raise rescue FatalDeploymentError => error StatsD.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 |