Skip to content

Commit 8e0f05e

Browse files
committed
resolve comment
1 parent 718ccf0 commit 8e0f05e

File tree

3 files changed

+49
-65
lines changed

3 files changed

+49
-65
lines changed

internal/controller/ingress_controller.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,31 @@ func (r *IngressReconciler) listIngressesBySecret(ctx context.Context, obj clien
356356
})
357357
}
358358
}
359-
return requests
359+
360+
gatewayProxyList := &v1alpha1.GatewayProxyList{}
361+
if err := r.List(ctx, gatewayProxyList, client.MatchingFields{
362+
indexer.SecretIndexRef: indexer.GenIndexKey(secret.GetNamespace(), secret.GetName()),
363+
}); err != nil {
364+
r.Log.Error(err, "failed to list gateway proxies by secret", "secret", secret.GetName())
365+
return nil
366+
}
367+
368+
for _, gatewayProxy := range gatewayProxyList.Items {
369+
var (
370+
ingressClassList networkingv1.IngressClassList
371+
indexKey = indexer.GenIndexKey(gatewayProxy.GetNamespace(), gatewayProxy.GetName())
372+
matchingFields = client.MatchingFields{indexer.IngressClassParametersRef: indexKey}
373+
)
374+
if err := r.List(ctx, &ingressClassList, matchingFields); err != nil {
375+
r.Log.Error(err, "failed to list ingress classes for gateway proxy", "gatewayproxy", indexKey)
376+
continue
377+
}
378+
for _, ingressClass := range ingressClassList.Items {
379+
requests = append(requests, r.listIngressForIngressClass(ctx, &ingressClass)...)
380+
}
381+
}
382+
383+
return distinctRequests(requests)
360384
}
361385

