Class: KubernetesDeploy::RestartTask
- Inherits:
-
Object
- Object
- KubernetesDeploy::RestartTask
- Includes:
- KubeclientBuilder
- 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) ⇒ Object
Constructor Details
#initialize(context:, namespace:, logger:, max_watch_seconds: nil) ⇒ RestartTask
Returns a new instance of RestartTask.
23 24 25 26 27 28 29 |
# File 'lib/kubernetes-deploy/restart_task.rb', line 23 def initialize(context:, namespace:, logger:, max_watch_seconds: nil) @context = context @namespace = namespace @logger = logger @sync_mediator = SyncMediator.new(namespace: @namespace, context: @context, logger: @logger) @max_watch_seconds = max_watch_seconds end |
Instance Method Details
#perform(*args) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/kubernetes-deploy/restart_task.rb', line 31 def perform(*args) perform!(*args) true rescue FatalDeploymentError false end |
#perform!(deployments_names = nil) ⇒ Object
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 70 71 72 |
# File 'lib/kubernetes-deploy/restart_task.rb', line 38 def perform!(deployments_names = nil) start = Time.now.utc @logger.reset @logger.phase_heading("Initializing restart") verify_namespace deployments = identify_target_deployments(deployments_names) 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, sync_mediator: @sync_mediator, logger: @logger, operation_name: "restart", timeout: @max_watch_seconds).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.measure('restart.duration', StatsD.duration(start), tags: ('success', deployments)) @logger.print_summary(:success) rescue DeploymentTimeoutError ::StatsD.measure('restart.duration', StatsD.duration(start), tags: ('timeout', deployments)) @logger.print_summary(:timed_out) raise rescue FatalDeploymentError => error ::StatsD.measure('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 |