Skip to content

Commit

Permalink
Merge pull request #3006 from zendesk/grosser/blue-green
Browse files Browse the repository at this point in the history
PAAS-2251 creating 2 budgets that match a single pod causes alerts du…
  • Loading branch information
grosser authored Oct 17, 2018
2 parents 7cd062b + d085725 commit b390670
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
2 changes: 2 additions & 0 deletions plugins/kubernetes/app/models/kubernetes/release_doc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@ def add_pod_disruption_budget
[replica_target - 1, Integer(min_available)].min
end
target = 0 if target < 0

annotations = (resource.dig(:metadata, :annotations) || {}).dup
annotations[:"samson/updateTimestamp"] = Time.now.utc.iso8601

budget = {
apiVersion: "policy/v1beta1",
kind: "PodDisruptionBudget",
Expand Down
9 changes: 8 additions & 1 deletion plugins/kubernetes/app/models/kubernetes/template_filler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ def to_hash(verification: false)
set_image_pull_secrets
set_resource_blue_green if blue_green_color
set_init_containers
when 'PodDisruptionBudget'
set_name
set_match_labels_blue_green if blue_green_color
else
set_name
end
Expand Down Expand Up @@ -115,10 +118,14 @@ def set_service_blue_green

def set_resource_blue_green
template.dig_set([:metadata, :labels, :blue_green], blue_green_color)
template.dig_set([:spec, :selector, :matchLabels, :blue_green], blue_green_color)
set_match_labels_blue_green
template.dig_set([:spec, :template, :metadata, :labels, :blue_green], blue_green_color)
end

def set_match_labels_blue_green
template.dig_set([:spec, :selector, :matchLabels, :blue_green], blue_green_color)
end

# TODO: unify into with label verification logic in role_validator
def set_project_labels
[
Expand Down
16 changes: 16 additions & 0 deletions plugins/kubernetes/test/models/kubernetes/template_filler_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,15 @@ def secret_annotations(hash)
end
end

describe "PodDisruptionBudget" do
it "modified name" do
raw_template[:kind] = 'PodDisruptionBudget'
hash = template.to_hash
hash.dig_fetch(:metadata, :name).must_equal 'test-app-server'
refute hash.dig(:spec, :selector, :matchLabels).key?(:blue_green)
end
end

describe "blue-green" do
before do
doc.kubernetes_role.blue_green = true
Expand All @@ -789,6 +798,13 @@ def secret_annotations(hash)
hash.dig_fetch(:spec, :selector, :matchLabels, :blue_green).must_equal 'green'
hash.dig_fetch(:spec, :template, :metadata, :labels, :blue_green).must_equal 'green'
end

it "modified budgets so we do not get errors when 2 budgets match the same pod" do
raw_template[:kind] = 'PodDisruptionBudget'
hash = template.to_hash
hash.dig_fetch(:metadata, :name).must_equal 'test-app-server-green'
hash.dig_fetch(:spec, :selector, :matchLabels, :blue_green).must_equal 'green'
end
end
end

Expand Down

0 comments on commit b390670

Please sign in to comment.