Skip to content

Commit

Permalink
Assume no strategy is rollingUpdate on Vallidation (#289)
Browse files Browse the repository at this point in the history
* Assume no strategy is rollingUpdate during validation
  • Loading branch information
dturn committed Jun 1, 2018
1 parent eed1403 commit 4d2adff
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/kubernetes-deploy/kubernetes_resource/deployment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def validate_definition(_)
end

strategy = @definition.dig('spec', 'strategy', 'type').to_s
if required_rollout.downcase == 'maxunavailable' && strategy.downcase != 'rollingupdate'
if required_rollout.downcase == 'maxunavailable' && strategy.present? && strategy.downcase != 'rollingupdate'
@validation_errors << "'#{REQUIRED_ROLLOUT_ANNOTATION}: #{required_rollout}' is incompatible "\
"with strategy '#{strategy}'"
end
Expand Down
15 changes: 15 additions & 0 deletions test/unit/kubernetes-deploy/kubernetes_resource/deployment_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,17 @@ def test_validation_fails_with_invalid_mix_of_annotation
assert_equal expected, deploy.validation_error_msg
end

def test_validation_works_with_no_strategy_and_max_unavailable_annotation
deploy = build_synced_deployment(
template: build_deployment_template(rollout: 'maxUnavailable', strategy: nil),
replica_sets: [build_rs_template]
)
kubectl.expects(:run).with('create', '-f', anything, '--dry-run', '--output=name', anything).returns(
["", "", SystemExit.new(0)]
)
assert deploy.validate_definition(kubectl)
end

def test_deploy_succeeded_not_fooled_by_stale_rs_data_in_deploy_status
deployment_status = {
"replicas" => 3,
Expand Down Expand Up @@ -347,6 +358,10 @@ def build_deployment_template(status: { 'replicas' => 3 }, rollout: nil,
result["spec"]["strategy"] = { "type" => strategy }
end

if strategy.nil?
result["spec"]["strategy"] = nil
end

if max_unavailable
result["spec"]["strategy"]["rollingUpdate"] = { "maxUnavailable" => max_unavailable }
end
Expand Down

0 comments on commit 4d2adff

Please sign in to comment.