Skip to content

Commit d15aa22

Browse files
committed
Add support for unprivileged user on BYOIDC clusters
1 parent b3b9424 commit d15aa22

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

tests/conftest.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,12 +376,19 @@ def kubconfig_filepath() -> str:
376376
return kubeconfig_path
377377

378378

379+
@pytest.fixture(scope="session")
380+
def is_byoidc(pytestconfig: pytest.Config) -> bool:
381+
auth_type = run_command(command="oc get authentication cluster -o jsonpath={.spec.type}".split())[1].strip()
382+
return auth_type == "OIDC"
383+
384+
379385
@pytest.fixture(scope="session")
380386
def unprivileged_client(
381387
admin_client: DynamicClient,
382388
use_unprivileged_client: bool,
383389
kubconfig_filepath: str,
384390
non_admin_user_password: tuple[str, str],
391+
is_byoidc: bool,
385392
) -> Generator[DynamicClient, Any, Any]:
386393
"""
387394
Provides none privileged API client. If non_admin_user_password is None, then it will raise.
@@ -390,6 +397,16 @@ def unprivileged_client(
390397
LOGGER.warning("Unprivileged client is not enabled, using admin client")
391398
yield admin_client
392399

400+
elif is_byoidc:
401+
# this requires a pre-existing context in $KUBECONFIG with a unprivileged user
402+
current_context = run_command(command=["oc", "config", "current-context"])[1].strip()
403+
unprivileged_context = current_context + "-unprivileged"
404+
405+
unprivileged_client = get_client(config_file=kubconfig_filepath, context=unprivileged_context)
406+
407+
yield unprivileged_client
408+
409+
393410
elif non_admin_user_password is None:
394411
raise ValueError("Unprivileged user not provisioned")
395412

0 commit comments

Comments
 (0)