Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: k8s-attach-handlers auto-generated policy #8922

Merged

Conversation

danmihai1
Copy link
Contributor

@danmihai1 danmihai1 commented Jan 25, 2024

Automatically generate the test policy for k8s-attach-handlers.bats, if AUTO_GENERATE_POLICY is enabled.

A few commits are part of this PR - some of them not directly related to k8s-attach-handlers.bats but helpful for easier testing of the k8s-attach-handlers.bats changes.

Fixes: #8921

@danmihai1 danmihai1 added the wip Work in Progress (PR incomplete - needs more work or rework) label Jan 25, 2024
@katacontainersbot katacontainersbot added the size/large Task of significant size label Jan 25, 2024
@danmihai1 danmihai1 force-pushed the danmihai1/k8s-attach-handlers branch 8 times, most recently from 63ec0cb to 94da070 Compare February 2, 2024 02:04
@danmihai1 danmihai1 force-pushed the danmihai1/k8s-attach-handlers branch from 94da070 to 82a74d8 Compare February 2, 2024 16:45
@danmihai1 danmihai1 removed the wip Work in Progress (PR incomplete - needs more work or rework) label Feb 2, 2024
Copy link
Member

@fidencio fidencio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danmihai1, series looks good to me.
I'd like to have @wainersm taking a look at this one as well, if possible.

@@ -139,14 +139,18 @@ test_successful_actions() {
for K8S_TEST_ENTRY in ${K8S_TEST_UNION[@]}
do
info "$(kubectl get pods --all-namespaces 2>&1)"
info "Executing ${K8S_TEST_ENTRY}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately bats doesn't provide an option to print the file name :(

tests/common.bash Outdated Show resolved Hide resolved
tests/common.bash Outdated Show resolved Hide resolved
@wainersm
Copy link
Contributor

wainersm commented Feb 6, 2024

hi @danmihai1 , finish my 1st round of review. Most nits & questions to you :)

@danmihai1 danmihai1 force-pushed the danmihai1/k8s-attach-handlers branch from 1bb9e25 to a68efd4 Compare February 7, 2024 02:13
@danmihai1
Copy link
Contributor Author

hi @danmihai1 , finish my 1st round of review. Most nits & questions to you :)

Thanks for the feedback, @wainersm! I believe I addressed it with my latest push.

Allow everyone to directly execute run_kubernetes_tests.sh, for easier
local testing.

Signed-off-by: Dan Mihai <dmihai@microsoft.com>
1. Avoid repeating "kata-containers-k8s-tests".
2. Allow users to specify a different test namespace.
3. Introduce the TEST_CLUSTER_NAMESPACE variable, that will also be
   useful when auto-generating the Agent Policy for these tests.

Signed-off-by: Dan Mihai <dmihai@microsoft.com>
Make these scripts easier to debug.

Signed-off-by: Dan Mihai <dmihai@microsoft.com>
Output the names of test files, for easier search through logs.

Signed-off-by: Dan Mihai <dmihai@microsoft.com>
Add script functions useful for auto-generating and testing policy.

Signed-off-by: Dan Mihai <dmihai@microsoft.com>
Install the genpolicy app before starting test execution.

Signed-off-by: Dan Mihai <dmihai@microsoft.com>
Enable AUTO_GENERATE_POLICY for one of the Kata CI K8s test platforms.
Additional platforms will be enabled after testing them.

When AUTO_GENERATE_POLICY is enabled, create genpolicy settings that
are common for all tests. Some of the tests will make temporary copies
of these common settings and customize them as needed.

Signed-off-by: Dan Mihai <dmihai@microsoft.com>
Automatically generate the test policy for k8s-attach-handlers.bats,
if AUTO_GENERATE_POLICY is enabled.

Steps:

- Create a temporary directory for the current test and copy the
  common genpolicy settings into this new directory.

- Change genpolicy settings in the temp directory to allow the
  "kubectl exec" command that this test needs. (For CoCo, exec is
  blocked by the default policy settings)

- Auto-generate the policy for the test YAML file.

- Test as usual, using the YAML file.

- Clean-up the temporary settings described above.

Fixes: kata-containers#8921

Signed-off-by: Dan Mihai <dmihai@microsoft.com>
@danmihai1 danmihai1 force-pushed the danmihai1/k8s-attach-handlers branch from a68efd4 to 956577b Compare February 7, 2024 02:27
@fidencio
Copy link
Member

fidencio commented Feb 7, 2024

/test

Copy link
Contributor

@wainersm wainersm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @danmihai1 !

1. Rename install_kata_common to install_kata_core.

2. Add TODO for better way to install the Kata tools.

Signed-off-by: Dan Mihai <dmihai@microsoft.com>
@danmihai1 danmihai1 force-pushed the danmihai1/k8s-attach-handlers branch from 956577b to 6b5e57f Compare February 7, 2024 18:52
@danmihai1
Copy link
Contributor Author

/test

@danmihai1 danmihai1 merged commit 2bb91c9 into kata-containers:main Feb 7, 2024
286 of 293 checks passed
@danmihai1 danmihai1 deleted the danmihai1/k8s-attach-handlers branch March 29, 2024 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ok-to-test size/large Task of significant size
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tests: auto-generated policy for k8s-attach-handlers.bats
5 participants