diff --git a/adapter/internal/operator/controllers/dp/api_controller.go b/adapter/internal/operator/controllers/dp/api_controller.go index d8c28ecf1..ad6eeb0fd 100644 --- a/adapter/internal/operator/controllers/dp/api_controller.go +++ b/adapter/internal/operator/controllers/dp/api_controller.go @@ -85,6 +85,7 @@ const ( apiAPIPolicyResourceIndex = "apiAPIPolicyResourceIndex" serviceHTTPRouteIndex = "serviceHTTPRouteIndex" httprouteScopeIndex = "httprouteScopeIndex" + gqlRouteScopeIndex = "gqlRouteScopeIndex" configMapBackend = "configMapBackend" configMapAPIDefinition = "configMapAPIDefinition" secretBackend = "secretBackend" @@ -502,7 +503,7 @@ func isAPIPropagatable(apiState *synchronizer.APIState) bool { return false } // Only valid organization's APIs can be propagated to CP - return utils.ContainsString(validOrgs, apiState.APIDefinition.Spec.Organization) + return utils.ContainsString(validOrgs, apiState.APIDefinition.Spec.Organization) } func (apiReconciler *APIReconciler) resolveGQLRouteRefs(ctx context.Context, gqlRouteRefs []string, @@ -1469,6 +1470,23 @@ func (apiReconciler *APIReconciler) getAPIsForScope(ctx context.Context, obj k8c httpRoute := httpRouteList.Items[item] requests = append(requests, apiReconciler.getAPIForHTTPRoute(ctx, &httpRoute)...) } + + gqlRouteList := &dpv1alpha2.GQLRouteList{} + if err := apiReconciler.client.List(ctx, gqlRouteList, &k8client.ListOptions{ + FieldSelector: fields.OneTermEqualSelector(gqlRouteScopeIndex, utils.NamespacedName(scope).String()), + }); err != nil { + loggers.LoggerAPKOperator.ErrorC(logging.PrintError(logging.Error2625, logging.CRITICAL, "Unable to find associated GQLRoute: %s", utils.NamespacedName(scope).String())) + return []reconcile.Request{} + } + + if len(gqlRouteList.Items) == 0 { + loggers.LoggerAPKOperator.Debugf("GQLRoutes for scope not found: %s", utils.NamespacedName(scope).String()) + } + for item := range gqlRouteList.Items { + httpRoute := gqlRouteList.Items[item] + requests = append(requests, apiReconciler.getAPIForGQLRoute(ctx, &httpRoute)...) + } + return requests } @@ -1676,6 +1694,25 @@ func addIndexes(ctx context.Context, mgr manager.Manager) error { return err } + if err := mgr.GetFieldIndexer().IndexField(ctx, &dpv1alpha2.GQLRoute{}, gqlRouteAPIIndex, + func(rawObj k8client.Object) []string { + gqlRoute := rawObj.(*dpv1alpha2.GQLRoute) + var scopes []string + for _, rule := range gqlRoute.Spec.Rules { + for _, filter := range rule.Filters { + if filter.ExtensionRef != nil && filter.ExtensionRef.Kind == constants.KindScope { + scopes = append(scopes, types.NamespacedName{ + Namespace: gqlRoute.Namespace, + Name: string(filter.ExtensionRef.Name), + }.String()) + } + } + } + return scopes + }); err != nil { + return err + } + // Backend to HTTPRoute indexer if err := mgr.GetFieldIndexer().IndexField(ctx, &gwapiv1b1.HTTPRoute{}, backendHTTPRouteIndex, func(rawObj k8client.Object) []string {