1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00
kyverno/pkg/engine
Ammar Yasser 9a8e35d787
Selector with mutate target (#11208)
* feature: Add LabelSelector as a field of resource spec to allow fetching by labels

Signed-off-by: aerosouund <aerosound161@gmail.com>

* chore: Generate CRDs

Signed-off-by: aerosouund <aerosound161@gmail.com>

* feat: Add the capability to fetch with label selector

- Add the label selector as a parameter to GetResources of the engine api client and the dclient.
- Use the label selector with list options in the dclient.
- convert a metav1.LabelSelector to a labels.Selector before fetching to be able to convert it to a string to be used with ListOptions.

Signed-off-by: aerosouund <aerosound161@gmail.com>

* feat: Pass label selector to the GetResources method

Signed-off-by: aerosouund <aerosound161@gmail.com>

* feat: Return the resource selector when resolving spec

Signed-off-by: aerosouund <aerosound161@gmail.com>

* fix: Instantiate the fake client schema using the passed gvrToListKind map and by inferring schema from passed resources

All tests that use List will fail because the fake client doesn't infer the schema from the passed resources.
gvrToListKind can't be fully deprecated as some parts of kyverno use the fake client without passing resources to it (resource generation). And so both approaches have to be supported.

References:
- https://github.com/kubernetes/client-go/issues/983
- 46c1ad3baa

Signed-off-by: aerosouund <aerosound161@gmail.com>

* test: Add labelSelector unit test to mutate existing test.

- Remove the unwanted call to GetResource.
- Pass an empty map of GVR to string to the fake client constructor.

Signed-off-by: aerosouund <aerosound161@gmail.com>

* test: Add chainsaw test

Signed-off-by: aerosouund <aerosound161@gmail.com>

* chore: Run codegen

Signed-off-by: aerosouund <aerosound161@gmail.com>

* chore: Generate helm CRDs

Signed-off-by: aerosouund <aerosound161@gmail.com>

* refactor: Put the LabelSelector in a separate struct

Many types use the ResourceSpec struct and not all of them support label selectors.
This removes the field into a separate schema dedicated to target selection called TargetSelector.
It has the ResourceSpec and the selector.

Signed-off-by: aerosouund <aerosound161@gmail.com>

* chore: Run codegen after modifying selector comment

Signed-off-by: aerosouund <aerosound161@gmail.com>

* chore: Run codegen

Signed-off-by: aerosouund <aerosound161@gmail.com>

---------

Signed-off-by: aerosouund <aerosound161@gmail.com>
Co-authored-by: shuting <shuting@nirmata.com>
2024-10-16 11:17:08 +00:00
..
adapters Selector with mutate target (#11208) 2024-10-16 11:17:08 +00:00
anchor fix: validate pattern premature skip (#9155) 2024-01-29 13:06:39 +00:00
api Selector with mutate target (#11208) 2024-10-16 11:17:08 +00:00
apicall support HTTP headers in service API calls (#11041) 2024-09-09 21:04:08 +00:00
context feat:support default value into apiCall context variables (#10594) 2024-09-05 13:57:44 +08:00
factories feat: add globalcontext loader and interface (#9602) 2024-02-05 11:24:37 +00:00
handlers Selector with mutate target (#11208) 2024-10-16 11:17:08 +00:00
internal feat:Add support for condition validation across multiple image verification attestations or context entry (#9960) 2024-09-05 10:33:37 +00:00
jmespath feat(perf): add new linter prealloc to enforce slice declarations best practice (#10250) 2024-05-20 14:46:35 +05:30
jsonutils feat(json): reduce reliance on DocumentToUntyped() (#10724) 2024-07-29 11:57:20 +00:00
mutate refactor: move autogen v1 and v2 packages (#11416) 2024-10-16 08:51:38 +00:00
operator fix: change inrange operator regexs (#5962) 2023-01-16 16:23:36 +01:00
pattern chore: move utils/wildcard in ext (#8772) 2023-10-29 23:59:53 +00:00
policycontext fix: allow changes to preexisting resources that violate a validate foreach, cel or pss policy (#10033) 2024-09-06 06:42:56 +00:00
resources refactor: introduce engine handler (#6680) 2023-03-24 16:24:00 +00:00
utils refactor: move autogen v1 and v2 packages (#11416) 2024-10-16 08:51:38 +00:00
validate fix(anchor): skip anchors don't have priority (#10206) 2024-05-22 09:04:14 +00:00
variables add support for shallow substitution (#11058) 2024-10-08 19:43:04 +00:00
wildcards chore: move utils/wildcard in ext (#8772) 2023-10-29 23:59:53 +00:00
attestation_test.go Conditions message (#7113) 2023-05-08 15:34:23 +08:00
background.go refactor: move autogen v1 and v2 packages (#11416) 2024-10-16 08:51:38 +00:00
engine.go feat: enable custom data in policy reports using properties (#10933) 2024-09-03 17:36:07 +00:00
exceptions.go chore: use v2 clients for policy exceptions (#10530) 2024-06-24 16:36:55 +00:00
forceMutate.go feat(json): unmarshal once per policy (#10701) 2024-07-30 10:52:41 +00:00
forceMutate_test.go Improved test covergae for forceMutate (#10103) 2024-07-24 10:43:07 +00:00
fuzz_test.go refactor: move autogen v1 and v2 packages (#11416) 2024-10-16 08:51:38 +00:00
generation.go refactor: move autogen v1 and v2 packages (#11416) 2024-10-16 08:51:38 +00:00
image_verify.go refactor: move autogen v1 and v2 packages (#11416) 2024-10-16 08:51:38 +00:00
image_verify_test.go feat:Add support for condition validation across multiple image verification attestations or context entry (#9960) 2024-09-05 10:33:37 +00:00
metrics.go fix: change generic policy to not return any (#9463) 2024-01-20 19:20:22 +02:00
mutation.go refactor: move autogen v1 and v2 packages (#11416) 2024-10-16 08:51:38 +00:00
mutation_test.go Selector with mutate target (#11208) 2024-10-16 11:17:08 +00:00
policy_context.go refactor: hide json context from caller (#7139) 2023-05-12 14:14:48 +00:00
validation.go refactor: move autogen v1 and v2 packages (#11416) 2024-10-16 08:51:38 +00:00
validation_test.go chore: rename validationFailureAction to failureAction under the rule (#10893) 2024-08-27 20:07:57 +00:00