Skip to content

Commit

Permalink
Predeploy RoleBinding before unmanaged pods
Browse files Browse the repository at this point in the history
RoleBindings should be deployed before unmanaged pods. This matters when
RoleBindings define Pod Security Policies. This might prevent unmanaged
pods from starting unless RoleBinding has been set up. Regular pods
retry so the race condition would not break anything.
  • Loading branch information
lautis committed Oct 18, 2018
1 parent 58890c9 commit 4c03936
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/kubernetes-deploy/deploy_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class DeployTask
ConfigMap
PersistentVolumeClaim
ServiceAccount
RoleBinding
Pod
)

Expand Down
22 changes: 22 additions & 0 deletions lib/kubernetes-deploy/kubernetes_resource/role_binding.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true
module KubernetesDeploy
class RoleBinding < KubernetesResource
TIMEOUT = 30.seconds

def status
exists? ? "Created" : "Unknown"
end

def deploy_succeeded?
exists?
end

def deploy_failed?
false
end

def timeout_message
UNUSUAL_FAILURE_MESSAGE
end
end
end
12 changes: 12 additions & 0 deletions test/fixtures/hello-cloud/role-binding.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: RoleBinding
metadata:
name: role-binding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: extension-apiserver-authentication-reader
subjects:
- kind: ServiceAccount
name: build-robot
18 changes: 17 additions & 1 deletion test/integration/kubernetes_deploy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def test_full_hello_cloud_set_deploy_succeeds
%r{Deploying Pod/unmanaged-pod-[-\w]+ \(timeout: 60s\)}, # annotation timeout override
"Hello from the command runner!", # unmanaged pod logs
"Result: SUCCESS",
"Successfully deployed 19 resources"
"Successfully deployed 20 resources"
], in_order: true)

assert_logs_match_all([
Expand Down Expand Up @@ -52,6 +52,22 @@ def test_service_account_predeployed_before_unmanaged_pod
], in_order: true)
end

def test_role_binding_predeployed_before_unmanaged_pod
result = deploy_fixtures("hello-cloud",
subset: ["configmap-data.yml", "unmanaged-pod.yml.erb", "role-binding.yml", "service-account.yml"])

# Expect that role binding account is deployed before the unmanaged pod
assert_deploy_success(result)
hello_cloud = FixtureSetAssertions::HelloCloud.new(@namespace)
hello_cloud.assert_configmap_data_present
hello_cloud.assert_all_service_accounts_up
hello_cloud.assert_unmanaged_pod_statuses("Succeeded")
assert_logs_match_all([
%r{Successfully deployed in \d.\ds: RoleBinding/role-binding},
%r{Successfully deployed in \d.\ds: Pod/unmanaged-pod-.*}
], in_order: true)
end

def test_pruning_works
assert_deploy_success(deploy_fixtures("hello-cloud"))
hello_cloud = FixtureSetAssertions::HelloCloud.new(@namespace)
Expand Down

0 comments on commit 4c03936

Please sign in to comment.