From 745423ce27b5df2f51c56beff6d18e989c964d91 Mon Sep 17 00:00:00 2001 From: James Hall Date: Fri, 19 Apr 2024 10:44:42 -0400 Subject: [PATCH 1/2] Consider updated pods in StatefulSet#deploy_failed? --- Gemfile | 2 +- lib/krane/kubernetes_resource/stateful_set.rb | 2 +- .../kubernetes_resource/stateful_set_test.rb | 49 +++++++++++++++---- 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/Gemfile b/Gemfile index 351033344..59d7fdccb 100644 --- a/Gemfile +++ b/Gemfile @@ -4,4 +4,4 @@ source 'https://rubygems.org' # Specify your gem's dependencies in krane.gemspec gemspec -gem "ruby-lsp", "~> 0.2.0", :group => :development +gem "ruby-lsp", "~> 0.2.0", group: :development diff --git a/lib/krane/kubernetes_resource/stateful_set.rb b/lib/krane/kubernetes_resource/stateful_set.rb index 4961d6951..fc42bd838 100644 --- a/lib/krane/kubernetes_resource/stateful_set.rb +++ b/lib/krane/kubernetes_resource/stateful_set.rb @@ -65,7 +65,7 @@ def desired_replicas def parent_of_pod?(pod_data) return false unless pod_data.dig("metadata", "ownerReferences") pod_data["metadata"]["ownerReferences"].any? { |ref| ref["uid"] == @instance_data["metadata"]["uid"] } && - @instance_data["status"]["currentRevision"] == pod_data["metadata"]["labels"]["controller-revision-hash"] + @instance_data["status"]["updateRevision"] == pod_data["metadata"]["labels"]["controller-revision-hash"] end def required_rollout diff --git a/test/unit/krane/kubernetes_resource/stateful_set_test.rb b/test/unit/krane/kubernetes_resource/stateful_set_test.rb index 99838f11b..1c3aa2d8b 100644 --- a/test/unit/krane/kubernetes_resource/stateful_set_test.rb +++ b/test/unit/krane/kubernetes_resource/stateful_set_test.rb @@ -41,28 +41,59 @@ def test_deploy_does_not_succeed_when_current_and_observed_generations_do_not_ma refute_predicate(ss, :deploy_succeeded?) end - def test_deploy_failed_not_fooled_by_stale_status_for_rollingupdate_strategy + def test_deploy_failed_not_fooled_by_stale_status status = { "observedGeneration": 1, "readyReplicas": 0, } - ss_template = build_ss_template(status: status, updateStrategy: "RollingUpdate") + ss_template = build_ss_template(status: status) ss = build_synced_ss(ss_template: ss_template) ss.stubs(:pods).returns([stub(deploy_failed?: true)]) refute_predicate(ss, :deploy_failed?) end - def test_deploy_failed_not_fooled_by_stale_status_for_ondelete_strategy - status = { - "observedGeneration": 1, - "readyReplicas": 0, + def test_deploy_failed_ignores_current_pods + current_pod = pod_fixture.deep_merge( + "metadata" => { + "labels" => { + "controller-revision-hash" => "current", + }, + }, + "status" => { + "phase" => "Failed", + }, + ) + + ss_status = { + "observedGeneration" => 2, + "currentRevision" => "current", + "updateRevision" => "updated", } - ss_template = build_ss_template(status: status, updateStrategy: "OnDelete") - ss = build_synced_ss(ss_template: ss_template) - ss.stubs(:pods).returns([stub(deploy_failed?: true)]) + ss = build_synced_ss(ss_template: build_ss_template(status: ss_status), pod_template: current_pod) refute_predicate(ss, :deploy_failed?) end + def test_deploy_failed_considers_updated_pods + updated_pod = pod_fixture.deep_merge( + "metadata" => { + "labels" => { + "controller-revision-hash" => "updated", + }, + }, + "status" => { + "phase" => "Failed", + }, + ) + + ss_status = { + "observedGeneration" => 2, + "currentRevision" => "current", + "updateRevision" => "updated", + } + ss = build_synced_ss(ss_template: build_ss_template(status: ss_status), pod_template: updated_pod) + assert_predicate(ss, :deploy_failed?) + end + private def build_ss_template(status: {}, updateStrategy: "RollingUpdate", rollout: "full") From 13608f6720961bd5251fc3f40e9b4960c7f82078 Mon Sep 17 00:00:00 2001 From: James Hall Date: Fri, 19 Apr 2024 10:48:02 -0400 Subject: [PATCH 2/2] Version 3.5.2 --- CHANGELOG.md | 4 ++++ lib/krane/version.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b10d3974f..219eb9a77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## next +## 3.5.2 + +- Fixed an issue where deploying StatefulSets monitored the health of the previous revision's pods instead of the updated one. + ## 3.5.1 - Fixed successful deployment check for StatefulSets introduced in v3.3.0. diff --git a/lib/krane/version.rb b/lib/krane/version.rb index 826408985..23372a2c5 100644 --- a/lib/krane/version.rb +++ b/lib/krane/version.rb @@ -1,4 +1,4 @@ # frozen_string_literal: true module Krane - VERSION = "3.5.1" + VERSION = "3.5.2" end