Skip to content

Commit

Permalink
Test role bindings in fixture sets
Browse files Browse the repository at this point in the history
  • Loading branch information
lautis committed Oct 27, 2018
1 parent 4c03936 commit 3de9a14
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/kubernetes-deploy/kubeclient_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ def build_autoscaling_v1_kubeclient(context)
)
end

def build_rbac_v1beta1_kubeclient(context)
_build_kubeclient(
api_version: "v1",
context: context,
endpoint_path: "/apis/rbac.authorization.k8s.io"
)
end

def _build_kubeclient(api_version:, context:, endpoint_path: nil)
# Find a context defined in kube conf files that matches the input context by name
friendly_configs = config_files.map { |f| GoogleFriendlyConfig.read(f) }
Expand Down
6 changes: 6 additions & 0 deletions test/helpers/fixture_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ def assert_service_account_present(name)
assert desired.present?, "Service account #{name} does not exist"
end

def assert_role_binding_present(name)
role_bindings = rbac_v1beta1_kubeclient.get_role_bindings(namespace: namespace)
desired = role_bindings.find { |sa| sa.metadata.name == name }
assert desired.present?, "Role binding #{name} does not exist"
end

def assert_annotated(obj, annotation)
annotations = obj.metadata.annotations.to_h.stringify_keys
assert annotations.key?(annotation), "Expected secret to have annotation #{annotation}, but it did not"
Expand Down
5 changes: 5 additions & 0 deletions test/helpers/fixture_sets/hello_cloud.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def assert_all_up
assert_poddisruptionbudget
assert_bare_replicaset_up
assert_all_service_accounts_up
assert_all_role_bindings_up
assert_daemon_set_up
assert_stateful_set_up
assert_job_up
Expand Down Expand Up @@ -88,6 +89,10 @@ def assert_all_service_accounts_up
assert_service_account_present("build-robot")
end

def assert_all_role_bindings_up
assert_role_binding_present("role-binding")
end

def assert_daemon_set_up
assert_daemon_set_present("ds-app")
end
Expand Down
4 changes: 4 additions & 0 deletions test/helpers/kubeclient_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ def apiextensions_v1beta1_kubeclient
def autoscaling_v1_kubeclient
@autoscaling_v1_kubeclient ||= build_autoscaling_v1_kubeclient(MINIKUBE_CONTEXT)
end

def rbac_v1beta1_kubeclient
@rbac_v1beta1_kubeclient ||= build_rbac_v1beta1_kubeclient(TEST_CONTEXT)
end
end
1 change: 1 addition & 0 deletions test/integration/kubernetes_deploy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def test_role_binding_predeployed_before_unmanaged_pod
hello_cloud = FixtureSetAssertions::HelloCloud.new(@namespace)
hello_cloud.assert_configmap_data_present
hello_cloud.assert_all_service_accounts_up
hello_cloud.assert_all_role_bindings_up
hello_cloud.assert_unmanaged_pod_statuses("Succeeded")
assert_logs_match_all([
%r{Successfully deployed in \d.\ds: RoleBinding/role-binding},
Expand Down

0 comments on commit 3de9a14

Please sign in to comment.