Skip to content

Commit

Permalink
feat: put message per assertion (#91)
Browse files Browse the repository at this point in the history
Signed-off-by: Charles-Edouard Brétéché <[email protected]>
  • Loading branch information
eddycharly authored Oct 10, 2023
1 parent 9ec8f17 commit 804ffbe
Show file tree
Hide file tree
Showing 33 changed files with 509 additions and 159 deletions.
5 changes: 3 additions & 2 deletions catalog/aws/policy-1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ spec:
validate:
assert:
all:
- foo:
/(bar)/: 10
- check:
foo:
/(bar)/: 10
5 changes: 3 additions & 2 deletions catalog/ecs/policy-1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ spec:
validate:
assert:
all:
- foo:
/(bar)/: 10
- check:
foo:
/(bar)/: 10
28 changes: 22 additions & 6 deletions config/crds/json.kyverno.io_policies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,21 +114,37 @@ spec:
description: All allows specifying resources which will
be ANDed.
items:
properties:
check:
description: Check is the assertion check definition.
type: object
x-kubernetes-preserve-unknown-fields: true
message:
description: Message is the variable associated
message.
type: string
required:
- check
type: object
x-kubernetes-preserve-unknown-fields: true
type: array
any:
description: Any allows specifying resources which will
be ORed.
items:
properties:
check:
description: Check is the assertion check definition.
type: object
x-kubernetes-preserve-unknown-fields: true
message:
description: Message is the variable associated
message.
type: string
required:
- check
type: object
x-kubernetes-preserve-unknown-fields: true
type: array
type: object
message:
description: Message specifies a custom message to be displayed
on failure.
type: string
type: object
required:
- name
Expand Down
75 changes: 60 additions & 15 deletions docs/user/apis/md/kyverno-json.v1alpha1.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,12 @@ auto_generated: true

**Appears in:**

- [Assertion](#json-kyverno-io-v1alpha1-Assertion)

- [ContextEntry](#json-kyverno-io-v1alpha1-ContextEntry)

- [Match](#json-kyverno-io-v1alpha1-Match)



<table class="table">
Expand All @@ -70,18 +74,68 @@ auto_generated: true
</tbody>
</table>

## `Assertions` {#json-kyverno-io-v1alpha1-Assertions}
## `Assert` {#json-kyverno-io-v1alpha1-Assert}

(Alias of `[]github.com/kyverno/kyverno-json/pkg/apis/v1alpha1.Any`)

**Appears in:**

- [Match](#json-kyverno-io-v1alpha1-Match)
- [Validation](#json-kyverno-io-v1alpha1-Validation)



<table class="table">
<thead><tr><th width="30%">Field</th><th>Description</th></tr></thead>
<tbody>


<tr><td><code>any</code> <B>[Required]</B><br/>
<a href="#json-kyverno-io-v1alpha1-Assertion"><code>[]Assertion</code></a>
</td>
<td>
<p>Any allows specifying resources which will be ORed.</p>
</td>
</tr>
<tr><td><code>all</code> <B>[Required]</B><br/>
<a href="#json-kyverno-io-v1alpha1-Assertion"><code>[]Assertion</code></a>
</td>
<td>
<p>All allows specifying resources which will be ANDed.</p>
</td>
</tr>
</tbody>
</table>

## `Assertion` {#json-kyverno-io-v1alpha1-Assertion}


**Appears in:**

- [Assert](#json-kyverno-io-v1alpha1-Assert)



<table class="table">
<thead><tr><th width="30%">Field</th><th>Description</th></tr></thead>
<tbody>


<tr><td><code>message</code> <B>[Required]</B><br/>
<code>string</code>
</td>
<td>
<p>Message is the variable associated message.</p>
</td>
</tr>
<tr><td><code>check</code> <B>[Required]</B><br/>
<a href="#json-kyverno-io-v1alpha1-Any"><code>Any</code></a>
</td>
<td>
<p>Check is the assertion check definition.</p>
</td>
</tr>
</tbody>
</table>

## `ContextEntry` {#json-kyverno-io-v1alpha1-ContextEntry}


Expand Down Expand Up @@ -122,8 +176,6 @@ auto_generated: true

- [Rule](#json-kyverno-io-v1alpha1-Rule)

- [Validation](#json-kyverno-io-v1alpha1-Validation)



<table class="table">
Expand All @@ -132,14 +184,14 @@ auto_generated: true


<tr><td><code>any</code> <B>[Required]</B><br/>
<a href="#json-kyverno-io-v1alpha1-Assertions"><code>Assertions</code></a>
<a href="#json-kyverno-io-v1alpha1-Any"><code>[]Any</code></a>
</td>
<td>
<p>Any allows specifying resources which will be ORed.</p>
</td>
</tr>
<tr><td><code>all</code> <B>[Required]</B><br/>
<a href="#json-kyverno-io-v1alpha1-Assertions"><code>Assertions</code></a>
<a href="#json-kyverno-io-v1alpha1-Any"><code>[]Any</code></a>
</td>
<td>
<p>All allows specifying resources which will be ANDed.</p>
Expand Down Expand Up @@ -245,15 +297,8 @@ and admission review request information like the name or role.</p>
<tbody>


<tr><td><code>message</code> <B>[Required]</B><br/>
<code>string</code>
</td>
<td>
<p>Message specifies a custom message to be displayed on failure.</p>
</td>
</tr>
<tr><td><code>assert</code> <B>[Required]</B><br/>
<a href="#json-kyverno-io-v1alpha1-Match"><code>Match</code></a>
<a href="#json-kyverno-io-v1alpha1-Assert"><code>Assert</code></a>
</td>
<td>
<p>Assert specifies an overlay-style pattern used to check resources.</p>
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/kyverno/kyverno v1.11.0-beta.4
github.com/spf13/cobra v1.7.0
github.com/stretchr/testify v1.8.4
go.uber.org/multierr v1.11.0
gopkg.in/yaml.v3 v3.0.1
k8s.io/apimachinery v0.28.2
sigs.k8s.io/kubectl-validate v0.0.0-20230927155409-3b3ca3ad91d0
Expand Down Expand Up @@ -257,7 +258,6 @@ require (
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
go.step.sm/crypto v0.35.0 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.26.0 // indirect
go4.org/intern v0.0.0-20230525184215-6c62f75575cb // indirect
go4.org/unsafe/assume-no-moving-gc v0.0.0-20230525183740-e7c30c78aeb2 // indirect
Expand Down
9 changes: 9 additions & 0 deletions pkg/apis/v1alpha1/assert.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package v1alpha1

type Assert struct {
// Any allows specifying resources which will be ORed.
Any []Assertion `json:"any,omitempty"`

// All allows specifying resources which will be ANDed.
All []Assertion `json:"all,omitempty"`
}
9 changes: 9 additions & 0 deletions pkg/apis/v1alpha1/assertion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package v1alpha1

type Assertion struct {
// Message is the variable associated message.
Message string `json:"message,omitempty"`

// Check is the assertion check definition.
Check Any `json:"check"`
}
2 changes: 1 addition & 1 deletion pkg/apis/v1alpha1/assertions.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package v1alpha1

type Assertions []Any
type Assertions []Assertion
4 changes: 2 additions & 2 deletions pkg/apis/v1alpha1/match.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package v1alpha1

type Match struct {
// Any allows specifying resources which will be ORed.
Any Assertions `json:"any,omitempty"`
Any []Any `json:"any,omitempty"`

// All allows specifying resources which will be ANDed.
All Assertions `json:"all,omitempty"`
All []Any `json:"all,omitempty"`
}
5 changes: 1 addition & 4 deletions pkg/apis/v1alpha1/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ package v1alpha1

// Validation defines checks to be performed on matching resources.
type Validation struct {
// Message specifies a custom message to be displayed on failure.
Message string `json:"message,omitempty"`

// Assert specifies an overlay-style pattern used to check resources.
Assert *Match `json:"assert,omitempty"`
Assert *Assert `json:"assert,omitempty"`
}
53 changes: 50 additions & 3 deletions pkg/apis/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 22 additions & 6 deletions pkg/data/crds/json.kyverno.io_policies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,21 +114,37 @@ spec:
description: All allows specifying resources which will
be ANDed.
items:
properties:
check:
description: Check is the assertion check definition.
type: object
x-kubernetes-preserve-unknown-fields: true
message:
description: Message is the variable associated
message.
type: string
required:
- check
type: object
x-kubernetes-preserve-unknown-fields: true
type: array
any:
description: Any allows specifying resources which will
be ORed.
items:
properties:
check:
description: Check is the assertion check definition.
type: object
x-kubernetes-preserve-unknown-fields: true
message:
description: Message is the variable associated
message.
type: string
required:
- check
type: object
x-kubernetes-preserve-unknown-fields: true
type: array
type: object
message:
description: Message specifies a custom message to be displayed
on failure.
type: string
type: object
required:
- name
Expand Down
Loading

0 comments on commit 804ffbe

Please sign in to comment.