Skip to content

Commit

Permalink
Merge pull request #3023 from zendesk/grosser/shard-replicas
Browse files Browse the repository at this point in the history
set replica on nested deplyment templates to support sharded deployme…
  • Loading branch information
grosser authored Oct 29, 2018
2 parents 4705d7e + 563effa commit b23a8cc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
18 changes: 12 additions & 6 deletions plugins/kubernetes/app/models/kubernetes/template_filler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ def to_hash(verification: false)
set_history_limit
end

if ['StatefulSet', 'Deployment'].include?(kind)
set_replica_target
else
validate_replica_target_is_supported
end
set_replica_target || validate_replica_target_is_supported

make_stateful_set_match_service if kind == 'StatefulSet'
set_pre_stop if kind == 'Deployment'
Expand Down Expand Up @@ -278,7 +274,17 @@ def set_rc_unique_label_key
end

def set_replica_target
template.dig_set [:spec, :replicas], @doc.replica_target
key = [:spec, :replicas]
target =
if ['StatefulSet', 'Deployment'].include?(template[:kind])
template
else
# custom resource that has replicas set on itself or it's template
containers = [template] + (template[:spec] || {}).values_at(*RoleConfigFile.template_keys(template))
containers.detect { |c| c.dig(*key) }
end

target&.dig_set key, @doc.replica_target
end

def validate_replica_target_is_supported
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@ def add_init_container(container)
template.to_hash[:metadata][:name].must_equal "test-app-server"
end

it "sets replicas for templates" do
raw_template[:kind] = "foobar"
raw_template[:spec].delete :replicas
raw_template[:spec][:template][:spec][:replicas] = 1
result = template.to_hash
result[:spec][:replicas].must_be_nil
result[:spec][:template][:spec][:replicas].must_equal 2
end

['CustomResourceDefinition', 'APIService'].each do |kind|
it "does not set override name for #{kind} since it follows a fixed naming pattern" do
raw_template[:kind] = kind
Expand Down

0 comments on commit b23a8cc

Please sign in to comment.