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

feat: use IsReady method (#3426)

Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com>

Co-authored-by: shuting <shuting@nirmata.com>
This commit is contained in:
Charles-Edouard Brétéché 2022-03-21 10:18:54 +01:00 committed by GitHub
parent bdcecf9882
commit 5816144912
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 19 deletions

View file

@ -197,8 +197,11 @@ func main() {
os.Exit(1)
}
lease := coord.Lease{}
lease.ObjectMeta.Name = "kyvernopre-lock"
lease := coord.Lease{
ObjectMeta: v1.ObjectMeta{
Name: "kyvernopre-lock",
},
}
_, err = kubeClientLeaderElection.CoordinationV1().Leases(getKyvernoNameSpace()).Create(ctx, &lease, v1.CreateOptions{})
if err != nil {
log.Log.Info("Failed to create lease 'kyvernopre-lock'")

View file

@ -48,7 +48,7 @@ func (pc PromConfig) RegisterPolicy(policy interface{}, policyChangeType PolicyC
policyBackgroundMode := metrics.ParsePolicyBackgroundMode(inputPolicy.Spec.Background)
policyType := metrics.Cluster
policyNamespace := "" // doesn't matter for cluster policy
policyName := inputPolicy.ObjectMeta.Name
policyName := inputPolicy.GetName()
if err = pc.registerPolicyChangesMetric(policyValidationMode, policyType, policyBackgroundMode, policyNamespace, policyName, policyChangeType); err != nil {
return err
}
@ -60,8 +60,8 @@ func (pc PromConfig) RegisterPolicy(policy interface{}, policyChangeType PolicyC
}
policyBackgroundMode := metrics.ParsePolicyBackgroundMode(inputPolicy.Spec.Background)
policyType := metrics.Namespaced
policyNamespace := inputPolicy.ObjectMeta.Namespace
policyName := inputPolicy.ObjectMeta.Name
policyNamespace := inputPolicy.GetNamespace()
policyName := inputPolicy.GetName()
if err = pc.registerPolicyChangesMetric(policyValidationMode, policyType, policyBackgroundMode, policyNamespace, policyName, policyChangeType); err != nil {
return err
}

View file

@ -66,12 +66,12 @@ func (pc PromConfig) ProcessEngineResponse(policy kyverno.ClusterPolicy, engineR
}
policyType := metrics.Namespaced
policyBackgroundMode := metrics.ParsePolicyBackgroundMode(policy.Spec.Background)
policyNamespace := policy.ObjectMeta.Namespace
policyNamespace := policy.GetNamespace()
if policyNamespace == "" {
policyNamespace = "-"
policyType = metrics.Cluster
}
policyName := policy.ObjectMeta.Name
policyName := policy.GetName()
resourceSpec := engineResponse.PolicyResponse.Resource

View file

@ -59,12 +59,12 @@ func (pc PromConfig) ProcessEngineResponse(policy kyverno.ClusterPolicy, engineR
}
policyType := metrics.Namespaced
policyBackgroundMode := metrics.ParsePolicyBackgroundMode(policy.Spec.Background)
policyNamespace := policy.ObjectMeta.Namespace
policyNamespace := policy.GetNamespace()
if policyNamespace == "" {
policyNamespace = "-"
policyType = metrics.Cluster
}
policyName := policy.ObjectMeta.Name
policyName := policy.GetName()
resourceSpec := engineResponse.PolicyResponse.Resource

View file

@ -70,8 +70,8 @@ func (pc PromConfig) AddPolicy(policy interface{}) error {
policyBackgroundMode := metrics.ParsePolicyBackgroundMode(inputPolicy.Spec.Background)
policyType := metrics.Cluster
policyNamespace := "" // doesn't matter for cluster policy
policyName := inputPolicy.ObjectMeta.Name
ready := inputPolicy.Status.Ready
policyName := inputPolicy.GetName()
ready := inputPolicy.IsReady()
// registering the metrics on a per-rule basis
for _, rule := range inputPolicy.GetRules() {
ruleName := rule.Name
@ -89,9 +89,9 @@ func (pc PromConfig) AddPolicy(policy interface{}) error {
}
policyBackgroundMode := metrics.ParsePolicyBackgroundMode(inputPolicy.Spec.Background)
policyType := metrics.Namespaced
policyNamespace := inputPolicy.ObjectMeta.Namespace
policyName := inputPolicy.ObjectMeta.Name
ready := inputPolicy.Status.Ready
policyNamespace := inputPolicy.GetNamespace()
policyName := inputPolicy.GetName()
ready := inputPolicy.IsReady()
// registering the metrics on a per-rule basis
for _, rule := range inputPolicy.GetRules() {
ruleName := rule.Name
@ -118,10 +118,10 @@ func (pc PromConfig) RemovePolicy(policy interface{}) error {
policyBackgroundMode := metrics.ParsePolicyBackgroundMode(inputPolicy.Spec.Background)
policyType := metrics.Cluster
policyNamespace := "" // doesn't matter for cluster policy
policyName := inputPolicy.ObjectMeta.Name
policyName := inputPolicy.GetName()
ruleName := rule.Name
ruleType := metrics.ParseRuleType(rule)
ready := inputPolicy.Status.Ready
ready := inputPolicy.IsReady()
if err = pc.registerPolicyRuleInfoMetric(policyValidationMode, policyType, policyBackgroundMode, policyNamespace, policyName, ruleName, ruleType, PolicyRuleDeleted, ready); err != nil {
return err
@ -136,11 +136,11 @@ func (pc PromConfig) RemovePolicy(policy interface{}) error {
}
policyBackgroundMode := metrics.ParsePolicyBackgroundMode(inputPolicy.Spec.Background)
policyType := metrics.Namespaced
policyNamespace := inputPolicy.ObjectMeta.Namespace
policyName := inputPolicy.ObjectMeta.Name
policyNamespace := inputPolicy.GetNamespace()
policyName := inputPolicy.GetName()
ruleName := rule.Name
ruleType := metrics.ParseRuleType(rule)
ready := inputPolicy.Status.Ready
ready := inputPolicy.IsReady()
if err = pc.registerPolicyRuleInfoMetric(policyValidationMode, policyType, policyBackgroundMode, policyNamespace, policyName, ruleName, ruleType, PolicyRuleDeleted, ready); err != nil {
return err