Skip to content

Commit

Permalink
Merge pull request #4126 from zendesk/amir/prestop-sleep-action
Browse files Browse the repository at this point in the history
feat: use SleepAction for prestop hooks instead of ExecAction
  • Loading branch information
grosser authored Jan 26, 2025
2 parents e5cfbc0 + b497f5c commit 19f070d
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion plugins/kubernetes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ To make Samson leave your resource name alone, set `metadata.annotations.samson/
When not using kubernetes services to route requests, requests can be lost during a deployment,
since old pods shut down before everyone all clients are refreshed.

To prevent this, samson can automatically add `container[].lifecycle.preStop` `/bin/sleep <INT>`
To prevent this, samson can automatically add `container[].lifecycle.preStop.sleep.seconds: <INT>`
and increase the `spec.terminationGracePeriodSeconds` if necessary.

(will only add if `preStop` hook is not set and pod `metadata.annotations.container-nameofcontainer-samson/preStop` is not set to `disabled` and container has ports)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ def set_pre_stop
# add prestop sleep
sleep_time = Integer(ENV['KUBERNETES_PRESTOP_SLEEP_DURATION'] || '3')
containers.each do |container|
(container[:lifecycle] ||= {})[:preStop] = {exec: {command: ["/bin/sleep", sleep_time.to_s]}}
(container[:lifecycle] ||= {})[:preStop] = {sleep: {seconds: sleep_time}}
end

# shut down after prestop sleeping is done
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ def lifecycle_defined?

it "adds preStop to avoid 502 errors when server addresses are cached for a few seconds" do
template.to_hash.dig_fetch(:spec, :template, :spec, :containers, 0, :lifecycle).must_equal(
preStop: {exec: {command: ["/bin/sleep", "3"]}}
preStop: {sleep: {seconds: 3}}
)
end

Expand Down

0 comments on commit 19f070d

Please sign in to comment.