Skip to content

Commit

Permalink
Merge pull request #2310 from AmaliMatharaarachchi/rec-fix
Browse files Browse the repository at this point in the history
fix scope index gql
  • Loading branch information
Krishanx92 authored Apr 8, 2024
2 parents 935e215 + 1262ada commit b0802cf
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion adapter/internal/operator/controllers/dp/api_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ const (
apiAPIPolicyResourceIndex = "apiAPIPolicyResourceIndex"
serviceHTTPRouteIndex = "serviceHTTPRouteIndex"
httprouteScopeIndex = "httprouteScopeIndex"
gqlRouteScopeIndex = "gqlRouteScopeIndex"
configMapBackend = "configMapBackend"
configMapAPIDefinition = "configMapAPIDefinition"
secretBackend = "secretBackend"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit b0802cf

Please sign in to comment.