Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions api/policies.kyverno.io/v1alpha1/generating_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,43 @@ type OrphanDownstreamOnPolicyDeleteConfiguration struct {
}

// Generation defines the configuration for the generation of resources.
// +kubebuilder:validation:XValidation:rule="(has(self.expression) && !has(self.template)) || (!has(self.expression) && has(self.template))",message="exactly one of expression or template must be set"
type Generation struct {
Comment thread
realshuting marked this conversation as resolved.
Resolved
// Expression is a CEL expression that takes a list of resources to be generated.
// +optional
Expression string `json:"expression,omitempty"`

// Template declares the resources to be generated as a YAML document,
// with optional CEL interpolation.
// +optional
Template *GenerationTemplate `json:"template,omitempty"`
}

// InterpolationMode controls placeholder evaluation in a generation template.
// +kubebuilder:validation:Enum=none;cel
type InterpolationMode string

const (
// InterpolationModeNone disables placeholder evaluation, the template is treated as plain YAML.
InterpolationModeNone InterpolationMode = "none"
// InterpolationModeCEL evaluates `(( ... ))` placeholders as CEL expressions before the YAML is parsed.
InterpolationModeCEL InterpolationMode = "cel"
)

// GenerationTemplate declares generated resources as a YAML document with optional CEL interpolation.
type GenerationTemplate struct {
// Value is a YAML string, single or multi-document, defining the resources to generate.
// The namespace of each generated resource is taken from its rendered metadata.namespace,
// resources without a namespace are treated as cluster-scoped.
// +kubebuilder:validation:MinLength=1
Value string `json:"value"`

// Interpolate controls placeholder evaluation in Value:
// "none" (default) treats Value as plain YAML;
// "cel" evaluates `(( ... ))` placeholders as CEL expressions before the YAML is parsed.
// +kubebuilder:default=none
// +optional
Interpolate InterpolationMode `json:"interpolate,omitempty"`
}

