mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-31 03:45:17 +00:00
Merge pull request #1440 from NoSkillGirl/bug/generate_refactoring
Bug/generate refactoring
This commit is contained in:
commit
9397a2f157
4 changed files with 14 additions and 14 deletions
|
@ -28,7 +28,7 @@ func AddLabels(client *kyvernoclient.Clientset, grInformer kyvernoinformer.Gener
|
|||
for _, gr := range grList {
|
||||
|
||||
grLabels := gr.Labels
|
||||
if grLabels == nil || len(grLabels) == 0 {
|
||||
if len(grLabels) == 0 {
|
||||
grLabels = make(map[string]string)
|
||||
}
|
||||
grLabels["generate.kyverno.io/policy-name"] = gr.Spec.Policy
|
||||
|
@ -53,7 +53,6 @@ func AddLabels(client *kyvernoclient.Clientset, grInformer kyvernoinformer.Gener
|
|||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func addLabelForGR(name string, namespace string, client *kyvernoclient.Clientset, grInformer kyvernoinformer.GenerateRequestInformer) error {
|
||||
|
@ -64,7 +63,7 @@ func addLabelForGR(name string, namespace string, client *kyvernoclient.Clientse
|
|||
}
|
||||
|
||||
grLabels := gr.Labels
|
||||
if grLabels == nil || len(grLabels) == 0 {
|
||||
if len(grLabels) == 0 {
|
||||
grLabels = make(map[string]string)
|
||||
}
|
||||
grLabels["generate.kyverno.io/policy-name"] = gr.Spec.Policy
|
||||
|
|
|
@ -2,8 +2,9 @@ package policy
|
|||
|
||||
import (
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"math/big"
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
|
@ -440,19 +441,21 @@ func updateGR(kyvernoClient *kyvernoclient.Clientset, policyKey string, grList [
|
|||
for _, gr := range grList {
|
||||
if policyKey == gr.Spec.Policy {
|
||||
grLabels := gr.Labels
|
||||
if grLabels == nil || len(grLabels) == 0 {
|
||||
if len(grLabels) == 0 {
|
||||
grLabels = make(map[string]string)
|
||||
}
|
||||
grLabels["policy-update"] = fmt.Sprintf("revision-count-%d", rand.Intn(100000))
|
||||
// gr.SetLabels(map[string]string{
|
||||
// "policy-update": fmt.Sprintf("revision-count-%d", rand.Intn(100000)),
|
||||
// })
|
||||
|
||||
nBig, err := rand.Int(rand.Reader, big.NewInt(100000))
|
||||
if err != nil {
|
||||
logger.Error(err, "failed to generate random interger")
|
||||
}
|
||||
grLabels["policy-update"] = fmt.Sprintf("revision-count-%d", nBig.Int64())
|
||||
gr.SetLabels(grLabels)
|
||||
_, err := kyvernoClient.KyvernoV1().GenerateRequests(config.KyvernoNamespace).Update(context.TODO(), gr, metav1.UpdateOptions{})
|
||||
|
||||
_, err = kyvernoClient.KyvernoV1().GenerateRequests(config.KyvernoNamespace).Update(context.TODO(), gr, metav1.UpdateOptions{})
|
||||
if err != nil {
|
||||
logger.Error(err, "failed to update gr", "name", gr.GetName())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -155,7 +155,7 @@ func retryApplyResource(client *kyvernoclient.Clientset, grSpec kyverno.Generate
|
|||
for _, v := range grList {
|
||||
|
||||
grLabels := gr.Labels
|
||||
if grLabels == nil || len(grLabels) == 0 {
|
||||
if len(grLabels) == 0 {
|
||||
grLabels = make(map[string]string)
|
||||
}
|
||||
grLabels["resources-update"] = "true"
|
||||
|
|
|
@ -86,8 +86,6 @@ func (ws *WebhookServer) HandleGenerate(request *v1beta1.AdmissionRequest, polic
|
|||
if request.Operation == v1beta1.Update {
|
||||
ws.handleUpdate(request)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
//HandleUpdate handles admission-requests for update
|
||||
|
|
Loading…
Add table
Reference in a new issue