Skip to content

Commit

Permalink
feat: add patch operation outputs support (#1076)
Browse files Browse the repository at this point in the history
* feat: add patch operation outputs support

Signed-off-by: Charles-Edouard Brétéché <[email protected]>

* clean

Signed-off-by: Charles-Edouard Brétéché <[email protected]>

---------

Signed-off-by: Charles-Edouard Brétéché <[email protected]>
  • Loading branch information
eddycharly authored Mar 7, 2024
1 parent 3e39a5d commit 0c9194b
Show file tree
Hide file tree
Showing 20 changed files with 238 additions and 35 deletions.
22 changes: 22 additions & 0 deletions .crds/chainsaw.kyverno.io_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2056,6 +2056,28 @@ spec:
that matches multiple files, such as "manifest/*.yaml"
for all YAML files within the "manifest" directory.
type: string
outputs:
description: Outputs defines output bindings.
items:
description: Output represents an output binding
with a match to determine if the binding must
be considered or not.
properties:
match:
description: Match defines the matching statement.
type: object
x-kubernetes-preserve-unknown-fields: true
name:
description: Name the name of the binding.
type: string
value:
description: Value value of the binding.
x-kubernetes-preserve-unknown-fields: true
required:
- name
- value
type: object
type: array
resource:
description: Resource provides a resource to be applied.
type: object
Expand Down
22 changes: 22 additions & 0 deletions .crds/chainsaw.kyverno.io_teststeps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1490,6 +1490,28 @@ spec:
multiple files, such as "manifest/*.yaml" for all YAML
files within the "manifest" directory.
type: string
outputs:
description: Outputs defines output bindings.
items:
description: Output represents an output binding with
a match to determine if the binding must be considered
or not.
properties:
match:
description: Match defines the matching statement.
type: object
x-kubernetes-preserve-unknown-fields: true
name:
description: Name the name of the binding.
type: string
value:
description: Value value of the binding.
x-kubernetes-preserve-unknown-fields: true
required:
- name
- value
type: object
type: array
resource:
description: Resource provides a resource to be applied.
type: object
Expand Down
32 changes: 32 additions & 0 deletions .schemas/json/test-chainsaw-v1alpha1.json
Original file line number Diff line number Diff line change
Expand Up @@ -3689,6 +3689,38 @@
"null"
]
},
"outputs": {
"description": "Outputs defines output bindings.",
"type": [
"array",
"null"
],
"items": {
"description": "Output represents an output binding with a match to determine if the binding must be considered or not.",
"type": [
"object",
"null"
],
"required": [
"name",
"value"
],
"properties": {
"match": {
"description": "Match defines the matching statement.",
"x-kubernetes-preserve-unknown-fields": true
},
"name": {
"description": "Name the name of the binding.",
"type": "string"
},
"value": {
"description": "Value value of the binding.",
"x-kubernetes-preserve-unknown-fields": true
}
}
}
},
"resource": {
"description": "Resource provides a resource to be applied.",
"x-kubernetes-embedded-resource": true,
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/v1alpha1/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ type Patch struct {
// +optional
Bindings []Binding `json:"bindings,omitempty"`

// Outputs defines output bindings.
// +optional
Outputs []Output `json:"outputs,omitempty"`

// Cluster defines the target cluster (default cluster will be used if not specified and/or overridden).
// +optional
Cluster string `json:"cluster,omitempty"`
Expand Down
7 changes: 7 additions & 0 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.

22 changes: 22 additions & 0 deletions pkg/data/crds/chainsaw.kyverno.io_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2056,6 +2056,28 @@ spec:
that matches multiple files, such as "manifest/*.yaml"
for all YAML files within the "manifest" directory.
type: string
outputs:
description: Outputs defines output bindings.
items:
description: Output represents an output binding
with a match to determine if the binding must
be considered or not.
properties:
match:
description: Match defines the matching statement.
type: object
x-kubernetes-preserve-unknown-fields: true
name:
description: Name the name of the binding.
type: string
value:
description: Value value of the binding.
x-kubernetes-preserve-unknown-fields: true
required:
- name
- value
type: object
type: array
resource:
description: Resource provides a resource to be applied.
type: object
Expand Down
22 changes: 22 additions & 0 deletions pkg/data/crds/chainsaw.kyverno.io_teststeps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1490,6 +1490,28 @@ spec:
multiple files, such as "manifest/*.yaml" for all YAML
files within the "manifest" directory.
type: string
outputs:
description: Outputs defines output bindings.
items:
description: Output represents an output binding with
a match to determine if the binding must be considered
or not.
properties:
match:
description: Match defines the matching statement.
type: object
x-kubernetes-preserve-unknown-fields: true
name:
description: Name the name of the binding.
type: string
value:
description: Value value of the binding.
x-kubernetes-preserve-unknown-fields: true
required:
- name
- value
type: object
type: array
resource:
description: Resource provides a resource to be applied.
type: object
Expand Down
32 changes: 32 additions & 0 deletions pkg/data/schemas/json/test-chainsaw-v1alpha1.json
Original file line number Diff line number Diff line change
Expand Up @@ -3689,6 +3689,38 @@
"null"
]
},
"outputs": {
"description": "Outputs defines output bindings.",
"type": [
"array",
"null"
],
"items": {
"description": "Output represents an output binding with a match to determine if the binding must be considered or not.",
"type": [
"object",
"null"
],
"required": [
"name",
"value"
],
"properties": {
"match": {
"description": "Match defines the matching statement.",
"x-kubernetes-preserve-unknown-fields": true
},
"name": {
"description": "Name the name of the binding.",
"type": "string"
},
"value": {
"description": "Value value of the binding.",
"x-kubernetes-preserve-unknown-fields": true
}
}
}
},
"resource": {
"description": "Resource provides a resource to be applied.",
"x-kubernetes-embedded-resource": true,
Expand Down
4 changes: 2 additions & 2 deletions pkg/runner/operations/apply/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ func New(
}
}

