Skip to content

Commit

Permalink
fix: ruleset eventhandler (#85)
Browse files Browse the repository at this point in the history
fix ruleset eventhandler
  • Loading branch information
Eikykun authored Sep 5, 2023
1 parent 4dbcf84 commit dcbc2da
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/controllers/ruleset/eventhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (p *RulesetEventHandler) Create(e event.CreateEvent, q workqueue.RateLimiti
func (p *RulesetEventHandler) Update(e event.UpdateEvent, q workqueue.RateLimitingInterface) {
oldRuleset := e.ObjectOld.(*appsv1alpha1.RuleSet)
newRuleset := e.ObjectNew.(*appsv1alpha1.RuleSet)
if equality.Semantic.DeepEqual(oldRuleset.Spec, newRuleset.Spec) {
if equality.Semantic.DeepEqual(oldRuleset.Spec, newRuleset.Spec) && newRuleset.DeletionTimestamp == nil {
return
}
q.Add(reconcile.Request{NamespacedName: types.NamespacedName{
Expand Down
4 changes: 2 additions & 2 deletions pkg/controllers/ruleset/ruleset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (r *RuleSetReconciler) Reconcile(ctx context.Context, request reconcile.Req
}

if !rulesetutils.RulesetVersionExpectation.SatisfiedExpectations(commonutils.ObjectKeyString(ruleSet), ruleSet.ResourceVersion) {
logger.Info("ruleSet's resourceVerison is too old, retry later", "resourceVerison.now", ruleSet.ResourceVersion)
logger.Info("ruleSet's resourceVersion is too old, retry later", "resourceVersion.now", ruleSet.ResourceVersion)
return reconcile.Result{}, nil
}

Expand Down Expand Up @@ -272,7 +272,7 @@ func (r *RuleSetReconciler) cleanUpRuleSetPods(ctx context.Context, ruleSet *app
return nil
}

func (r *RuleSetReconciler) updateRuleSetOnPod(ctx context.Context, ruleSet, name, namespace string, fn func(pod *corev1.Pod, name string) bool) (*corev1.Pod, error) {
func (r *RuleSetReconciler) updateRuleSetOnPod(ctx context.Context, ruleSet, name, namespace string, fn func(*corev1.Pod, string) bool) (*corev1.Pod, error) {
pod := &corev1.Pod{}
return pod, retry.RetryOnConflict(retry.DefaultRetry, func() error {
if err := r.Client.Get(ctx, types.NamespacedName{Namespace: namespace, Name: name}, pod); err != nil {
Expand Down
7 changes: 6 additions & 1 deletion pkg/controllers/ruleset/ruleset_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/labels"
Expand Down Expand Up @@ -85,7 +86,6 @@ func TestRuleSet(t *testing.T) {
for _, po := range podList.Items {
g.Expect(c.Delete(ctx, &po)).NotTo(gomega.HaveOccurred())
}
g.Expect(c.Delete(ctx, rs)).NotTo(gomega.HaveOccurred())
}()

g.Expect(c.List(ctx, podList, &client.ListOptions{
Expand Down Expand Up @@ -148,6 +148,11 @@ func TestRuleSet(t *testing.T) {
printJson(rs)
g.Expect(c.List(ctx, ruleSetList, &client.ListOptions{FieldSelector: fields.OneTermEqualSelector(inject.FieldIndexRuleSet, "pod-test-1")})).NotTo(gomega.HaveOccurred())
g.Expect(len(ruleSetList.Items)).Should(gomega.BeEquivalentTo(0))

g.Expect(c.Delete(ctx, rs)).NotTo(gomega.HaveOccurred())
waitProcessFinished(request)
err := c.Get(ctx, types.NamespacedName{Namespace: "default", Name: "ruleset-default"}, rs)
g.Expect(errors.IsNotFound(err)).Should(gomega.BeTrue())
}

const (
Expand Down

0 comments on commit dcbc2da

Please sign in to comment.