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

Feature/foreach validate #2443

Merged
merged 20 commits into from Oct 4, 2021
Merged

Feature/foreach validate #2443

merged 20 commits into from Oct 4, 2021

Conversation

JimBugwadia
Copy link
Member

@JimBugwadia JimBugwadia commented Sep 27, 2021

Related issue

Implements validate.foreach: #1745

Milestone of this PR

1.5

What type of PR is this

/kind feature

Proposed Changes

Implements foreach for validate rules

Checklist

  • I have read the contributing guidelines.
  • I have added tests that prove my fix is effective or that my feature works.
  • My PR contains new or altered behavior to Kyverno and
    • [] I have added or changed the documentation myself in an existing PR and the link is:
    • [] I have raised an issue in kyverno/website to track the doc update and the link is:
    • [] I have read the PR documentation guide and followed the process including adding proof manifests to this PR.

Pending Tasks (before merge)

  • Add tests for foreach context and preconditions
  • Add element to context instead of replacing request.object
  • make RuleStatus lowercase
  • return RuleStatusSkip when an conditional or global anchors do not match resource
  • add Validation for foreach and fields like list.
  • add messages for foreach rule responses

Tasks to be complete after merge to main

Signed-off-by: Jim Bugwadia <jim@nirmata.com>
Signed-off-by: Jim Bugwadia <jim@nirmata.com>
Signed-off-by: Jim Bugwadia <jim@nirmata.com>
Signed-off-by: Jim Bugwadia <jim@nirmata.com>
Signed-off-by: Jim Bugwadia <jim@nirmata.com>
@JimBugwadia JimBugwadia marked this pull request as draft September 27, 2021 21:32
Signed-off-by: Jim Bugwadia <jim@nirmata.com>
Signed-off-by: Jim Bugwadia <jim@nirmata.com>
Signed-off-by: Jim Bugwadia <jim@nirmata.com>
Signed-off-by: Jim Bugwadia <jim@nirmata.com>
@JimBugwadia JimBugwadia added the milestone 1.5.0 Issues and PRs for the 1.5.0 release. label Oct 2, 2021
Signed-off-by: Jim Bugwadia <jim@nirmata.com>
Signed-off-by: Jim Bugwadia <jim@nirmata.com>
Signed-off-by: Jim Bugwadia <jim@nirmata.com>
Signed-off-by: Jim Bugwadia <jim@nirmata.com>
Signed-off-by: Jim Bugwadia <jim@nirmata.com>
Signed-off-by: Jim Bugwadia <jim@nirmata.com>
Signed-off-by: Jim Bugwadia <jim@nirmata.com>
@JimBugwadia JimBugwadia marked this pull request as ready for review October 3, 2021 11:00
@JimBugwadia
Copy link
Member Author

Here is a sample policy for testing:

apiVersion : kyverno.io/v1
kind: ClusterPolicy
metadata:
  name: check-containers
spec:
  validationFailureAction: enforce
  background: false
  rules:
  - name: check-names
    match:
      resources:
        kinds:
        - Pod
    preconditions:
      - key: "{{request.type}}"
        operator: NotEquals
        value: "DELETE"    
    validate:
      message: "Container names must contain the suffix '-valid'"  
      foreach:
        list: "request.object.spec.containers"
        pattern:
          name: "*-valid"

With this policy configured, here are some tests to show it executing:

λ kubectl run nginx --image=nginx
Error from server: admission webhook "validate.kyverno.svc" denied the request:

resource Pod/default/nginx was blocked due to the following policies

check-containers:
  check-names: 'validation failed in foreach rule for validation error: Container
    names must contain the suffix ''-valid''. Rule check-names failed at path /name/'
λ kubectl run nginx-valid --image=nginx
pod/nginx-valid created

Copy link
Member

@realshuting realshuting left a comment

Choose a reason for hiding this comment

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

@JimBugwadia - looks good, but the CLI test keeps failing without a specific error message. Does it pass for you locally?

Signed-off-by: Jim Bugwadia <jim@nirmata.com>
Signed-off-by: Jim Bugwadia <jim@nirmata.com>
Signed-off-by: Jim Bugwadia <jim@nirmata.com>
Signed-off-by: Jim Bugwadia <jim@nirmata.com>
@JimBugwadia JimBugwadia merged commit 705e029 into kyverno:main Oct 4, 2021
@JimBugwadia JimBugwadia deleted the feature/foreach_validate branch October 4, 2021 07:05
@realshuting realshuting added this to the Kyverno Release 1.5.0 milestone Oct 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
milestone 1.5.0 Issues and PRs for the 1.5.0 release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants