mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-06 16:06:56 +00:00
feat: add evaluation mode to api (#12262)
Signed-off-by: ShutingZhao <shuting@nirmata.com>
This commit is contained in:
parent
5420fecbd6
commit
26a6b37265
6 changed files with 76 additions and 7 deletions
|
@ -91,7 +91,7 @@ type ValidatingPolicySpec struct {
|
||||||
|
|
||||||
// EvaluationConfiguration defines the configuration for the policy evaluation.
|
// EvaluationConfiguration defines the configuration for the policy evaluation.
|
||||||
// +optional
|
// +optional
|
||||||
EvaluationConfiguration *EvaluationConfiguration `json:"evaluationConfiguration,omitempty"`
|
EvaluationConfiguration *EvaluationConfiguration `json:"evaluation,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// AdmissionEnabled checks if admission is set to true
|
// AdmissionEnabled checks if admission is set to true
|
||||||
|
@ -110,6 +110,14 @@ func (s ValidatingPolicySpec) BackgroundEnabled() bool {
|
||||||
return *s.EvaluationConfiguration.Background.Enabled
|
return *s.EvaluationConfiguration.Background.Enabled
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EvaluationMode returns the evaluation mode of the policy.
|
||||||
|
func (s ValidatingPolicySpec) EvaluationMode() EvaluationMode {
|
||||||
|
if s.EvaluationConfiguration == nil || s.EvaluationConfiguration.Mode == "" {
|
||||||
|
return EvaluationModeKubernetes
|
||||||
|
}
|
||||||
|
return s.EvaluationConfiguration.Mode
|
||||||
|
}
|
||||||
|
|
||||||
type WebhookConfiguration struct {
|
type WebhookConfiguration struct {
|
||||||
// TimeoutSeconds specifies the maximum time in seconds allowed to apply this policy.
|
// TimeoutSeconds specifies the maximum time in seconds allowed to apply this policy.
|
||||||
// After the configured time expires, the admission request may fail, or may simply ignore the policy results,
|
// After the configured time expires, the admission request may fail, or may simply ignore the policy results,
|
||||||
|
@ -118,6 +126,12 @@ type WebhookConfiguration struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type EvaluationConfiguration struct {
|
type EvaluationConfiguration struct {
|
||||||
|
// Mode is the mode of policy evaluation.
|
||||||
|
// Allowed values are "Kubernetes" or "JSON".
|
||||||
|
// Optional. Default value is "Kubernetes".
|
||||||
|
// +optional
|
||||||
|
Mode EvaluationMode `json:"mode,omitempty"`
|
||||||
|
|
||||||
// Admission controls policy evaluation during admission.
|
// Admission controls policy evaluation during admission.
|
||||||
// +optional
|
// +optional
|
||||||
Admission *AdmissionConfiguration `json:"admission,omitempty"`
|
Admission *AdmissionConfiguration `json:"admission,omitempty"`
|
||||||
|
@ -143,3 +157,10 @@ type BackgroundConfiguration struct {
|
||||||
// +kubebuilder:default=true
|
// +kubebuilder:default=true
|
||||||
Enabled *bool `json:"enabled,omitempty"`
|
Enabled *bool `json:"enabled,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type EvaluationMode string
|
||||||
|
|
||||||
|
const (
|
||||||
|
EvaluationModeKubernetes EvaluationMode = "Kubernetes"
|
||||||
|
EvaluationModeJSON EvaluationMode = "JSON"
|
||||||
|
)
|
||||||
|
|
|
@ -108,7 +108,7 @@ spec:
|
||||||
type: object
|
type: object
|
||||||
type: array
|
type: array
|
||||||
x-kubernetes-list-type: atomic
|
x-kubernetes-list-type: atomic
|
||||||
evaluationConfiguration:
|
evaluation:
|
||||||
description: EvaluationConfiguration defines the configuration for
|
description: EvaluationConfiguration defines the configuration for
|
||||||
the policy evaluation.
|
the policy evaluation.
|
||||||
properties:
|
properties:
|
||||||
|
@ -134,6 +134,12 @@ spec:
|
||||||
uses variables that are only available in the admission review request (e.g. user name).
|
uses variables that are only available in the admission review request (e.g. user name).
|
||||||
type: boolean
|
type: boolean
|
||||||
type: object
|
type: object
|
||||||
|
mode:
|
||||||
|
description: |-
|
||||||
|
Mode is the mode of policy evaluation.
|
||||||
|
Allowed values are "Kubernetes" or "JSON".
|
||||||
|
Optional. Default value is "Kubernetes".
|
||||||
|
type: string
|
||||||
type: object
|
type: object
|
||||||
failurePolicy:
|
failurePolicy:
|
||||||
description: |-
|
description: |-
|
||||||
|
|
|
@ -102,7 +102,7 @@ spec:
|
||||||
type: object
|
type: object
|
||||||
type: array
|
type: array
|
||||||
x-kubernetes-list-type: atomic
|
x-kubernetes-list-type: atomic
|
||||||
evaluationConfiguration:
|
evaluation:
|
||||||
description: EvaluationConfiguration defines the configuration for
|
description: EvaluationConfiguration defines the configuration for
|
||||||
the policy evaluation.
|
the policy evaluation.
|
||||||
properties:
|
properties:
|
||||||
|
@ -128,6 +128,12 @@ spec:
|
||||||
uses variables that are only available in the admission review request (e.g. user name).
|
uses variables that are only available in the admission review request (e.g. user name).
|
||||||
type: boolean
|
type: boolean
|
||||||
type: object
|
type: object
|
||||||
|
mode:
|
||||||
|
description: |-
|
||||||
|
Mode is the mode of policy evaluation.
|
||||||
|
Allowed values are "Kubernetes" or "JSON".
|
||||||
|
Optional. Default value is "Kubernetes".
|
||||||
|
type: string
|
||||||
type: object
|
type: object
|
||||||
failurePolicy:
|
failurePolicy:
|
||||||
description: |-
|
description: |-
|
||||||
|
|
|
@ -102,7 +102,7 @@ spec:
|
||||||
type: object
|
type: object
|
||||||
type: array
|
type: array
|
||||||
x-kubernetes-list-type: atomic
|
x-kubernetes-list-type: atomic
|
||||||
evaluationConfiguration:
|
evaluation:
|
||||||
description: EvaluationConfiguration defines the configuration for
|
description: EvaluationConfiguration defines the configuration for
|
||||||
the policy evaluation.
|
the policy evaluation.
|
||||||
properties:
|
properties:
|
||||||
|
@ -128,6 +128,12 @@ spec:
|
||||||
uses variables that are only available in the admission review request (e.g. user name).
|
uses variables that are only available in the admission review request (e.g. user name).
|
||||||
type: boolean
|
type: boolean
|
||||||
type: object
|
type: object
|
||||||
|
mode:
|
||||||
|
description: |-
|
||||||
|
Mode is the mode of policy evaluation.
|
||||||
|
Allowed values are "Kubernetes" or "JSON".
|
||||||
|
Optional. Default value is "Kubernetes".
|
||||||
|
type: string
|
||||||
type: object
|
type: object
|
||||||
failurePolicy:
|
failurePolicy:
|
||||||
description: |-
|
description: |-
|
||||||
|
|
|
@ -48650,7 +48650,7 @@ spec:
|
||||||
type: object
|
type: object
|
||||||
type: array
|
type: array
|
||||||
x-kubernetes-list-type: atomic
|
x-kubernetes-list-type: atomic
|
||||||
evaluationConfiguration:
|
evaluation:
|
||||||
description: EvaluationConfiguration defines the configuration for
|
description: EvaluationConfiguration defines the configuration for
|
||||||
the policy evaluation.
|
the policy evaluation.
|
||||||
properties:
|
properties:
|
||||||
|
@ -48676,6 +48676,12 @@ spec:
|
||||||
uses variables that are only available in the admission review request (e.g. user name).
|
uses variables that are only available in the admission review request (e.g. user name).
|
||||||
type: boolean
|
type: boolean
|
||||||
type: object
|
type: object
|
||||||
|
mode:
|
||||||
|
description: |-
|
||||||
|
Mode is the mode of policy evaluation.
|
||||||
|
Allowed values are "Kubernetes" or "JSON".
|
||||||
|
Optional. Default value is "Kubernetes".
|
||||||
|
type: string
|
||||||
type: object
|
type: object
|
||||||
failurePolicy:
|
failurePolicy:
|
||||||
description: |-
|
description: |-
|
||||||
|
|
|
@ -10840,7 +10840,7 @@ WebhookConfiguration
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<code>evaluationConfiguration</code><br/>
|
<code>evaluation</code><br/>
|
||||||
<em>
|
<em>
|
||||||
<a href="#policies.kyverno.io/v1alpha1.EvaluationConfiguration">
|
<a href="#policies.kyverno.io/v1alpha1.EvaluationConfiguration">
|
||||||
EvaluationConfiguration
|
EvaluationConfiguration
|
||||||
|
@ -11560,6 +11560,22 @@ Secrets must live in the Kyverno namespace.</p>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
|
<code>mode</code><br/>
|
||||||
|
<em>
|
||||||
|
<a href="#policies.kyverno.io/v1alpha1.EvaluationMode">
|
||||||
|
EvaluationMode
|
||||||
|
</a>
|
||||||
|
</em>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<em>(Optional)</em>
|
||||||
|
<p>Mode is the mode of policy evaluation.
|
||||||
|
Allowed values are “Kubernetes” or “JSON”.
|
||||||
|
Optional. Default value is “Kubernetes”.</p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
<code>admission</code><br/>
|
<code>admission</code><br/>
|
||||||
<em>
|
<em>
|
||||||
<a href="#policies.kyverno.io/v1alpha1.AdmissionConfiguration">
|
<a href="#policies.kyverno.io/v1alpha1.AdmissionConfiguration">
|
||||||
|
@ -11589,6 +11605,14 @@ BackgroundConfiguration
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<hr />
|
<hr />
|
||||||
|
<h3 id="policies.kyverno.io/v1alpha1.EvaluationMode">EvaluationMode
|
||||||
|
(<code>string</code> alias)</p></h3>
|
||||||
|
<p>
|
||||||
|
(<em>Appears on:</em>
|
||||||
|
<a href="#policies.kyverno.io/v1alpha1.EvaluationConfiguration">EvaluationConfiguration</a>)
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
</p>
|
||||||
<h3 id="policies.kyverno.io/v1alpha1.GenericPolicy">GenericPolicy
|
<h3 id="policies.kyverno.io/v1alpha1.GenericPolicy">GenericPolicy
|
||||||
</h3>
|
</h3>
|
||||||
<p>
|
<p>
|
||||||
|
@ -12706,7 +12730,7 @@ WebhookConfiguration
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<code>evaluationConfiguration</code><br/>
|
<code>evaluation</code><br/>
|
||||||
<em>
|
<em>
|
||||||
<a href="#policies.kyverno.io/v1alpha1.EvaluationConfiguration">
|
<a href="#policies.kyverno.io/v1alpha1.EvaluationConfiguration">
|
||||||
EvaluationConfiguration
|
EvaluationConfiguration
|
||||||
|
|
Loading…
Add table
Reference in a new issue