Skip to content

Commit

Permalink
Fix StatefulSet#deploy_succeeded? for OnDelete
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesOwenHall committed Apr 2, 2024
1 parent d4ac4d0 commit 5ea1e35
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
4 changes: 0 additions & 4 deletions lib/krane/kubernetes_resource/stateful_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ def status
def deploy_succeeded?
success = observed_generation == current_generation

@pods.each do |pod|
success &= pod.definition["metadata"]["labels"]["controller-revision-hash"] == status_data['updateRevision']
end

if update_strategy == 'RollingUpdate'
success &= status_data['currentRevision'] == status_data['updateRevision']
success &= desired_replicas == status_data['readyReplicas'].to_i
Expand Down
23 changes: 12 additions & 11 deletions test/unit/krane/kubernetes_resource/stateful_set_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@
class StatefulSetTest < Krane::TestCase
include ResourceCacheTestHelper

def test_deploy_succeeded_when_revision_matches_for_rollingupdate_strategy
ss_template = build_ss_template(updateStrategy: "RollingUpdate", rollout: nil)
def test_deploy_succeeded_true_with_rolling_update_strategy
ss = build_synced_ss(ss_template: build_ss_template)
assert_predicate(ss, :deploy_succeeded?)
end

def test_deploy_succeeded_true_with_on_delete_strategy_and_no_rollout_annotation
# OnDelete strategy without rollout annotation should always succeed.
# Change the updateRevision to ensure it's not being used to determine success.
ss_template = build_ss_template(status: { "updateRevision": 3 }, updateStrategy: "OnDelete", rollout: nil)
ss = build_synced_ss(ss_template: ss_template)
assert_predicate(ss, :deploy_succeeded?)
end

def test_deploy_succeeded_when_revision_matches_for_ondelete_strategy_without_annotation
ss_template = build_ss_template(updateStrategy: "OnDelete", rollout: nil)
def test_deploy_succeeded_true_with_on_delete_strategy_and_full_rollout_annotation
ss_template = build_ss_template(status: { "updateRevision": 3 }, updateStrategy: "OnDelete", rollout: nil)
ss = build_synced_ss(ss_template: ss_template)
assert_predicate(ss, :deploy_succeeded?)
end
Expand All @@ -34,19 +41,13 @@ def test_deploy_does_not_succeed_when_replica_counts_do_not_match_for_ondelete_s
refute_predicate(ss, :deploy_succeeded?)
end

def test_deploy_succeeded_when_replica_counts_match_for_rollingupdate_strategy
ss_template = build_ss_template(updateStrategy: "RollingUpdate", rollout: nil)
ss = build_synced_ss(ss_template: ss_template)
assert_predicate(ss, :deploy_succeeded?)
end

def test_deploy_does_not_succeed_when_replica_counts_do_not_match_for_rollingupdate_strategy
ss_template = build_ss_template(status: { "currentReplicas": 1 }, updateStrategy: "RollingUpdate", rollout: nil)
ss = build_synced_ss(ss_template: ss_template)
refute_predicate(ss, :deploy_succeeded?)
end

def test_deploy_fails_when_current_and_observed_generations_do_not_match
def test_deploy_does_not_succeed_when_current_and_observed_generations_do_not_match
ss_template = build_ss_template(status: { "observedGeneration": 1 })
ss = build_synced_ss(ss_template: ss_template)
refute_predicate(ss, :deploy_succeeded?)
Expand Down

0 comments on commit 5ea1e35

Please sign in to comment.