1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-06 07:57:07 +00:00
kyverno/test/conformance/kuttl
Vishal Choudhary e2469415b7
feat: add support for custom sigstore using TUF (#8385)
* feat; add support for custom sigstore using TUF

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: add kuttl test

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: add commit hash

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: add kyverno.yaml

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: update kyverno deployment

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: update ordering

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: update deployment

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: update create image step

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: remove wait step

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: install crane

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: set sha on install crane

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: add cosign installer

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: update custom deployment

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: helm chart linting

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: update Chart.yaml

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* fix: helm values liniting error

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: remove step

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: kind-deploy-kyverno

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: create configmap in kyverno namespace

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: update policy

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: create kyverno ns

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: use envfrom

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* fix: indentation

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: update tuf root

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: add sigstore volume

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: nit

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: remove tuf root

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: use default tuf instead :(

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: update Create kind cluster

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: remove root

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: update impl

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: nit

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: use custom test

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: remove force

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: cosign initialize

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: add yes flag

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* update manifest

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: move tuf to features

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: update comments

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* chore: helmchart generate

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: trailing white space

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: remove old fields

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: decouple env config map from tuf

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* change the way we pass flags

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* fix: re add envConfigMap

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* fix env vars

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* remove envConfigMap

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* fix

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

---------

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
Co-authored-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
2023-09-18 13:16:08 +00:00
..
_aaa_template_resources feat: template for user setup in kuttl (#7731) 2023-07-01 12:07:27 +00:00
_config chore: bump kuttl to use stopOnFirstFailure feature (#8161) 2023-08-29 14:36:26 +00:00
autogen fix: autogen not working correctly with cronjob conditions (#7571) 2023-06-19 06:06:30 +00:00
background-only feat: migrate to events.k8s.io/v1 (#7673) 2023-07-26 14:06:51 +00:00
cleanup kuttl README (#6984) 2023-04-23 18:39:41 +00:00
custom-sigstore/standard/basic feat: add support for custom sigstore using TUF (#8385) 2023-09-18 13:16:08 +00:00
deferred Fix deferred loading (#7597) 2023-06-27 09:58:50 -07:00
events feat: migrate to events.k8s.io/v1 (#7673) 2023-07-26 14:06:51 +00:00
exceptions chore: move policy exceptions to beta (#8378) 2023-09-14 14:23:51 +00:00
filter feat: support wildcard in subjects statements (#8068) 2023-08-20 20:46:42 -04:00
flags/standard/emit-events Added fetchAttestations method to notaryV2 implimentation (#6800) 2023-06-01 16:05:28 +08:00
force-failure-policy-ignore/cluster-policy/fail fix: kuttl tests for force-failure-policy-ignore config (#6840) 2023-04-11 12:24:12 +02:00
generate wrong-fields (#8364) 2023-09-12 23:05:47 +00:00
generate-validating-admission-policy/clusterpolicy/standard fix generate VAPs kuttl tests (#8376) 2023-09-13 11:16:53 +00:00
mutate fix: mutate existing kuttl tests (#8088) 2023-08-22 16:50:26 +00:00
policy-validation feat: skip schema validation for CRD (#7869) 2023-07-20 22:02:27 +00:00
rangeoperators/standard fix: change inrange operator regexs (#5962) 2023-01-16 16:23:36 +01:00
rbac/aggregate-to-admin feat: add view aggregated cluster role support (#6350) 2023-02-25 20:57:56 +01:00
reports feat: migrate ignoreSCT from rekor to ctlog (#8166) 2023-08-30 08:39:49 +02:00
ttl [Fix] flakes in e2e tests (#8253) 2023-09-04 17:41:34 +00:00
validate remove unnecessary steps (#8374) 2023-09-13 10:30:40 +00:00
validating-admission-policy-reports/background feat: add kuttl tests for validating admission policy backgroundscan reports (#8292) 2023-09-07 02:22:12 +00:00
verify-manifests feat: migrate ignoreSCT from rekor to ctlog (#8166) 2023-08-30 08:39:49 +02:00
verifyImages/clusterpolicy feat: migrate ignoreSCT from rekor to ctlog (#8166) 2023-08-30 08:39:49 +02:00
webhooks refactor: do not allow matching with subresource kind (#6625) 2023-03-21 13:28:00 +00:00
kuttl-test.yaml feat: improve background scan reports enqueue logic (#5810) 2023-01-03 13:51:37 +00:00
README.md Update README.md (#6389) 2023-02-24 10:07:26 +00:00

Testing with kuttl

This document explains conformance and end-to-end (e2e) tests using the kuttl tool, when test coverage is required or beneficial, and how contributors may write these tests.

Overview

Kyverno uses kuttl for performing tests on a live Kubernetes environment with the current code of Kyverno running inside it. The official documentation for this tool is located here. kuttl is a Kubernetes testing tool that is capable of submitting resources to a cluster and checking the state of those resources. By comparing that state with declarations defined in other files, kuttl can determine whether the observed state is "correct" and either pass or fail based upon this. It also has abilities to run commands or whole scripts. kuttl tests work by defining a number of different YAML files with a numerical prefix and co-locating these files in a single directory. Each directory represents a "test case". Files within this directory are evaluated/executed in numerical order. If a failure is encountered at any step in the process, the test is halted and a failure reported. The benefit of kuttl is that test cases may be easily and quickly written with no knowledge of a programming language required.

How Tests Are Conducted

Kyverno uses kuttl tests to check behavior against incoming code in the form of PRs. Upon every PR, the following automated actions occur in GitHub Actions:

  1. A KinD cluster is built.
  2. Kyverno is built from source incorporating the changes in your PR.
  3. Kyverno is installed into the KinD cluster.
  4. Kuttl executes all test cases against the live environment.

When Tests Are Required

Tests are required for any PR which:

  1. Introduces a new capability
  2. Enhances an existing capability
  3. Fixes an issue
  4. Makes a behavioral change

Test cases are required for any of the above which can be tested and verified from an end-user (black box) perspective. Tests are also required at the same time as when a PR is proposed. Unless there are special circumstances, tests may not follow a PR which introduces any of the following items in the list. This is because it is too easy to forget to write a test and then it never happens. Tests should always be considered a part of a responsible development process and not an after thought or "extra".

Organizing Tests

Organization of tests is critical to ensure we have an accounting of what exists. With the eventuality of hundreds of test cases, they must be organized to be useful. Please look at the existing directory structure to identify a suitable location for your tests. Tests are typically organized with the following structure, though this is subject to change.

.
├── generate
│   └── clusterpolicy
│       ├── cornercases
│       │   ├── test_case_01
│       │   │   ├── <files>.yaml
│       │   └── test_case_02
│       │       ├── <files>.yaml
│       └── standard
│           ├── clone
│           │   ├── nosync
│           │   │   ├── test_case_03

PRs which address issues will typically go into the cornercases directory separated by clusterpolicy or policy depending on which it addresses. If both, it can go under cornercases. PRs which add net new functionality such as a new rule type or significant capability should have basic tests under the standard directory. Standard tests test for generic behavior and NOT an esoteric combination of inputs/events to expose a problem. For example, an example of a standard test is to ensure that a ClusterPolicy with a single validate rule can successfully be created. Unless the contents are highly specific, this is a standard test which should be organized under the standard directory.

Writing Tests

To make writing test cases even easier, we have provided an example here under the scaffold directory which may be copied-and-pasted to a new test case (directory) based upon the organizational structure outlined above. Additional kuttl test files may be found in either commands or scripts with some common test files for Kyverno.

It is imperative you modify README.md for each test case and follow the template provided. The template looks like the following:

## Description

This is a description of what my test does and why it needs to do it.

## Expected Behavior

This is the expected behavior of my test. Although it's assumed the test, overall, should pass/succeed, be specific about what the internal behavior is which leads to that result.

## Reference Issue(s)

1234

For some best practices we have identified, see the best practices document here.