mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-31 03:45:17 +00:00
feat: add support for ready message (#6670)
* feat: add support for ready message Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * Update .vscode/launch.json Signed-off-by: shuting <shutting06@gmail.com> --------- Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> Signed-off-by: shuting <shutting06@gmail.com> Co-authored-by: shuting <shutting06@gmail.com>
This commit is contained in:
parent
cb6fd07899
commit
7c571f76f4
11 changed files with 47 additions and 6 deletions
|
@ -23,6 +23,7 @@ import (
|
||||||
// +kubebuilder:printcolumn:name="Mutate",type=integer,JSONPath=`.status.rulecount.mutate`,priority=1
|
// +kubebuilder:printcolumn:name="Mutate",type=integer,JSONPath=`.status.rulecount.mutate`,priority=1
|
||||||
// +kubebuilder:printcolumn:name="Generate",type=integer,JSONPath=`.status.rulecount.generate`,priority=1
|
// +kubebuilder:printcolumn:name="Generate",type=integer,JSONPath=`.status.rulecount.generate`,priority=1
|
||||||
// +kubebuilder:printcolumn:name="Verifyimages",type=integer,JSONPath=`.status.rulecount.verifyimages`,priority=1
|
// +kubebuilder:printcolumn:name="Verifyimages",type=integer,JSONPath=`.status.rulecount.verifyimages`,priority=1
|
||||||
|
// +kubebuilder:printcolumn:name="MESSAGE",type=string,JSONPath=`.status.conditions[?(@.type == "Ready")].message`
|
||||||
// +kubebuilder:storageversion
|
// +kubebuilder:storageversion
|
||||||
|
|
||||||
// ClusterPolicy declares validation, mutation, and generation behaviors for matching resources.
|
// ClusterPolicy declares validation, mutation, and generation behaviors for matching resources.
|
||||||
|
|
|
@ -48,9 +48,10 @@ type RuleCountStatus struct {
|
||||||
VerifyImages int `json:"verifyimages" yaml:"verifyimages"`
|
VerifyImages int `json:"verifyimages" yaml:"verifyimages"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (status *PolicyStatus) SetReady(ready bool) {
|
func (status *PolicyStatus) SetReady(ready bool, message string) {
|
||||||
condition := metav1.Condition{
|
condition := metav1.Condition{
|
||||||
Type: PolicyConditionReady,
|
Type: PolicyConditionReady,
|
||||||
|
Message: message,
|
||||||
}
|
}
|
||||||
if ready {
|
if ready {
|
||||||
condition.Status = metav1.ConditionTrue
|
condition.Status = metav1.ConditionTrue
|
||||||
|
|
|
@ -22,6 +22,7 @@ import (
|
||||||
// +kubebuilder:printcolumn:name="Generate",type=integer,JSONPath=`.status.rulecount.generate`,priority=1
|
// +kubebuilder:printcolumn:name="Generate",type=integer,JSONPath=`.status.rulecount.generate`,priority=1
|
||||||
// +kubebuilder:printcolumn:name="Verifyimages",type=integer,JSONPath=`.status.rulecount.verifyimages`,priority=1
|
// +kubebuilder:printcolumn:name="Verifyimages",type=integer,JSONPath=`.status.rulecount.verifyimages`,priority=1
|
||||||
// +kubebuilder:resource:shortName=pol,categories=kyverno
|
// +kubebuilder:resource:shortName=pol,categories=kyverno
|
||||||
|
// +kubebuilder:printcolumn:name="MESSAGE",type=string,JSONPath=`.status.conditions[?(@.type == "Ready")].message`
|
||||||
// +kubebuilder:storageversion
|
// +kubebuilder:storageversion
|
||||||
|
|
||||||
// Policy declares validation, mutation, and generation behaviors for matching resources.
|
// Policy declares validation, mutation, and generation behaviors for matching resources.
|
||||||
|
|
|
@ -24,6 +24,7 @@ import (
|
||||||
// +kubebuilder:printcolumn:name="Mutate",type=integer,JSONPath=`.status.rulecount.mutate`,priority=1
|
// +kubebuilder:printcolumn:name="Mutate",type=integer,JSONPath=`.status.rulecount.mutate`,priority=1
|
||||||
// +kubebuilder:printcolumn:name="Generate",type=integer,JSONPath=`.status.rulecount.generate`,priority=1
|
// +kubebuilder:printcolumn:name="Generate",type=integer,JSONPath=`.status.rulecount.generate`,priority=1
|
||||||
// +kubebuilder:printcolumn:name="Verifyimages",type=integer,JSONPath=`.status.rulecount.verifyimages`,priority=1
|
// +kubebuilder:printcolumn:name="Verifyimages",type=integer,JSONPath=`.status.rulecount.verifyimages`,priority=1
|
||||||
|
// +kubebuilder:printcolumn:name="MESSAGE",type=string,JSONPath=`.status.conditions[?(@.type == "Ready")].message`
|
||||||
|
|
||||||
// ClusterPolicy declares validation, mutation, and generation behaviors for matching resources.
|
// ClusterPolicy declares validation, mutation, and generation behaviors for matching resources.
|
||||||
type ClusterPolicy struct {
|
type ClusterPolicy struct {
|
||||||
|
|
|
@ -22,6 +22,7 @@ import (
|
||||||
// +kubebuilder:printcolumn:name="Mutate",type=integer,JSONPath=`.status.rulecount.mutate`,priority=1
|
// +kubebuilder:printcolumn:name="Mutate",type=integer,JSONPath=`.status.rulecount.mutate`,priority=1
|
||||||
// +kubebuilder:printcolumn:name="Generate",type=integer,JSONPath=`.status.rulecount.generate`,priority=1
|
// +kubebuilder:printcolumn:name="Generate",type=integer,JSONPath=`.status.rulecount.generate`,priority=1
|
||||||
// +kubebuilder:printcolumn:name="Verifyimages",type=integer,JSONPath=`.status.rulecount.verifyimages`,priority=1
|
// +kubebuilder:printcolumn:name="Verifyimages",type=integer,JSONPath=`.status.rulecount.verifyimages`,priority=1
|
||||||
|
// +kubebuilder:printcolumn:name="MESSAGE",type=string,JSONPath=`.status.conditions[?(@.type == "Ready")].message`
|
||||||
// +kubebuilder:resource:shortName=pol,categories=kyverno
|
// +kubebuilder:resource:shortName=pol,categories=kyverno
|
||||||
|
|
||||||
// Policy declares validation, mutation, and generation behaviors for matching resources.
|
// Policy declares validation, mutation, and generation behaviors for matching resources.
|
||||||
|
|
|
@ -3438,6 +3438,9 @@ spec:
|
||||||
name: Verifyimages
|
name: Verifyimages
|
||||||
priority: 1
|
priority: 1
|
||||||
type: integer
|
type: integer
|
||||||
|
- jsonPath: .status.conditions[?(@.type == "Ready")].message
|
||||||
|
name: MESSAGE
|
||||||
|
type: string
|
||||||
name: v1
|
name: v1
|
||||||
schema:
|
schema:
|
||||||
openAPIV3Schema:
|
openAPIV3Schema:
|
||||||
|
@ -10152,6 +10155,9 @@ spec:
|
||||||
name: Verifyimages
|
name: Verifyimages
|
||||||
priority: 1
|
priority: 1
|
||||||
type: integer
|
type: integer
|
||||||
|
- jsonPath: .status.conditions[?(@.type == "Ready")].message
|
||||||
|
name: MESSAGE
|
||||||
|
type: string
|
||||||
name: v2beta1
|
name: v2beta1
|
||||||
schema:
|
schema:
|
||||||
openAPIV3Schema:
|
openAPIV3Schema:
|
||||||
|
@ -16622,6 +16628,9 @@ spec:
|
||||||
name: Verifyimages
|
name: Verifyimages
|
||||||
priority: 1
|
priority: 1
|
||||||
type: integer
|
type: integer
|
||||||
|
- jsonPath: .status.conditions[?(@.type == "Ready")].message
|
||||||
|
name: MESSAGE
|
||||||
|
type: string
|
||||||
name: v1
|
name: v1
|
||||||
schema:
|
schema:
|
||||||
openAPIV3Schema:
|
openAPIV3Schema:
|
||||||
|
@ -23338,6 +23347,9 @@ spec:
|
||||||
name: Verifyimages
|
name: Verifyimages
|
||||||
priority: 1
|
priority: 1
|
||||||
type: integer
|
type: integer
|
||||||
|
- jsonPath: .status.conditions[?(@.type == "Ready")].message
|
||||||
|
name: MESSAGE
|
||||||
|
type: string
|
||||||
name: v2beta1
|
name: v2beta1
|
||||||
schema:
|
schema:
|
||||||
openAPIV3Schema:
|
openAPIV3Schema:
|
||||||
|
|
|
@ -52,6 +52,9 @@ spec:
|
||||||
name: Verifyimages
|
name: Verifyimages
|
||||||
priority: 1
|
priority: 1
|
||||||
type: integer
|
type: integer
|
||||||
|
- jsonPath: .status.conditions[?(@.type == "Ready")].message
|
||||||
|
name: MESSAGE
|
||||||
|
type: string
|
||||||
name: v1
|
name: v1
|
||||||
schema:
|
schema:
|
||||||
openAPIV3Schema:
|
openAPIV3Schema:
|
||||||
|
@ -6766,6 +6769,9 @@ spec:
|
||||||
name: Verifyimages
|
name: Verifyimages
|
||||||
priority: 1
|
priority: 1
|
||||||
type: integer
|
type: integer
|
||||||
|
- jsonPath: .status.conditions[?(@.type == "Ready")].message
|
||||||
|
name: MESSAGE
|
||||||
|
type: string
|
||||||
name: v2beta1
|
name: v2beta1
|
||||||
schema:
|
schema:
|
||||||
openAPIV3Schema:
|
openAPIV3Schema:
|
||||||
|
|
|
@ -52,6 +52,9 @@ spec:
|
||||||
name: Verifyimages
|
name: Verifyimages
|
||||||
priority: 1
|
priority: 1
|
||||||
type: integer
|
type: integer
|
||||||
|
- jsonPath: .status.conditions[?(@.type == "Ready")].message
|
||||||
|
name: MESSAGE
|
||||||
|
type: string
|
||||||
name: v1
|
name: v1
|
||||||
schema:
|
schema:
|
||||||
openAPIV3Schema:
|
openAPIV3Schema:
|
||||||
|
@ -6768,6 +6771,9 @@ spec:
|
||||||
name: Verifyimages
|
name: Verifyimages
|
||||||
priority: 1
|
priority: 1
|
||||||
type: integer
|
type: integer
|
||||||
|
- jsonPath: .status.conditions[?(@.type == "Ready")].message
|
||||||
|
name: MESSAGE
|
||||||
|
type: string
|
||||||
name: v2beta1
|
name: v2beta1
|
||||||
schema:
|
schema:
|
||||||
openAPIV3Schema:
|
openAPIV3Schema:
|
||||||
|
|
|
@ -3521,6 +3521,9 @@ spec:
|
||||||
name: Verifyimages
|
name: Verifyimages
|
||||||
priority: 1
|
priority: 1
|
||||||
type: integer
|
type: integer
|
||||||
|
- jsonPath: .status.conditions[?(@.type == "Ready")].message
|
||||||
|
name: MESSAGE
|
||||||
|
type: string
|
||||||
name: v1
|
name: v1
|
||||||
schema:
|
schema:
|
||||||
openAPIV3Schema:
|
openAPIV3Schema:
|
||||||
|
@ -10235,6 +10238,9 @@ spec:
|
||||||
name: Verifyimages
|
name: Verifyimages
|
||||||
priority: 1
|
priority: 1
|
||||||
type: integer
|
type: integer
|
||||||
|
- jsonPath: .status.conditions[?(@.type == "Ready")].message
|
||||||
|
name: MESSAGE
|
||||||
|
type: string
|
||||||
name: v2beta1
|
name: v2beta1
|
||||||
schema:
|
schema:
|
||||||
openAPIV3Schema:
|
openAPIV3Schema:
|
||||||
|
@ -16705,6 +16711,9 @@ spec:
|
||||||
name: Verifyimages
|
name: Verifyimages
|
||||||
priority: 1
|
priority: 1
|
||||||
type: integer
|
type: integer
|
||||||
|
- jsonPath: .status.conditions[?(@.type == "Ready")].message
|
||||||
|
name: MESSAGE
|
||||||
|
type: string
|
||||||
name: v1
|
name: v1
|
||||||
schema:
|
schema:
|
||||||
openAPIV3Schema:
|
openAPIV3Schema:
|
||||||
|
@ -23421,6 +23430,9 @@ spec:
|
||||||
name: Verifyimages
|
name: Verifyimages
|
||||||
priority: 1
|
priority: 1
|
||||||
type: integer
|
type: integer
|
||||||
|
- jsonPath: .status.conditions[?(@.type == "Ready")].message
|
||||||
|
name: MESSAGE
|
||||||
|
type: string
|
||||||
name: v2beta1
|
name: v2beta1
|
||||||
schema:
|
schema:
|
||||||
openAPIV3Schema:
|
openAPIV3Schema:
|
||||||
|
|
|
@ -437,17 +437,17 @@ func (c *controller) updatePolicyStatuses(ctx context.Context) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
ready := true
|
ready, message := true, "Ready"
|
||||||
if c.autoUpdateWebhooks {
|
if c.autoUpdateWebhooks {
|
||||||
for _, set := range c.policyState {
|
for _, set := range c.policyState {
|
||||||
if !set.Has(policyKey) {
|
if !set.Has(policyKey) {
|
||||||
ready = false
|
ready, message = false, "Not ready yet"
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
status := policy.GetStatus()
|
status := policy.GetStatus()
|
||||||
status.SetReady(ready)
|
status.SetReady(ready, message)
|
||||||
status.Autogen.Rules = nil
|
status.Autogen.Rules = nil
|
||||||
rules := autogen.ComputeRules(policy)
|
rules := autogen.ComputeRules(policy)
|
||||||
setRuleCount(rules, status)
|
setRuleCount(rules, status)
|
||||||
|
|
|
@ -25,7 +25,7 @@ func (inner HttpHandler) WithTrace(name string) HttpHandler {
|
||||||
},
|
},
|
||||||
trace.WithAttributes(
|
trace.WithAttributes(
|
||||||
semconv.HTTPRequestContentLengthKey.Int64(request.ContentLength),
|
semconv.HTTPRequestContentLengthKey.Int64(request.ContentLength),
|
||||||
// semconv.HTTPHostKey.String(tracing.StringValue(request.Host)),
|
semconv.NetSockPeerAddrKey.String(tracing.StringValue(request.Host)),
|
||||||
semconv.HTTPMethodKey.String(tracing.StringValue(request.Method)),
|
semconv.HTTPMethodKey.String(tracing.StringValue(request.Method)),
|
||||||
semconv.HTTPURLKey.String(tracing.StringValue(request.RequestURI)),
|
semconv.HTTPURLKey.String(tracing.StringValue(request.RequestURI)),
|
||||||
),
|
),
|
||||||
|
|
Loading…
Add table
Reference in a new issue