Skip to content

Commit

Permalink
Merge branch 'main' into assertion-tree-api
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 committed Sep 18, 2024
2 parents 807f2f0 + 1a34dd6 commit 6b9e4e4
Show file tree
Hide file tree
Showing 12 changed files with 313 additions and 294 deletions.
6 changes: 0 additions & 6 deletions .crds/json.kyverno.io_validatingpolicies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ spec:
properties:
check:
description: Check is the assertion check definition.
type: object
x-kubernetes-preserve-unknown-fields: true
message:
description: Message is the message associated message.
Expand All @@ -74,7 +73,6 @@ spec:
properties:
check:
description: Check is the assertion check definition.
type: object
x-kubernetes-preserve-unknown-fields: true
message:
description: Message is the message associated message.
Expand Down Expand Up @@ -110,15 +108,13 @@ spec:
will be ANDed.
items:
description: AssertionTree represents an assertion tree.
type: object
x-kubernetes-preserve-unknown-fields: true
type: array
any:
description: Any allows specifying assertion trees which
will be ORed.
items:
description: AssertionTree represents an assertion tree.
type: object
x-kubernetes-preserve-unknown-fields: true
type: array
type: object
Expand Down Expand Up @@ -151,15 +147,13 @@ spec:
will be ANDed.
items:
description: AssertionTree represents an assertion tree.
type: object
x-kubernetes-preserve-unknown-fields: true
type: array
any:
description: Any allows specifying assertion trees which
will be ORed.
items:
description: AssertionTree represents an assertion tree.
type: object
x-kubernetes-preserve-unknown-fields: true
type: array
type: object
Expand Down
2 changes: 1 addition & 1 deletion .schemas/openapi/v3/apis/json.kyverno.io/v1alpha1.json

Large diffs are not rendered by default.

6 changes: 0 additions & 6 deletions charts/kyverno-json/templates/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ spec:
properties:
check:
description: Check is the assertion check definition.
type: object
x-kubernetes-preserve-unknown-fields: true
message:
description: Message is the message associated message.
Expand All @@ -83,7 +82,6 @@ spec:
properties:
check:
description: Check is the assertion check definition.
type: object
x-kubernetes-preserve-unknown-fields: true
message:
description: Message is the message associated message.
Expand Down Expand Up @@ -119,15 +117,13 @@ spec:
will be ANDed.
items:
description: AssertionTree represents an assertion tree.
type: object
x-kubernetes-preserve-unknown-fields: true
type: array
any:
description: Any allows specifying assertion trees which
will be ORed.
items:
description: AssertionTree represents an assertion tree.
type: object
x-kubernetes-preserve-unknown-fields: true
type: array
type: object
Expand Down Expand Up @@ -160,15 +156,13 @@ spec:
will be ANDed.
items:
description: AssertionTree represents an assertion tree.
type: object
x-kubernetes-preserve-unknown-fields: true
type: array
any:
description: Any allows specifying assertion trees which
will be ORed.
items:
description: AssertionTree represents an assertion tree.
type: object
x-kubernetes-preserve-unknown-fields: true
type: array
type: object
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ require (
github.com/blang/semver/v4 v4.0.0
github.com/gin-contrib/cors v1.7.2
github.com/gin-gonic/gin v1.10.0
github.com/jinzhu/copier v0.4.0
github.com/jmespath-community/go-jmespath v1.1.2-0.20240117150817-e430401a2172
github.com/kyverno/pkg/ext v0.0.0-20240418121121-df8add26c55c
github.com/loopfz/gadgeto v0.11.4
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,6 @@ github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4=
github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/jinzhu/copier v0.4.0 h1:w3ciUoD19shMCRargcpm0cm91ytaBhDvuRpz1ODO/U8=
github.com/jinzhu/copier v0.4.0/go.mod h1:DfbEm0FYsaqBcKcFuvmOZb218JkPGtvSHsKg8S8hyyg=
github.com/jmespath-community/go-jmespath v1.1.2-0.20240117150817-e430401a2172 h1:XQYEhx+bEiWn6eiHFivu4wEHm91FoZ/gCvoLZK6Ze5Y=
github.com/jmespath-community/go-jmespath v1.1.2-0.20240117150817-e430401a2172/go.mod h1:j4OeykGPBbhX3rw4AOPGXSmX2/zuWXktm704A4MtHFs=
github.com/jonboulle/clockwork v0.4.0 h1:p4Cf1aMWXnXAUh8lVfewRBx1zaTSYKrKMF2g3ST4RZ4=
Expand Down
48 changes: 44 additions & 4 deletions pkg/apis/policy/v1alpha1/any.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,65 @@
package v1alpha1

import (
"github.com/jinzhu/copier"
"fmt"

"k8s.io/apimachinery/pkg/util/json"
)

func deepCopy(in any) any {
if in == nil {
return nil
}
switch in := in.(type) {
case string:
return in
case int:
return in
case int32:
return in
case int64:
return in
case float32:
return in
case float64:
return in
case bool:
return in

Check warning on line 27 in pkg/apis/policy/v1alpha1/any.go

View check run for this annotation

Codecov / codecov/patch

pkg/apis/policy/v1alpha1/any.go#L18-L27

Added lines #L18 - L27 were not covered by tests
case []any:
var out []any
for _, in := range in {
out = append(out, deepCopy(in))
}
return out
case map[string]any:
out := map[string]any{}
for k, in := range in {
out[k] = deepCopy(in)
}
return out
}
panic(fmt.Sprintf("deep copy failed - unrecognized type %T", in))

Check warning on line 41 in pkg/apis/policy/v1alpha1/any.go

View check run for this annotation

Codecov / codecov/patch

pkg/apis/policy/v1alpha1/any.go#L41

Added line #L41 was not covered by tests
}

// Any can be any type.
// +k8s:deepcopy-gen=false
// +kubebuilder:validation:XPreserveUnknownFields
// +kubebuilder:validation:Type:=""
type Any struct {
// +optional
value any `json:"-"`
}

func NewAny(value any) Any {
return Any{value}
}

func (t *Any) Value() any {
return t.value
}

func (in *Any) DeepCopyInto(out *Any) {
if err := copier.CopyWithOption(out, in, copier.Option{DeepCopy: true}); err != nil {
panic("deep copy failed")
}
out.value = deepCopy(in.value)
}

func (in *Any) DeepCopy() *Any {
Expand Down
Loading

0 comments on commit 6b9e4e4

Please sign in to comment.