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:, max_watch_seconds: nil) ⇒ RestartTask
constructor
A new instance of RestartTask.
- #perform(*args) ⇒ Object
- #perform!(deployments_names = nil, selector: nil) ⇒ Object
Constructor Details
#initialize(context:, namespace:, logger:, max_watch_seconds: nil) ⇒ RestartTask
Returns a new instance of RestartTask.
21 22 23 24 25 26 |
# File 'lib/kubernetes-deploy/restart_task.rb', line 21 def initialize(context:, namespace:, logger:, max_watch_seconds: nil) @context = context @namespace = namespace @logger = logger @max_watch_seconds = max_watch_seconds end |
Instance Method Details
#perform(*args) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/kubernetes-deploy/restart_task.rb', line 28 def perform(*args) perform!(*args) true rescue FatalDeploymentError false end |
#perform!(deployments_names = nil, selector: nil) ⇒ Object
35 36 37 38 39 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 |
# File 'lib/kubernetes-deploy/restart_task.rb', line 35 def perform!(deployments_names = nil, selector: nil) start = Time.now.utc @logger.reset @logger.phase_heading("Initializing restart") verify_namespace deployments = identify_target_deployments(deployments_names, selector: selector) if kubectl.server_version < Gem::Version.new(MIN_KUBE_VERSION) @logger.warn(KubernetesDeploy::Errors.server_version_warning(kubectl.server_version)) end @logger.phase_heading("Triggering restart by touching ENV[RESTARTED_AT]") patch_kubeclient_deployments(deployments) @logger.phase_heading("Waiting for rollout") resources = build_watchables(deployments, start) ResourceWatcher.new(resources: resources, logger: @logger, operation_name: "restart", timeout: @max_watch_seconds, namespace: @namespace, context: @context).run failed_resources = resources.reject(&:deploy_succeeded?) success = failed_resources.empty? if !success && failed_resources.all?(&:deploy_timed_out?) raise DeploymentTimeoutError end raise FatalDeploymentError unless success 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 |