lib/vidar/cli.rb in vidar-1.11.0 vs lib/vidar/cli.rb in vidar-1.12.0

- old
+ new

@@ -87,13 +87,15 @@ method_option :revision, required: false method_option :kubectl_context, required: false method_option :destination, required: false, default: "deployments,cronjobs" method_option :container, required: false, default: "*" method_option :all, required: false, type: :boolean, default: true + method_option :max_tries, required: false, default: "30" def deploy revision = options[:revision] || Config.get!(:revision) kubectl_context = options[:kubectl_context] || Config.get!(:kubectl_context) + max_tries = options[:max_tries].to_i Log.info "Current kubectl context: #{kubectl_context}" Log.info "Looking for deploy hook..." template_name, error, status = Open3.capture3 "kubectl get cronjob deploy-hook-template -n #{Config.get!(:namespace)} -o name --ignore-not-found=true" @@ -102,19 +104,12 @@ if status.success? if template_name.to_s.empty? Log.info "No deploy hook found" else - Log.info "Executing deploy hook #{template_name.strip!}..." - Run.kubectl "delete job deploy-hook --ignore-not-found=true" - Run.kubectl "set image cronjobs/deploy-hook-template deploy-hook-template=#{Config.get!(:image)}:#{revision} --all" - Run.kubectl "create job deploy-hook --from=#{template_name}" + deploy_status = run_deploy_hook(template_name:, revision:, max_tries:) - deploy_status = Vidar::DeployStatus.new(namespace: Config.get!(:namespace), filter: "deploy-hook") - deploy_status.wait_until_up - deploy_status.wait_until_completed - unless deploy_status.success? Run.kubectl "describe job deploy-hook" Log.error "Error running deploy hook template" slack_notification.failure if slack_notification.configured? honeycomb_notification.failure @@ -161,18 +156,21 @@ Run.docker_compose "build #{Config.get!(:release_stage_name)}" publish end desc "monitor_deploy_status", "Check is deployment has finished and sends post-deploy notification" + method_option :max_tries, required: false, default: "30" def monitor_deploy_status + max_tries = options[:max_tries].to_i + Log.info "Current kubectl context: #{Config.get!(:kubectl_context)}" - Log.info "Checking if all containers in #{Config.get!(:namespace)} namespace(s) are ready..." + Log.info "Checking if all containers in #{Config.get!(:namespace)} namespace(s) are ready (#{max_tries} tries)..." slack_notification = SlackNotification.get honeycomb_notification = HoneycombNotification.get - deploy_status = Vidar::DeployStatus.new(namespace: Config.get!(:namespace)) + deploy_status = Vidar::DeployStatus.new(namespace: Config.get!(:namespace), max_tries:) deploy_status.wait_until_completed if deploy_status.success? Log.info "OK: All containers are ready" @@ -254,8 +252,22 @@ build_url: Config.build_url, deploy_config: Config.deploy_config ) slack_notification.deliver(message: options[:message]) if slack_notification.configured? + end + + private + + def run_deploy_hook(template_name:, revision:, max_tries:) + Log.info "Executing deploy hook #{template_name.strip!} (#{max_tries} tries)..." + Run.kubectl "delete job deploy-hook --ignore-not-found=true" + Run.kubectl "set image cronjobs/deploy-hook-template deploy-hook-template=#{Config.get!(:image)}:#{revision} --all" + Run.kubectl "create job deploy-hook --from=#{template_name}" + + deploy_status = Vidar::DeployStatus.new(namespace: Config.get!(:namespace), filter: "deploy-hook", max_tries:) + deploy_status.wait_until_up + deploy_status.wait_until_completed + deploy_status end end end