Skip to content

Commit

Permalink
Fix role setting on secretes, still need to do integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
welpaolo committed Mar 27, 2024
1 parent 4a88a55 commit 538c0f0
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 20 deletions.
21 changes: 21 additions & 0 deletions spark8t/resources/templates/role_yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,24 @@ rules:
- list
- watch
- delete
- deletecollection
- update
- patch
- apiGroups:
- ""
resources:
- secrets
resourceNames:
- spark8t-sa-conf-{{username}}
verbs:
- get
- patch
- update
- apiGroups:
- ""
resources:
- secrets
resourceNames:
- configuration-hub-conf-{{username}}
verbs:
- get
31 changes: 21 additions & 10 deletions spark8t/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,26 @@ def create(
self.exec(
f"create {resource_type} {resource_name}", namespace=None, output="name"
)
elif resource_type == KubernetesResourceType.ROLE:
with open(self.defaults.template_role) as f:
res = codecs.load_all_yaml(
f,
context=filter_none(
{
"resourcename": resource_name,
"namespace": namespace,
}
| extra_args
),
)
with umask_named_temporary_file(
mode="w",
prefix="role-",
suffix=".yaml",
dir=os.path.expanduser("~"),
) as t:
codecs.dump_all_yaml(res, t)
self.exec(f"apply -f {t.name}", namespace=namespace, output="name")
else:
# NOTE: removing 'username' to avoid interference with KUBECONFIG
# ERROR: more than one authentication method found for admin; found [token basicAuth], only one is allowed
Expand Down Expand Up @@ -1281,16 +1301,7 @@ def create(self, service_account: ServiceAccount) -> str:
KubernetesResourceType.ROLE,
rolename,
namespace=service_account.namespace,
**{
"resource": [
"pods",
"configmaps",
"services",
"serviceaccounts",
"secrets",
],
"verb": ["create", "get", "list", "watch", "delete"],
},
**{"username": username},
)
self.kube_interface.create(
KubernetesResourceType.ROLEBINDING,
Expand Down
12 changes: 2 additions & 10 deletions tests/unittest/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,7 @@ def side_effect(*args, **kwargs):

with patch("builtins.open", mock_open(read_data=kubeconfig_yaml_str)):
k = LightKube(kube_config_file=kubeconfig, defaults=defaults)
print(f"rn: {resource_name}, namespace: {namespace}")
k.create(
KubernetesResourceType.ROLEBINDING,
resource_name,
Expand Down Expand Up @@ -1408,16 +1409,7 @@ def test_k8s_registry_create(mocker):
"role",
f"{name3}-role",
namespace=namespace3,
**{
"resource": [
"pods",
"configmaps",
"services",
"serviceaccounts",
"secrets",
],
"verb": ["create", "get", "list", "watch", "delete"],
},
**{"username": f"{name3}"},
)

mock_kube_interface.create.assert_any_call(
Expand Down

0 comments on commit 538c0f0

Please sign in to comment.