From 79407c93c98b7db3908993c0b637d0e4503883f7 Mon Sep 17 00:00:00 2001 From: Ben Langfeld Date: Sat, 2 Mar 2019 09:31:36 -0300 Subject: [PATCH] Log deployed resources in alphabetical order for ease of comparison Closes #261 --- CHANGELOG.md | 1 + lib/kubernetes-deploy/deploy_task.rb | 7 ++++--- lib/kubernetes-deploy/kubernetes_resource.rb | 4 ++++ test/integration/kubernetes_deploy_test.rb | 6 +++--- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 73a2e385c..e874cc504 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Arguments to `--bindings` will now be deep merged. ([#419](https://github.com/Shopify/kubernetes-deploy/pull/419)) - `kubernetes-deploy` and `kubernetes-render` now support reading templates from STDIN. ([#415](https://github.com/Shopify/kubernetes-deploy/pull/415)) - Support for specifying a `--selector`, a label with which all deployed resources are expected to have, and by which prunable resources will be filtered. This permits sharing a namespace with resources managed by third-parties, including other kubernetes-deploy deployments. ([#439](https://github.com/Shopify/kubernetes-deploy/pull/439)) +- Lists of resources printed during deployments will now be sorted alphabetically. ([#441](https://github.com/Shopify/kubernetes-deploy/pull/441)) *Features* diff --git a/lib/kubernetes-deploy/deploy_task.rb b/lib/kubernetes-deploy/deploy_task.rb index b45544af2..4da5f8421 100644 --- a/lib/kubernetes-deploy/deploy_task.rb +++ b/lib/kubernetes-deploy/deploy_task.rb @@ -282,7 +282,7 @@ def discover_resources @logger.warn("Detected non-namespaced #{'resource'.pluralize(global.count)} which will never be pruned:") global.each { |r| @logger.warn(" - #{r.id}") } end - resources + resources.sort end measure_method(:discover_resources) @@ -369,6 +369,9 @@ def deploy_resources(resources, prune: false, verify:, record_summary: true) if resources.length > 1 @logger.info("Deploying resources:") + resources.each do |r| + @logger.info("- #{r.id} (#{r.pretty_timeout_type})") + end else resource = resources.first @logger.info("Deploying #{resource.id} (#{resource.pretty_timeout_type})") @@ -381,7 +384,6 @@ def deploy_resources(resources, prune: false, verify:, record_summary: true) applyables += individuals.select { |r| pruneable_types.include?(r.type) } individuals.each do |r| - @logger.info("- #{r.id} (#{r.pretty_timeout_type})") if resources.length > 1 r.deploy_started_at = Time.now.utc case r.deploy_method when :replace @@ -425,7 +427,6 @@ def apply_all(resources, prune) Dir.mktmpdir do |tmp_dir| resources.each do |r| - @logger.info("- #{r.id} (#{r.pretty_timeout_type})") if resources.length > 1 FileUtils.symlink(r.file_path, tmp_dir) r.deploy_started_at = Time.now.utc end diff --git a/lib/kubernetes-deploy/kubernetes_resource.rb b/lib/kubernetes-deploy/kubernetes_resource.rb index c1c8ca984..71abe02fe 100644 --- a/lib/kubernetes-deploy/kubernetes_resource.rb +++ b/lib/kubernetes-deploy/kubernetes_resource.rb @@ -136,6 +136,10 @@ def id "#{type}/#{name}" end + def <=>(other) + id <=> other.id + end + def file_path file.path end diff --git a/test/integration/kubernetes_deploy_test.rb b/test/integration/kubernetes_deploy_test.rb index 6218546eb..ce62b0a04 100644 --- a/test/integration/kubernetes_deploy_test.rb +++ b/test/integration/kubernetes_deploy_test.rb @@ -628,8 +628,8 @@ def test_can_deploy_template_dir_with_only_secrets_ejson assert_logs_match_all([ "Result: SUCCESS", %r{Secret\/catphotoscom\s+Available}, - %r{Secret\/unused-secret\s+Available}, %r{Secret\/monitoring-token\s+Available}, + %r{Secret\/unused-secret\s+Available}, ], in_order: true) end @@ -756,10 +756,10 @@ def test_scale_existing_deployment_down_to_zero hello_cloud.assert_pod_status(pod_name, pod_status, target) assert_logs_match_all([ - %r{Service/web\s+Selects at least 1 pod}, %r{Deployment/web\s+1 replica, 1 updatedReplica, 1 availableReplica}, - %r{Service/web\s+Doesn't require any endpoint}, + %r{Service/web\s+Selects at least 1 pod}, %r{Deployment/web\s+0 replicas}, + %r{Service/web\s+Doesn't require any endpoint}, ], in_order: true) end