362386
func (r *IngressReconciler) listIngressForBackendTrafficPolicy(ctx context.Context, obj client.Object) (requests []reconcile.Request) {

internal/controller/ingressclass_controller.go

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"fmt"
66

7-
"github.com/api7/gopkg/pkg/log"
87
"github.com/go-logr/logr"
98
corev1 "k8s.io/api/core/v1"
109
networkingv1 "k8s.io/api/networking/v1"
@@ -17,6 +16,8 @@ import (
1716
"sigs.k8s.io/controller-runtime/pkg/predicate"
1817
"sigs.k8s.io/controller-runtime/pkg/reconcile"
1918

19+
"github.com/api7/gopkg/pkg/log"
20+
2021
"github.com/api7/api7-ingress-controller/api/v1alpha1"
2122
"github.com/api7/api7-ingress-controller/internal/controller/indexer"
2223
"github.com/api7/api7-ingress-controller/internal/provider"
@@ -154,29 +155,10 @@ func (r *IngressClassReconciler) listIngressClassesForSecret(ctx context.Context
154155
// 2. list ingress classes by gateway proxies
155156
requests := make([]reconcile.Request, 0)
156157
for _, gatewayProxy := range gatewayProxyList.Items {
157-
ingressClassList := &networkingv1.IngressClassList{}
158-
if err := r.List(ctx, ingressClassList, client.MatchingFields{
159-
indexer.IngressClassParametersRef: indexer.GenIndexKey(gatewayProxy.GetNamespace(), gatewayProxy.GetName()),
160-
}); err != nil {
161-
r.Log.Error(err, "failed to list ingress classes by secret", "secret", secret.GetName())
162-
return nil
163-
}
164-
for _, ingressClass := range ingressClassList.Items {
165-
if !r.matchesController(&ingressClass) {
166-
continue
167-
}
168-
requests = append(requests, reconcile.Request{
169-
NamespacedName: client.ObjectKey{
170-
Name: ingressClass.GetName(),
171-
Namespace: ingressClass.GetNamespace(),
172-
},
173-
})
174-
}
158+
requests = append(requests, r.listIngressClassesForGatewayProxy(ctx, &gatewayProxy)...)
175159
}
176160

177-
requests = distinctRequests(requests)
178-
179-
return requests
161+
return distinctRequests(requests)
180162
}
181163

182164
func (r *IngressClassReconciler) processInfrastructure(tctx *provider.TranslateContext, ingressClass *networkingv1.IngressClass) error {

test/e2e/ingress/ingress.go

Lines changed: 20 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -867,28 +867,10 @@ spec:
867867
name: httpbin-service-e2e-test
868868
port:
869869
number: 80
870-
`
871-
const ingressSpec2 = `
872-
apiVersion: networking.k8s.io/v1
873-
kind: Ingress
874-
metadata:
875-
name: api7-ingress
876-
spec:
877-
ingressClassName: api7-ingress-class
878-
rules:
879-
- host: ingress.example.com
880-
http:
881-
paths:
882-
- path: /put
883-
pathType: Prefix
884-
backend:
885-
service:
886-
name: httpbin-service-e2e-test
887-
port:
888-
number: 80
889870
`
890871
var (
891-
err error
872+
additionalGatewayGroupID string
873+
err error
892874
)
893875

894876
It("GatewayProxy reference Secret", func() {
@@ -917,35 +899,31 @@ spec:
917899
}).WithTimeout(8 * time.Second).ProbeEvery(time.Second).
918900
Should(Equal(http.StatusOK))
919901

920-
// update gateway group admin-key
921-
adminKey := s.GetAdminKey(s.CurrentGatewayGroupID())
902+
By("create additional gateway group to get new admin key")
903+
additionalGatewayGroupID, _, err = s.CreateAdditionalGatewayGroup("gateway-proxy-update")
904+
Expect(err).NotTo(HaveOccurred(), "creating additional gateway group")
905+
906+
client, err := s.NewAPISIXClientForGatewayGroup(additionalGatewayGroupID)
907+
Expect(err).NotTo(HaveOccurred(), "creating APISIX client for additional gateway group")
922908

923-
// should fail to request provider service and get 401 because the admin-key is changed
924-
By("create Ingress")
925-
err = s.CreateResourceFromStringWithNamespace(ingressSpec2, s.Namespace())
926-
s.WaitControllerManagerLog("Request failed with status code 401", 0, 10*time.Second)
909+
By("Ingress not found for additional gateway group")
910+
client.
911+
GET("/get").
912+
WithHost("ingress.example.com").
913+
Expect().
914+
Status(http.StatusNotFound)
927915

928-
// the new Ingress should not work consistently
929-
Consistently(func() int {
930-
return s.NewAPISIXClient().
931-
GET("/put").
932-
WithHost("ingress.example.com").
933-
Expect().Raw().StatusCode
934-
}).WithTimeout(8 * time.Second).ProbeEvery(time.Second).
935-
Should(Equal(http.StatusNotFound))
916+
resources, exists := s.GetAdditionalGatewayGroup(additionalGatewayGroupID)
917+
Expect(exists).To(BeTrue(), "additional gateway group should exist")
936918

937919
By("update secret")
938-
err = s.CreateResourceFromStringWithNamespace(fmt.Sprintf(secretSpec, base64.StdEncoding.EncodeToString([]byte(adminKey))), s.Namespace())
920+
err = s.CreateResourceFromStringWithNamespace(fmt.Sprintf(secretSpec, base64.StdEncoding.EncodeToString([]byte(resources.AdminAPIKey))), s.Namespace())
939921
Expect(err).NotTo(HaveOccurred(), "creating secret")
940922

941-
By("create Ingress again")
942-
err = s.CreateResourceFromStringWithNamespace(ingressSpec2, s.Namespace())
943-
Expect(err).NotTo(HaveOccurred(), "creating Ingress with path prefix /put")
944-
945-
By("verify Ingress works")
923+
By("verify Ingress works for additional gateway group")
946924
Eventually(func() int {
947-
return s.NewAPISIXClient().
948-
PUT("/put").
925+
return client.
926+
GET("/get").
949927
WithHost("ingress.example.com").
950928
Expect().Raw().StatusCode
951929
}).WithTimeout(8 * time.Second).ProbeEvery(time.Second).

0 commit comments

Comments
 (0)