diff --git a/api/policies.kyverno.io/v1alpha1/generating_policy.go b/api/policies.kyverno.io/v1alpha1/generating_policy.go index 57a5cc0..0da1fe2 100644 --- a/api/policies.kyverno.io/v1alpha1/generating_policy.go +++ b/api/policies.kyverno.io/v1alpha1/generating_policy.go @@ -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 { // 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 { diff --git a/api/policies.kyverno.io/v1alpha1/zz_generated.deepcopy.go b/api/policies.kyverno.io/v1alpha1/zz_generated.deepcopy.go index 9c3d584..62e764d 100644 --- a/api/policies.kyverno.io/v1alpha1/zz_generated.deepcopy.go +++ b/api/policies.kyverno.io/v1alpha1/zz_generated.deepcopy.go @@ -572,7 +572,9 @@ func (in *GeneratingPolicySpec) DeepCopyInto(out *GeneratingPolicySpec) { if in.Generation != nil { in, out := &in.Generation, &out.Generation *out = make([]Generation, len(*in)) - copy(*out, *in) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } } if in.AuditAnnotations != nil { in, out := &in.AuditAnnotations, &out.AuditAnnotations @@ -612,6 +614,11 @@ func (in *GeneratingPolicyStatus) DeepCopy() *GeneratingPolicyStatus { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Generation) DeepCopyInto(out *Generation) { *out = *in + if in.Template != nil { + in, out := &in.Template, &out.Template + *out = new(GenerationTemplate) + **out = **in + } return } @@ -625,6 +632,22 @@ func (in *Generation) DeepCopy() *Generation { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *GenerationTemplate) DeepCopyInto(out *GenerationTemplate) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GenerationTemplate. +func (in *GenerationTemplate) DeepCopy() *GenerationTemplate { + if in == nil { + return nil + } + out := new(GenerationTemplate) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Identity) DeepCopyInto(out *Identity) { *out = *in diff --git a/api/policies.kyverno.io/v1beta1/generating_policy.go b/api/policies.kyverno.io/v1beta1/generating_policy.go index 91f62a7..8c8764d 100644 --- a/api/policies.kyverno.io/v1beta1/generating_policy.go +++ b/api/policies.kyverno.io/v1beta1/generating_policy.go @@ -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 ( diff --git a/charts/kyverno-api/templates/crds/policies.kyverno.io_generatingpolicies.yaml b/charts/kyverno-api/templates/crds/policies.kyverno.io_generatingpolicies.yaml index 6b56d6a..0d60353 100644 --- a/charts/kyverno-api/templates/crds/policies.kyverno.io_generatingpolicies.yaml +++ b/charts/kyverno-api/templates/crds/policies.kyverno.io_generatingpolicies.yaml @@ -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: @@ -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: @@ -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: diff --git a/charts/kyverno-api/templates/crds/policies.kyverno.io_namespacedgeneratingpolicies.yaml b/charts/kyverno-api/templates/crds/policies.kyverno.io_namespacedgeneratingpolicies.yaml index fc80d95..7a57565 100644 --- a/charts/kyverno-api/templates/crds/policies.kyverno.io_namespacedgeneratingpolicies.yaml +++ b/charts/kyverno-api/templates/crds/policies.kyverno.io_namespacedgeneratingpolicies.yaml @@ -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: @@ -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: diff --git a/config/crds.yaml b/config/crds.yaml index be3b49c..cfc1ac2 100644 --- a/config/crds.yaml +++ b/config/crds.yaml @@ -1846,7 +1846,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: @@ -2526,7 +2555,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: @@ -3205,7 +3263,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: @@ -19091,7 +19178,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: @@ -19772,7 +19888,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: diff --git a/config/crds/policies.kyverno.io_generatingpolicies.yaml b/config/crds/policies.kyverno.io_generatingpolicies.yaml index 5512a05..eb28aa7 100644 --- a/config/crds/policies.kyverno.io_generatingpolicies.yaml +++ b/config/crds/policies.kyverno.io_generatingpolicies.yaml @@ -169,7 +169,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: @@ -849,7 +878,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: @@ -1528,7 +1586,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: diff --git a/config/crds/policies.kyverno.io_namespacedgeneratingpolicies.yaml b/config/crds/policies.kyverno.io_namespacedgeneratingpolicies.yaml index 9bc0d5b..1fef77b 100644 --- a/config/crds/policies.kyverno.io_namespacedgeneratingpolicies.yaml +++ b/config/crds/policies.kyverno.io_namespacedgeneratingpolicies.yaml @@ -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: @@ -852,7 +881,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: diff --git a/docs/user/crd/index.html b/docs/user/crd/index.html index f35fd23..4d65c86 100644 --- a/docs/user/crd/index.html +++ b/docs/user/crd/index.html @@ -5195,9 +5195,73 @@

Generation +(Optional)

Expression is a CEL expression that takes a list of resources to be generated.

+ + +template
+ + +GenerationTemplate + + + + +(Optional) +

Template declares the resources to be generated as a YAML document, +with optional CEL interpolation.

+ + + + +
+

GenerationTemplate +

+

+(Appears on: +Generation) +

+

+

+ + + + + + + + + + + + + + + +
FieldDescription
+value
+ +string + +
+

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.

+
+interpolate
+ + +InterpolationMode + + +
+(Optional) +

Interpolate controls placeholder evaluation in Value: +“none” (default) treats Value as plain YAML; +“cel” evaluates (( ... )) placeholders as CEL expressions before the YAML is parsed.

+

@@ -5780,6 +5844,14 @@

InToto
+

InterpolationMode +(string alias)

+

+(Appears on: +GenerationTemplate) +

+

+

Key

diff --git a/docs/user/crd/kyverno_cel_policies.v1alpha1.html b/docs/user/crd/kyverno_cel_policies.v1alpha1.html index 78ecc79..d0195c9 100644 --- a/docs/user/crd/kyverno_cel_policies.v1alpha1.html +++ b/docs/user/crd/kyverno_cel_policies.v1alpha1.html @@ -5705,6 +5705,99 @@

Generation expression +
+ + + + + string + + + + + + +

Expression is a CEL expression that takes a list of resources to be generated.

+ + + + + + + + + + + + + template + +
+ + + + + + GenerationTemplate + + + + + + + +

Template declares the resources to be generated as a YAML document, +with optional CEL interpolation.

+ + + + + + + + + + + + + + + +

GenerationTemplate +

+ + +

+ (Appears in: + Generation) +

+ + +

GenerationTemplate declares generated resources as a YAML document with optional CEL interpolation.

+

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FieldDescription
value + *
@@ -5719,7 +5812,40 @@

Generation

-

Expression is a CEL expression that takes a list of resources to be generated.

+

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.

+ + + + + +
interpolate + +
+ + + + + + InterpolationMode + + + +
+ + +

Interpolate controls placeholder evaluation in Value: +"none" (default) treats Value as plain YAML; +"cel" evaluates (( ... )) placeholders as CEL expressions before the YAML is parsed.

@@ -6905,6 +7031,21 @@

InToto

+

InterpolationMode + (string alias)

+ + +

+ (Appears in: + GenerationTemplate) +

+ + +

InterpolationMode controls placeholder evaluation in a generation template.

+

+ + +

Key