func (o *operation) Exec(ctx context.Context, bindings binding.Bindings) (_ operations.Outputs, err error) {
func (o *operation) Exec(ctx context.Context, bindings binding.Bindings) (_ operations.Outputs, _err error) {
if bindings == nil {
bindings = binding.NewBindings()
}
obj := o.base
logger := internal.GetLogger(ctx, &obj)
defer func() {
internal.LogEnd(logger, logging.Apply, err)
internal.LogEnd(logger, logging.Apply, _err)
}()
if o.template {
template := v1alpha1.Any{
Expand Down
4 changes: 2 additions & 2 deletions pkg/runner/operations/assert/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ func New(
}
}

func (o *operation) Exec(ctx context.Context, bindings binding.Bindings) (outputs operations.Outputs, err error) {
func (o *operation) Exec(ctx context.Context, bindings binding.Bindings) (_ operations.Outputs, _err error) {
if bindings == nil {
bindings = binding.NewBindings()
}
obj := o.base
logger := internal.GetLogger(ctx, &obj)
defer func() {
internal.LogEnd(logger, logging.Assert, err)
internal.LogEnd(logger, logging.Assert, _err)
}()
if o.template {
if err := template.ResourceRef(ctx, &obj, bindings); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/runner/operations/command/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func New(
}
}

func (o *operation) Exec(ctx context.Context, bindings binding.Bindings) (outputs operations.Outputs, _err error) {
func (o *operation) Exec(ctx context.Context, bindings binding.Bindings) (_ operations.Outputs, _err error) {
if bindings == nil {
bindings = binding.NewBindings()
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/runner/operations/create/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ func New(
}
}

func (o *operation) Exec(ctx context.Context, bindings binding.Bindings) (_ operations.Outputs, err error) {
func (o *operation) Exec(ctx context.Context, bindings binding.Bindings) (_ operations.Outputs, _err error) {
if bindings == nil {
bindings = binding.NewBindings()
}
obj := o.base
logger := internal.GetLogger(ctx, &obj)
defer func() {
internal.LogEnd(logger, logging.Create, err)
internal.LogEnd(logger, logging.Create, _err)
}()
if o.template {
template := v1alpha1.Any{
Expand Down
4 changes: 2 additions & 2 deletions pkg/runner/operations/delete/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ func New(
}
}

func (o *operation) Exec(ctx context.Context, bindings binding.Bindings) (outputs operations.Outputs, err error) {
func (o *operation) Exec(ctx context.Context, bindings binding.Bindings) (_ operations.Outputs, _err error) {
if bindings == nil {
bindings = binding.NewBindings()
}
obj := o.base
logger := internal.GetLogger(ctx, &obj)
defer func() {
internal.LogEnd(logger, logging.Delete, err)
internal.LogEnd(logger, logging.Delete, _err)
}()
if o.template {
template := v1alpha1.Any{
Expand Down
4 changes: 2 additions & 2 deletions pkg/runner/operations/error/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ func New(
}
}

func (o *operation) Exec(ctx context.Context, bindings binding.Bindings) (outputs operations.Outputs, err error) {
func (o *operation) Exec(ctx context.Context, bindings binding.Bindings) (_ operations.Outputs, _err error) {
if bindings == nil {
bindings = binding.NewBindings()
}
obj := o.base
logger := internal.GetLogger(ctx, &obj)
defer func() {
internal.LogEnd(logger, logging.Error, err)
internal.LogEnd(logger, logging.Error, _err)
}()
if o.template {
if err := template.ResourceRef(ctx, &obj, bindings); err != nil {
Expand Down
Loading

0 comments on commit 0c9194b

Please sign in to comment.