1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00

fix: remove supported from autogen status (#3714)

Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com>
This commit is contained in:
Charles-Edouard Brétéché 2022-04-29 01:14:48 +02:00 committed by GitHub
parent d0ada5529c
commit 7fca026678
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 69 additions and 124 deletions

View file

@ -5,8 +5,6 @@ import (
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
apiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// FailurePolicyType specifies a failure policy that defines how unrecognized errors from the admission endpoint are handled.
@ -467,69 +465,6 @@ type CloneFrom struct {
Name string `json:"name,omitempty" yaml:"name,omitempty"`
}
const (
// Ready means that the policy is ready
PolicyConditionReady = "Ready"
)
const (
// PolicyReasonSucceeded is the reason set when the policy is ready
PolicyReasonSucceeded = "Succeeded"
// PolicyReasonSucceeded is the reason set when the policy is not ready
PolicyReasonFailed = "Failed"
)
// PolicyStatus mostly contains runtime information related to policy execution.
// Deprecated. Policy metrics are now available via the "/metrics" endpoint.
// See: https://kyverno.io/docs/monitoring-kyverno-with-prometheus-metrics/
type PolicyStatus struct {
// Ready indicates if the policy is ready to serve the admission request.
// Deprecated in favor of Conditions
Ready bool `json:"ready" yaml:"ready"`
// Conditions is a list of conditions that apply to the policy
// +optional
Conditions []metav1.Condition `json:"conditions,omitempty"`
// Autogen contains autogen status information
// +optional
Autogen AutogenStatus `json:"autogen" yaml:"autogen"`
// Rules is a list of Rule instances. It contains original rules defined in the spec
// auto generated rules added for pod controllers
Rules []Rule `json:"rules,omitempty" yaml:"rules,omitempty"`
}
func (status *PolicyStatus) SetReady(ready bool) {
condition := metav1.Condition{
Type: PolicyConditionReady,
}
if ready {
condition.Status = metav1.ConditionTrue
condition.Reason = PolicyReasonSucceeded
} else {
condition.Status = metav1.ConditionFalse
condition.Reason = PolicyReasonFailed
}
status.Ready = ready
meta.SetStatusCondition(&status.Conditions, condition)
}
// IsReady indicates if the policy is ready to serve the admission request
func (status *PolicyStatus) IsReady() bool {
condition := meta.FindStatusCondition(status.Conditions, PolicyConditionReady)
return condition != nil && condition.Status == metav1.ConditionTrue
}
// AutogenStatus contains autogen status information.
// It indicates requested, supported and effective autogen controllers used when
// automatically generating rules.
type AutogenStatus struct {
// Requested indicates the autogen requested controllers
Requested []string `json:"requested,omitempty" yaml:"requested,omitempty"`
// Supported indicates the autogen supported controllers
Supported []string `json:"supported,omitempty" yaml:"supported,omitempty"`
// Activated indicates the autogen activated controllers
Activated []string `json:"activated,omitempty" yaml:"activated,omitempty"`
}
// ResourceSpec contains information to identify a resource.
type ResourceSpec struct {
// APIVersion specifies resource apiVersion.

View file

@ -0,0 +1,67 @@
package v1
import (
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
const (
// Ready means that the policy is ready
PolicyConditionReady = "Ready"
)
const (
// PolicyReasonSucceeded is the reason set when the policy is ready
PolicyReasonSucceeded = "Succeeded"
// PolicyReasonSucceeded is the reason set when the policy is not ready
PolicyReasonFailed = "Failed"
)
// PolicyStatus mostly contains runtime information related to policy execution.
// Deprecated. Policy metrics are now available via the "/metrics" endpoint.
// See: https://kyverno.io/docs/monitoring-kyverno-with-prometheus-metrics/
type PolicyStatus struct {
// Ready indicates if the policy is ready to serve the admission request.
// Deprecated in favor of Conditions
Ready bool `json:"ready" yaml:"ready"`
// Conditions is a list of conditions that apply to the policy
// +optional
Conditions []metav1.Condition `json:"conditions,omitempty"`
// Autogen contains autogen status information
// +optional
Autogen AutogenStatus `json:"autogen" yaml:"autogen"`
// Rules is a list of Rule instances. It contains original rules defined in the spec
// auto generated rules added for pod controllers
Rules []Rule `json:"rules,omitempty" yaml:"rules,omitempty"`
}
func (status *PolicyStatus) SetReady(ready bool) {
condition := metav1.Condition{
Type: PolicyConditionReady,
}
if ready {
condition.Status = metav1.ConditionTrue
condition.Reason = PolicyReasonSucceeded
} else {
condition.Status = metav1.ConditionFalse
condition.Reason = PolicyReasonFailed
}
status.Ready = ready
meta.SetStatusCondition(&status.Conditions, condition)
}
// IsReady indicates if the policy is ready to serve the admission request
func (status *PolicyStatus) IsReady() bool {
condition := meta.FindStatusCondition(status.Conditions, PolicyConditionReady)
return condition != nil && condition.Status == metav1.ConditionTrue
}
// AutogenStatus contains autogen status information.
// It indicates requested and effective autogen controllers used when
// automatically generating rules.
type AutogenStatus struct {
// Requested indicates the autogen requested controllers
Requested []string `json:"requested,omitempty" yaml:"requested,omitempty"`
// Activated indicates the autogen activated controllers
Activated []string `json:"activated,omitempty" yaml:"activated,omitempty"`
}

View file

@ -180,11 +180,6 @@ func (in *AutogenStatus) DeepCopyInto(out *AutogenStatus) {
*out = make([]string, len(*in))
copy(*out, *in)
}
if in.Supported != nil {
in, out := &in.Supported, &out.Supported
*out = make([]string, len(*in))
copy(*out, *in)
}
if in.Activated != nil {
in, out := &in.Activated, &out.Activated
*out = make([]string, len(*in))

View file

@ -1548,11 +1548,6 @@ spec:
items:
type: string
type: array
supported:
description: Supported indicates the autogen supported controllers
items:
type: string
type: array
type: object
conditions:
description: Conditions is a list of conditions that apply to the policy
@ -5333,11 +5328,6 @@ spec:
items:
type: string
type: array
supported:
description: Supported indicates the autogen supported controllers
items:
type: string
type: array
type: object
conditions:
description: Conditions is a list of conditions that apply to the policy

View file

@ -2465,11 +2465,6 @@ spec:
items:
type: string
type: array
supported:
description: Supported indicates the autogen supported controllers
items:
type: string
type: array
type: object
conditions:
description: Conditions is a list of conditions that apply to the

View file

@ -2467,11 +2467,6 @@ spec:
items:
type: string
type: array
supported:
description: Supported indicates the autogen supported controllers
items:
type: string
type: array
type: object
conditions:
description: Conditions is a list of conditions that apply to the

View file

@ -2482,11 +2482,6 @@ spec:
items:
type: string
type: array
supported:
description: Supported indicates the autogen supported controllers
items:
type: string
type: array
type: object
conditions:
description: Conditions is a list of conditions that apply to the
@ -8327,11 +8322,6 @@ spec:
items:
type: string
type: array
supported:
description: Supported indicates the autogen supported controllers
items:
type: string
type: array
type: object
conditions:
description: Conditions is a list of conditions that apply to the

View file

@ -2471,11 +2471,6 @@ spec:
items:
type: string
type: array
supported:
description: Supported indicates the autogen supported controllers
items:
type: string
type: array
type: object
conditions:
description: Conditions is a list of conditions that apply to the
@ -8292,11 +8287,6 @@ spec:
items:
type: string
type: array
supported:
description: Supported indicates the autogen supported controllers
items:
type: string
type: array
type: object
conditions:
description: Conditions is a list of conditions that apply to the

View file

@ -730,7 +730,7 @@ attributes for keyless verification, or a nested attestor declaration.</p>
</p>
<p>
<p>AutogenStatus contains autogen status information.
It indicates requested, supported and effective autogen controllers used when
It indicates requested and effective autogen controllers used when
automatically generating rules.</p>
</p>
<table class="table table-striped">
@ -754,17 +754,6 @@ automatically generating rules.</p>
</tr>
<tr>
<td>
<code>supported</code></br>
<em>
[]string
</em>
</td>
<td>
<p>Supported indicates the autogen supported controllers</p>
</td>
</tr>
<tr>
<td>
<code>activated</code></br>
<em>
[]string

View file

@ -705,10 +705,9 @@ func (m *webhookConfigManager) compareAndUpdateWebhook(webhookKind, webhookName
func (m *webhookConfigManager) updateStatus(namespace, name string, ready bool) error {
update := func(meta *metav1.ObjectMeta, spec *kyverno.Spec, status *kyverno.PolicyStatus) bool {
copy := status.DeepCopy()
requested, supported, activated := autogen.GetControllers(meta, spec, m.log)
requested, _, activated := autogen.GetControllers(meta, spec, m.log)
status.SetReady(ready)
status.Autogen.Requested = requested
status.Autogen.Supported = supported
status.Autogen.Activated = activated
status.Rules = spec.Rules
return !reflect.DeepEqual(status, copy)