Skip to content

Commit

Permalink
# This is a combination of 2 commits.
Browse files Browse the repository at this point in the history
# This is the 1st commit message:

New tests

# This is the commit message #2:

Rework restart test
  • Loading branch information
dturn committed Jan 11, 2018
1 parent d6004c1 commit b58d56f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 27 deletions.
19 changes: 8 additions & 11 deletions test/fixtures/slow-cloud/web.yml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,29 @@ metadata:
shipit.shopify.io/restart: "true"
kubernetes-deploy.shopify.io/required-rollout: maxUnavailable
spec:
replicas: 3
replicas: 2
selector:
matchLabels:
name: web
app: slow-cloud
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxSurge: 0
maxUnavailable: 1
template:
metadata:
labels:
name: web
app: slow-cloud
sha: "<%= current_sha %>"
spec:
terminationGracePeriodSeconds: 0
containers:
- name: app
readinessProbe:
exec:
command:
- sleep
- '7'
timeoutSeconds: 10
image: busybox
imagePullPolicy: IfNotPresent
command: ["tail", "-f", "/dev/null"]
ports:
- containerPort: 80
name: http
env:
- name: GITHUB_REV
value: <%= current_sha %>
22 changes: 17 additions & 5 deletions test/integration/kubernetes_deploy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -689,15 +689,27 @@ def test_can_deploy_deployment_with_zero_replicas
end

def test_deploy_successful_with_partial_availability
result = deploy_fixtures("slow-cloud")
result = deploy_fixtures("slow-cloud", sha: "deploy1")
assert_deploy_success(result)

result = deploy_fixtures("slow-cloud")
result = deploy_fixtures("slow-cloud", sha: "deploy2") do |fixtures|
dep = fixtures["web.yml.erb"]["Deployment"].first
container = dep["spec"]["template"]["spec"]["containers"].first
container["readinessProbe"] = {
"exec" => { "command" => %w(sleep 5) },
"timeoutSeconds" => 6
}
end
assert_deploy_success(result)

assert_logs_match_all(
[%r{Deployment\/web\s+[34] replicas, 3 updatedReplicas, 2 availableReplicas, [12] unavailableReplica}]
)
new_pods = kubeclient.get_pods(namespace: @namespace, label_selector: 'name=web,app=slow-cloud,sha=deploy2')
assert new_pods.length >= 1, "Expected at least one new pod, saw #{new_pods.length}"

new_ready_pods = new_pods.select do |pod|
pod.status.phase == "Running" &&
pod.status.conditions.any? { |condition| condition["type"] == "Ready" && condition["status"] == "True" }
end
assert_equal 1, new_ready_pods.length, "Expected exactly one new pod to be ready, saw #{new_ready_pods.length}"
end

def test_deploy_aborts_immediately_if_metadata_name_missing
Expand Down
27 changes: 16 additions & 11 deletions test/integration/restart_task_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,23 +209,28 @@ def test_restart_failure
def test_restart_successful_with_partial_availability
result = deploy_fixtures("slow-cloud") do |fixtures|
web = fixtures["web.yml.erb"]["Deployment"].first
web["spec"]["strategy"]['rollingUpdate']['maxUnavailable'] = '34%'
web["spec"]["strategy"]['rollingUpdate']['maxUnavailable'] = '50%'
container = web["spec"]["template"]["spec"]["containers"].first
container["readinessProbe"] = {
"exec" => { "command" => %w(sleep 5) },
"timeoutSeconds" => 6
}
end
assert_deploy_success(result)

restart = build_restart_task
assert_restart_success(restart.perform(["web"]))

assert_logs_match_all([
"Configured to restart deployments by name: web",
"Triggered `web` restart",
"Waiting for rollout",
%r{Successfully restarted in \d+\.\d+s: Deployment/web},
"Result: SUCCESS",
"Successfully restarted 1 resource",
%r{Deployment\/web\s+[34] replicas, 3 updatedReplicas, 2 availableReplicas, [12] unavailableReplica}
],
in_order: true)
pods = kubeclient.get_pods(namespace: @namespace, label_selector: 'name=web,app=slow-cloud')
new_pods = pods.select { |pod| pod.spec.containers.select { |c| c["name"] == "app" && c.env&.find { |n| n.name == "RESTARTED_AT" } } }
assert new_pods.length >= 1, "Expected at least one new pod, saw #{new_pods.length}"

new_ready_pods = new_pods.select do |pod|
pod.status.phase == "Running" &&
pod.status.conditions.any? { |condition| condition["type"] == "Ready" && condition["status"] == "True" } &&
pod.spec.containers.detect { |c| c["name"] == "app" && c.env&.find { |n| n.name == "RESTARTED_AT" } }
end
assert_equal 1, new_ready_pods.length, "Expected exactly one new pod to be ready, saw #{new_ready_pods.length}"

assert fetch_restarted_at("web"), "RESTARTED_AT is present after the restart"
end
Expand Down

0 comments on commit b58d56f

Please sign in to comment.