feat(e2e): add --run-as flag to run all tests as cluster-admin#574
feat(e2e): add --run-as flag to run all tests as cluster-admin#574midays wants to merge 1 commit into
Conversation
📝 WalkthroughWalkthroughAdds a ChangesRunAs Admin Mode for E2E Tests
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Test Coverage ReportTotal: 47.6% Per-package coverage
Full function-level detailsPosted by CI |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@e2e-tests/framework/rbac.go`:
- Around line 141-145: The partial admin-mode setup in the namespace creation
path can leave the source namespace behind when
scenario.KubectlSrc.CreateNamespace succeeds but
scenario.KubectlTgt.CreateNamespace fails. Update the helper in rbac.go to clean
up the already-created source namespace before returning the target-side error,
using the same namespace variable and the KubectlSrc/KubectlTgt setup flow so
the failure path does not leak resources.
In `@e2e-tests/framework/scenario.go`:
- Around line 34-37: Add focused test coverage for the RunAs context rewrite in
NewMigrationScenario, since the config.RunAs == "admin" branch changes both
non-admin contexts. Create a small table-driven test around NewMigrationScenario
that exercises default mode and admin mode, and assert the resulting
srcNonAdminCtx and tgtNonAdminCtx behavior so the branch is covered and won’t
regress.
In `@e2e-tests/tests/tier0/mta_805_sets_test.go`:
- Around line 49-50: Preserve the existing skip behavior in the MTA 805 test
setup when --run-as is not admin, since SetupActiveKubectlRunners and
SetupNamespaceAdminUsersForScenario still require the non-admin kubectl
contexts. Restore the preflight Skip(...) before calling
SetupActiveKubectlRunners in the test flow so environments without admin mode
continue to be skipped instead of failing. Use the relevant setup path around
SetupActiveKubectlRunners, SetupNamespaceAdminUsersForScenario, and the
Kubectl*NonAdmin.Context handling to locate the change.
In `@e2e-tests/tests/tier0/mta_811_mongodb_non_admin_test.go`:
- Around line 123-124: The non-admin setup path in this test now hard-fails
instead of preserving the previous skip behavior when non-admin contexts are
unset. Update the test around SetupActiveKubectlRunners /
SetupNamespaceAdminUsersForScenario so that when --run-as is not "admin" and
either non-admin context is empty, it skips the test rather than returning an
error, matching the prior behavior when --run-as is not provided.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 0c67c994-672a-4d90-85cb-50de19da1c0a
📒 Files selected for processing (26)
e2e-tests/config/config.goe2e-tests/framework/rbac.goe2e-tests/framework/scenario.goe2e-tests/tests/tier0/e2e_suite_test.goe2e-tests/tests/tier0/mta_804_empty_pvc_migration_test.goe2e-tests/tests/tier0/mta_805_sets_test.goe2e-tests/tests/tier0/mta_806_pvc_data_integrity_test.goe2e-tests/tests/tier0/mta_807_data_validation_test.goe2e-tests/tests/tier0/mta_809_initcontainer_test.goe2e-tests/tests/tier0/mta_810_configmap_test.goe2e-tests/tests/tier0/mta_811_mongodb_non_admin_test.goe2e-tests/tests/tier0/mta_812_role_migration_test.goe2e-tests/tests/tier0/mta_813_cronJob_PVC_test.goe2e-tests/tests/tier0/mta_827_custom_transformation_stage_test.goe2e-tests/tests/tier0/mta_828_instructions_file_migration_test.goe2e-tests/tests/tier0/mta_831_validate_compatible_resources_offline_test.goe2e-tests/tests/tier0/mta_833_compatible_resources_live_test.goe2e-tests/tests/tier0/mta_844_validate_mixed_resources_live_test.goe2e-tests/tests/tier0/mta_845_validate_mixed_resources_offline_test.goe2e-tests/tests/tier0/mta_846_validate_single_incompatible_route_live_test.goe2e-tests/tests/tier1/e2e_suite_test.goe2e-tests/tests/tier1/mta_829_validate_alternative_gv_suggestion_test.goe2e-tests/tests/tier1/mta_830_instructions_file_force_reconcile_test.goe2e-tests/tests/tier1/mta_832_validate_alternative_gv_suggestion_offline_test.goe2e-tests/tests/tier1/mta_836_validate_core_group_omitted_offline_test.goe2e-tests/tests/tier1/mta_850_validate_duplicate_gvk_test.go
💤 Files with no reviewable changes (2)
- e2e-tests/tests/tier0/mta_846_validate_single_incompatible_route_live_test.go
- e2e-tests/tests/tier1/mta_850_validate_duplicate_gvk_test.go
- Added `RunAs` field to the configuration to allow tests to run with cluster-admin credentials. - Updated `SetupActiveNamespaceAdmin` and `SetupActiveKubectlRunners` functions to utilize the new `RunAs` configuration for managing namespace access. - Refactored multiple test cases to replace direct calls to `SetupNamespaceAdminUsersForScenario` with `SetupActiveKubectlRunners`, streamlining the process for both admin and non-admin contexts. - Removed redundant context checks in tests, simplifying the setup process. This change improves flexibility in test execution and aligns with the new configuration structure. Signed-off-by: midays <midays@redhat.com>
43b539a to
b7a9ea8
Compare
|
/rfr |
Add a --run-as=admin flag that overrides all test contexts to use
cluster-admin credentials without modifying individual test files.
Changes:
helpers that bypass RBAC setup in admin mode and log the resolved
username as proof of identity
and replace SetupNamespaceAdminUsersForScenario with
SetupActiveKubectlRunners
When --run-as is omitted, behavior is unchanged.
Jenkins Run
Summary by CodeRabbit
--run-asoption to run end-to-end tests with admin credentials.