diff --git a/.github/workflows/conformance-test.yml b/.github/workflows/conformance-test.yml index 16b03fd97..54f5d6bfe 100644 --- a/.github/workflows/conformance-test.yml +++ b/.github/workflows/conformance-test.yml @@ -32,7 +32,7 @@ jobs: run: | go install sigs.k8s.io/kind@v0.23.0 - e2e-test: + conformance-test: needs: - prepare runs-on: buildjet-2vcpu-ubuntu-2204 @@ -85,11 +85,29 @@ jobs: shell: bash env: API7_EE_LICENSE: ${{ secrets.API7_EE_LICENSE }} + continue-on-error: true run: | make conformance-test - + - name: Upload Gateway API Conformance Report + if: ${{ github.event_name == 'push' }} uses: actions/upload-artifact@v4 with: name: api7-ingress-controller-conformance-report.yaml path: api7-ingress-controller-conformance-report.yaml + + - name: Format Conformance Test Report + if: ${{ github.event_name == 'pull_request' }} + run: | + echo '# conformance test report' > report.md + echo '```yaml' >> report.md + cat api7-ingress-controller-conformance-report.yaml >> report.md + echo '```' >> report.md + + - name: Report Conformance Test Result to PR Comment + if: ${{ github.event_name == 'pull_request' }} + uses: mshick/add-pr-comment@v2 + with: + message-id: '${{ matrix.target }}' + message-path: | + report.md diff --git a/internal/controller/httproute_controller.go b/internal/controller/httproute_controller.go index 89d1fd9c0..77e7251e8 100644 --- a/internal/controller/httproute_controller.go +++ b/internal/controller/httproute_controller.go @@ -12,7 +12,9 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/builder" "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/event" "sigs.k8s.io/controller-runtime/pkg/handler" "sigs.k8s.io/controller-runtime/pkg/predicate" "sigs.k8s.io/controller-runtime/pkg/reconcile" @@ -47,6 +49,25 @@ func (r *HTTPRouteReconciler) SetupWithManager(mgr ctrl.Manager) error { Watches(&v1alpha1.PluginConfig{}, handler.EnqueueRequestsFromMapFunc(r.listHTTPRoutesByExtensionRef), ). + Watches(&gatewayv1.Gateway{}, + handler.EnqueueRequestsFromMapFunc(r.listHTTPRoutesForGateway), + builder.WithPredicates( + predicate.Funcs{ + GenericFunc: func(e event.GenericEvent) bool { + return false + }, + DeleteFunc: func(e event.DeleteEvent) bool { + return false + }, + CreateFunc: func(e event.CreateEvent) bool { + return true + }, + UpdateFunc: func(e event.UpdateEvent) bool { + return true + }, + }, + ), + ). Complete(r) } @@ -190,6 +211,30 @@ func (r *HTTPRouteReconciler) listHTTPRoutesByExtensionRef(ctx context.Context, return requests } +func (r *HTTPRouteReconciler) listHTTPRoutesForGateway(ctx context.Context, obj client.Object) []reconcile.Request { + gateway, ok := obj.(*gatewayv1.Gateway) + if !ok { + r.Log.Error(fmt.Errorf("unexpected object type"), "failed to convert object to Gateway") + } + hrList := &gatewayv1.HTTPRouteList{} + if err := r.List(ctx, hrList, client.MatchingFields{ + indexer.ParentRefs: indexer.GenIndexKey(gateway.Namespace, gateway.Name), + }); err != nil { + r.Log.Error(err, "failed to list httproutes by gateway", "gateway", gateway.Name) + return nil + } + requests := make([]reconcile.Request, 0, len(hrList.Items)) + for _, hr := range hrList.Items { + requests = append(requests, reconcile.Request{ + NamespacedName: client.ObjectKey{ + Namespace: hr.Namespace, + Name: hr.Name, + }, + }) + } + return requests +} + func (r *HTTPRouteReconciler) processHTTPRouteBackendRefs(tctx *provider.TranslateContext) error { var terr error for _, backend := range tctx.BackendRefs { diff --git a/internal/provider/adc/adc.go b/internal/provider/adc/adc.go index c87499087..b0ebf2c0e 100644 --- a/internal/provider/adc/adc.go +++ b/internal/provider/adc/adc.go @@ -85,16 +85,18 @@ func (d *adcClient) Delete(ctx context.Context, obj client.Object) error { log.Debugw("deleting object", zap.Any("object", obj)) var resourceTypes []string + var labels map[string]string switch obj.(type) { case *gatewayv1.HTTPRoute: resourceTypes = append(resourceTypes, "service") + labels = label.GenLabel(obj) case *gatewayv1.Gateway: - resourceTypes = append(resourceTypes, "global_rule", "ssl", "plugin_metadata") + // delete all resources } return d.sync(Task{ Name: obj.GetName(), - Labels: label.GenLabel(obj), + Labels: labels, ResourceTypes: resourceTypes, }) } diff --git a/test/e2e/gatewayapi/httproute.go b/test/e2e/gatewayapi/httproute.go index 8a719408f..db0204463 100644 --- a/test/e2e/gatewayapi/httproute.go +++ b/test/e2e/gatewayapi/httproute.go @@ -173,7 +173,6 @@ spec: }) Context("HTTPRoute Base", func() { - var exactRouteByGet = ` apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute @@ -223,6 +222,29 @@ spec: Expect(). Status(404) }) + + It("Delete Gateway after apply HTTPRoute", func() { + By("create HTTPRoute") + ResourceApplied("HTTPRoute", "httpbin", exactRouteByGet, 1) + + By("access daataplane to check the HTTPRoute") + s.NewAPISIXClient(). + GET("/get"). + WithHost("httpbin.example"). + Expect(). + Status(200) + + By("delete Gateway") + err := s.DeleteResource("Gateway", "api7ee") + Expect(err).NotTo(HaveOccurred(), "deleting Gateway") + time.Sleep(5 * time.Second) + + s.NewAPISIXClient(). + GET("/get"). + WithHost("httpbin.example"). + Expect(). + Status(404) + }) }) Context("HTTPRoute Rule Match", func() { var exactRouteByGet = `