type GeneratingPolicyStatus struct {
Expand Down
25 changes: 24 additions & 1 deletion api/policies.kyverno.io/v1alpha1/zz_generated.deepcopy.go

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

7 changes: 7 additions & 0 deletions api/policies.kyverno.io/v1beta1/generating_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ type (
SynchronizationConfiguration = v1alpha1.SynchronizationConfiguration
OrphanDownstreamOnPolicyDeleteConfiguration = v1alpha1.OrphanDownstreamOnPolicyDeleteConfiguration
Generation = v1alpha1.Generation
GenerationTemplate = v1alpha1.GenerationTemplate
InterpolationMode = v1alpha1.InterpolationMode
)

const (
InterpolationModeNone = v1alpha1.InterpolationModeNone
InterpolationModeCEL = v1alpha1.InterpolationModeCEL
)

var (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,36 @@ spec:
description: Expression is a CEL expression that takes a list
of resources to be generated.
type: string
template:
description: |-
Template declares the resources to be generated as a YAML document,
with optional CEL interpolation.
properties:
interpolate:
default: none
description: |-
Interpolate controls placeholder evaluation in Value:
"none" (default) treats Value as plain YAML;
"cel" evaluates `(( ... ))` placeholders as CEL expressions before the YAML is parsed.
enum:
- none
- cel
type: string
value:
description: |-
Value is a YAML string, single or multi-document, defining the resources to generate.
The namespace of each generated resource is taken from its rendered metadata.namespace,
resources without a namespace are treated as cluster-scoped.
minLength: 1
type: string
required:
- value
type: object
type: object
x-kubernetes-validations:
- message: exactly one of expression or template must be set
rule: (has(self.expression) && !has(self.template)) || (!has(self.expression)
&& has(self.template))
minItems: 1
type: array
matchConditions:
Expand Down Expand Up @@ -851,7 +880,36 @@ spec:
description: Expression is a CEL expression that takes a list
of resources to be generated.
type: string
template:
description: |-
Template declares the resources to be generated as a YAML document,
with optional CEL interpolation.
properties:
interpolate:
default: none
description: |-
Interpolate controls placeholder evaluation in Value:
"none" (default) treats Value as plain YAML;
"cel" evaluates `(( ... ))` placeholders as CEL expressions before the YAML is parsed.
enum:
- none
- cel
type: string
value:
description: |-
Value is a YAML string, single or multi-document, defining the resources to generate.
The namespace of each generated resource is taken from its rendered metadata.namespace,
resources without a namespace are treated as cluster-scoped.
minLength: 1
type: string
required:
- value
type: object
type: object
x-kubernetes-validations:
- message: exactly one of expression or template must be set
rule: (has(self.expression) && !has(self.template)) || (!has(self.expression)
&& has(self.template))
minItems: 1
type: array
matchConditions:
Expand Down Expand Up @@ -1530,7 +1588,36 @@ spec:
description: Expression is a CEL expression that takes a list
of resources to be generated.
type: string
template:
description: |-
Template declares the resources to be generated as a YAML document,
with optional CEL interpolation.
properties:
interpolate:
default: none
description: |-
Interpolate controls placeholder evaluation in Value:
"none" (default) treats Value as plain YAML;
"cel" evaluates `(( ... ))` placeholders as CEL expressions before the YAML is parsed.
enum:
- none
- cel
type: string
value:
description: |-
Value is a YAML string, single or multi-document, defining the resources to generate.
The namespace of each generated resource is taken from its rendered metadata.namespace,
resources without a namespace are treated as cluster-scoped.
minLength: 1
type: string
required:
- value
type: object
type: object
x-kubernetes-validations:
- message: exactly one of expression or template must be set
rule: (has(self.expression) && !has(self.template)) || (!has(self.expression)
&& has(self.template))
minItems: 1
type: array
matchConditions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,36 @@ spec:
description: Expression is a CEL expression that takes a list
of resources to be generated.
type: string
template:
description: |-
Template declares the resources to be generated as a YAML document,
with optional CEL interpolation.
properties:
interpolate:
default: none
description: |-
Interpolate controls placeholder evaluation in Value:
"none" (default) treats Value as plain YAML;
"cel" evaluates `(( ... ))` placeholders as CEL expressions before the YAML is parsed.
enum:
- none
- cel
type: string
value:
description: |-
Value is a YAML string, single or multi-document, defining the resources to generate.
The namespace of each generated resource is taken from its rendered metadata.namespace,
resources without a namespace are treated as cluster-scoped.
minLength: 1
type: string
required:
- value
type: object
type: object
x-kubernetes-validations:
- message: exactly one of expression or template must be set
rule: (has(self.expression) && !has(self.template)) || (!has(self.expression)
&& has(self.template))
minItems: 1
type: array
matchConditions:
Expand Down Expand Up @@ -854,7 +883,36 @@ spec:
description: Expression is a CEL expression that takes a list
of resources to be generated.
type: string
template:
description: |-
Template declares the resources to be generated as a YAML document,
with optional CEL interpolation.
properties:
interpolate:
default: none
description: |-
Interpolate controls placeholder evaluation in Value:
"none" (default) treats Value as plain YAML;
"cel" evaluates `(( ... ))` placeholders as CEL expressions before the YAML is parsed.
enum:
- none
- cel
type: string
value:
description: |-
Value is a YAML string, single or multi-document, defining the resources to generate.
The namespace of each generated resource is taken from its rendered metadata.namespace,
resources without a namespace are treated as cluster-scoped.
minLength: 1
type: string
required:
- value
type: object
type: object
x-kubernetes-validations:
- message: exactly one of expression or template must be set
rule: (has(self.expression) && !has(self.template)) || (!has(self.expression)
&& has(self.template))
minItems: 1
type: array
matchConditions:
Expand Down
Loading