Skip to content

Commit 5edce5b

Browse files
committed
fix: review
Signed-off-by: ashing <[email protected]>
1 parent 5e02d1b commit 5edce5b

File tree

3 files changed

+6
-52
lines changed

3 files changed

+6
-52
lines changed

internal/controller/ingress_controller.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ func (r *IngressReconciler) SetupWithManager(mgr ctrl.Manager) error {
4242
predicate.NewPredicateFuncs(r.checkIngressClass),
4343
),
4444
).
45-
WithEventFilter(CombinedPredicate{}).
45+
WithEventFilter(
46+
predicate.Or(
47+
predicate.GenerationChangedPredicate{},
48+
predicate.AnnotationChangedPredicate{},
49+
),
50+
).
4651
Watches(
4752
&networkingv1.IngressClass{},
4853
handler.EnqueueRequestsFromMapFunc(r.listIngressForIngressClass),

internal/controller/utils.go

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,15 @@ package controller
33
import (
44
"context"
55
"fmt"
6-
"reflect"
76
"strings"
87

98
"github.com/api7/api7-ingress-controller/internal/controller/config"
10-
"github.com/api7/gopkg/pkg/log"
119
"github.com/samber/lo"
1210
corev1 "k8s.io/api/core/v1"
1311
networkingv1 "k8s.io/api/networking/v1"
1412
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1513
"k8s.io/apimachinery/pkg/labels"
1614
"sigs.k8s.io/controller-runtime/pkg/client"
17-
"sigs.k8s.io/controller-runtime/pkg/event"
18-
"sigs.k8s.io/controller-runtime/pkg/predicate"
1915
"sigs.k8s.io/controller-runtime/pkg/reconcile"
2016
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
2117
)
@@ -763,40 +759,3 @@ func SplitMetaNamespaceKey(key string) (namespace, name string, err error) {
763759

764760
return "", "", fmt.Errorf("unexpected key format: %q", key)
765761
}
766-
767-
type CombinedPredicate struct {
768-
predicate.GenerationChangedPredicate
769-
}
770-
771-
func (c CombinedPredicate) Update(e event.UpdateEvent) bool {
772-
if isNil(e.ObjectOld) {
773-
log.Debugw("Update event has no old object for update")
774-
return false
775-
}
776-
if isNil(e.ObjectNew) {
777-
log.Debugw("Update event has no new object for update")
778-
return false
779-
}
780-
781-
_, ok := e.ObjectNew.(*networkingv1.IngressClass)
782-
if ok {
783-
log.Debugw("IngressClass update event")
784-
return true
785-
}
786-
787-
log.Debugw("other update event")
788-
// if the object is not IngressClass, return the result of GenerationChangedPredicate.Update
789-
return c.GenerationChangedPredicate.Update(e)
790-
}
791-
792-
func isNil(arg any) bool {
793-
if v := reflect.ValueOf(arg); !v.IsValid() || ((v.Kind() == reflect.Ptr ||
794-
v.Kind() == reflect.Interface ||
795-
v.Kind() == reflect.Slice ||
796-
v.Kind() == reflect.Map ||
797-
v.Kind() == reflect.Chan ||
798-
v.Kind() == reflect.Func) && v.IsNil()) {
799-
return true
800-
}
801-
return false
802-
}

test/e2e/ingress/ingress.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,6 @@ spec:
7171
Expect(err).NotTo(HaveOccurred(), "creating Ingress")
7272
time.Sleep(5 * time.Second)
7373

74-
By("check Ingress status")
75-
ingressYaml, err := s.GetResourceYaml("Ingress", "api7-ingress")
76-
Expect(err).NotTo(HaveOccurred(), "getting Ingress yaml")
77-
Expect(ingressYaml).To(ContainSubstring("example.com"), "checking Ingress host")
78-
7974
By("verify HTTP request")
8075
s.NewAPISIXClient().
8176
GET("/get").
@@ -185,11 +180,6 @@ spec:
185180
Expect(err).NotTo(HaveOccurred(), "creating Ingress without IngressClass")
186181
time.Sleep(5 * time.Second)
187182

188-
By("check Default Ingress")
189-
ingressYaml, err := s.GetResourceYaml("Ingress", "api7-ingress-default")
190-
Expect(err).NotTo(HaveOccurred(), "getting Default Ingress yaml")
191-
Expect(ingressYaml).To(ContainSubstring("default.example.com"), "checking Default Ingress host")
192-
193183
By("verify default ingress")
194184
s.NewAPISIXClient().
195185
GET("/get").

0 commit comments

Comments
 (0)