diff --git a/adapter/internal/oasparser/constants/constants.go b/adapter/internal/oasparser/constants/constants.go index 5b67deae09..af21ce449d 100644 --- a/adapter/internal/oasparser/constants/constants.go +++ b/adapter/internal/oasparser/constants/constants.go @@ -105,7 +105,7 @@ const ( SOAP string = "SOAP" WS string = "WS" GRAPHQL string = "GraphQL" - GRPC string = "gRPC" + GRPC string = "GRPC" WEBHOOK string = "WEBHOOK" SSE string = "SSE" Prototyped string = "prototyped" diff --git a/adapter/internal/oasparser/envoyconf/routes_with_clusters.go b/adapter/internal/oasparser/envoyconf/routes_with_clusters.go index 3452f555db..e52d77faca 100644 --- a/adapter/internal/oasparser/envoyconf/routes_with_clusters.go +++ b/adapter/internal/oasparser/envoyconf/routes_with_clusters.go @@ -969,8 +969,14 @@ func createRoutes(params *routeCreateParams) (routes []*routev3.Route, err error decorator *routev3.Decorator ) if params.createDefaultPath { - xWso2Basepath = removeFirstOccurrence(xWso2Basepath, "/"+version) - resourcePath = removeFirstOccurrence(resource.GetPath(), "/"+version) + // check if basepath is separated from version by a . or / + if strings.Contains(basePath, "."+version) { + xWso2Basepath = removeFirstOccurrence(basePath, "."+version) + resourcePath = removeFirstOccurrence(resource.GetPath(), "."+version) + } else { + xWso2Basepath = removeFirstOccurrence(xWso2Basepath, "/"+version) + resourcePath = removeFirstOccurrence(resource.GetPath(), "/"+version) + } } if pathMatchType != gwapiv1.PathMatchExact { @@ -1181,6 +1187,16 @@ func createRoutes(params *routeCreateParams) (routes []*routev3.Route, err error rewritePath := generateRoutePathForReWrite(basePath, resourcePath, pathMatchType) action.Route.RegexRewrite = generateRegexMatchAndSubstitute(rewritePath, resourcePath, pathMatchType) + if apiType == constants.GRPC { + match.Headers = nil + newRoutePath := "/" + strings.TrimPrefix(resourcePath, basePath+".") + if newRoutePath == "/"+resourcePath { + temp := removeFirstOccurrence(basePath, "."+version) + newRoutePath = "/" + strings.TrimPrefix(resourcePath, temp+".") + } + action.Route.RegexRewrite = generateRegexMatchAndSubstitute(rewritePath, newRoutePath, pathMatchType) + } + route := generateRouteConfig(xWso2Basepath, match, action, nil, nil, decorator, perRouteFilterConfigs, nil, nil, nil, nil) // general headers to add and remove are included in this methods routes = append(routes, route) @@ -1332,8 +1348,13 @@ func CreateAPIDefinitionEndpoint(adapterInternalAPI *model.AdapterInternalAPI, v matchPath := basePath + endpoint if isDefaultversion { - basePathWithoutVersion := removeLastOccurrence(basePath, "/"+version) - matchPath = basePathWithoutVersion + endpoint + if adapterInternalAPI.GetAPIType() == constants.GRPC { + basePathWithoutVersion := removeLastOccurrence(basePath, "."+version) + matchPath = basePathWithoutVersion + "/" + vHost + endpoint + } else { + basePathWithoutVersion := removeLastOccurrence(basePath, "/"+version) + matchPath = basePathWithoutVersion + endpoint + } } matchPath = strings.Replace(matchPath, basePath, regexp.QuoteMeta(basePath), 1) diff --git a/adapter/internal/operator/config/crd/bases/dp.wso2.com_apis.yaml b/adapter/internal/operator/config/crd/bases/dp.wso2.com_apis.yaml index d24c5cafa0..1fa8ea6721 100644 --- a/adapter/internal/operator/config/crd/bases/dp.wso2.com_apis.yaml +++ b/adapter/internal/operator/config/crd/bases/dp.wso2.com_apis.yaml @@ -3,8 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.9.2 - creationTimestamp: null + controller-gen.kubebuilder.io/version: v0.12.0 name: apis.dp.wso2.com spec: group: dp.wso2.com @@ -260,8 +259,8 @@ spec: pattern: ^[/][a-zA-Z0-9~/_.-]*$ type: string definitionFileRef: - description: DefinitionFileRef contains the OpenAPI 3 or SDL file - in gzipped format. definition of the API in a ConfigMap. + description: DefinitionFileRef contains the definition of the API + in a ConfigMap. type: string definitionPath: default: /api-definition @@ -286,13 +285,13 @@ spec: items: description: EnvConfig contains the environment specific configuration properties: - httpRouteRefs: - description: HTTPRouteRefs denotes the environment of the API. + routeRefs: + description: RouteRefs denotes the environment of the API. items: type: string type: array required: - - httpRouteRefs + - routeRefs type: object maxItems: 1 nullable: true @@ -303,13 +302,13 @@ spec: items: description: EnvConfig contains the environment specific configuration properties: - httpRouteRefs: - description: HTTPRouteRefs denotes the environment of the API. + routeRefs: + description: RouteRefs denotes the environment of the API. items: type: string type: array required: - - httpRouteRefs + - routeRefs type: object maxItems: 1 nullable: true @@ -328,13 +327,11 @@ spec: description: APIStatus defines the observed state of API properties: deploymentStatus: - description: - DeploymentStatus denotes the deployment status of the + description: DeploymentStatus denotes the deployment status of the API properties: accepted: - description: - Accepted represents whether the API is accepted or + description: Accepted represents whether the API is accepted or not. type: boolean events: @@ -343,25 +340,22 @@ spec: type: string type: array message: - description: - Message represents a user friendly message that explains + description: Message represents a user friendly message that explains the current state of the API. type: string status: - description: - Status denotes the state of the API in its lifecycle. + description: Status denotes the state of the API in its lifecycle. Possible values could be Accepted, Invalid, Deploy etc. type: string transitionTime: - description: - TransitionTime represents the last known transition + description: TransitionTime represents the last known transition timestamp. format: date-time type: string required: - - accepted - - status - - transitionTime + - accepted + - status + - transitionTime type: object type: object type: object @@ -370,37 +364,35 @@ spec: subresources: status: {} - additionalPrinterColumns: - - jsonPath: .spec.apiName - name: API Name - type: string - - jsonPath: .spec.apiVersion - name: Version - type: string - - jsonPath: .spec.basePath - name: BasePath - type: string - - jsonPath: .spec.organization - name: Organization - type: string - - jsonPath: .metadata.creationTimestamp - name: Age - type: date + - jsonPath: .spec.apiName + name: API Name + type: string + - jsonPath: .spec.apiVersion + name: Version + type: string + - jsonPath: .spec.basePath + name: BasePath + type: string + - jsonPath: .spec.organization + name: Organization + type: string + - jsonPath: .metadata.creationTimestamp + name: Age + type: date name: v1beta1 schema: openAPIV3Schema: description: API is the Schema for the apis API properties: apiVersion: - description: - "APIVersion defines the versioned schema of this representation + description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources" + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' type: string kind: - description: - "Kind is a string value representing the REST resource this + description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds" + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' type: string metadata: type: object @@ -408,8 +400,7 @@ spec: description: APISpec defines the desired state of API properties: apiName: - description: - APIName is the unique name of the API can be used to + description: APIName is the unique name of the API can be used to uniquely identify an API. maxLength: 60 minLength: 1 @@ -428,13 +419,12 @@ spec: nullable: true type: array apiType: - description: - APIType denotes the type of the API. Possible values - could be REST, GraphQL, gRPC + description: APIType denotes the type of the API. Possible values + could be REST, GraphQL, GRPC enum: - - REST - - GraphQL - - gRPC + - REST + - GraphQL + - GRPC type: string apiVersion: description: APIVersion is the version number of the API. @@ -443,12 +433,11 @@ spec: pattern: ^[^~!@#;:%^*()+={}|\<>"'',&/$\[\]\s+\/]+$ type: string basePath: - description: "BasePath denotes the basepath of the API. e.g: /pet-store-api/1.0.6" + description: 'BasePath denotes the basepath of the API. e.g: /pet-store-api/1.0.6' pattern: ^[/][a-zA-Z0-9~/_.-]*$ type: string definitionFileRef: - description: - DefinitionFileRef contains the definition of the API + description: DefinitionFileRef contains the definition of the API in a ConfigMap. type: string definitionPath: @@ -461,19 +450,16 @@ spec: nullable: true type: string isDefaultVersion: - description: - IsDefaultVersion indicates whether this API version should + description: IsDefaultVersion indicates whether this API version should be used as a default API type: boolean organization: - description: - Organization denotes the organization. related to the + description: Organization denotes the organization. related to the API type: string production: - description: - "Production contains a list of references to HttpRoutes - of type HttpRoute. xref: https://github.com/kubernetes-sigs/gateway-api/blob/main/apis/v1beta1/httproute_types.go" + description: 'Production contains a list of references to HttpRoutes + of type HttpRoute. xref: https://github.com/kubernetes-sigs/gateway-api/blob/main/apis/v1beta1/httproute_types.go' items: description: EnvConfig contains the environment specific configuration properties: @@ -483,15 +469,14 @@ spec: type: string type: array required: - - routeRefs + - routeRefs type: object maxItems: 1 nullable: true type: array sandbox: - description: - "Sandbox contains a list of references to HttpRoutes - of type HttpRoute. xref: https://github.com/kubernetes-sigs/gateway-api/blob/main/apis/v1beta1/httproute_types.go" + description: 'Sandbox contains a list of references to HttpRoutes + of type HttpRoute. xref: https://github.com/kubernetes-sigs/gateway-api/blob/main/apis/v1beta1/httproute_types.go' items: description: EnvConfig contains the environment specific configuration properties: @@ -501,7 +486,7 @@ spec: type: string type: array required: - - routeRefs + - routeRefs type: object maxItems: 1 nullable: true @@ -510,18 +495,17 @@ spec: description: SystemAPI denotes if it is an internal system API. type: boolean required: - - apiName - - apiType - - apiVersion - - basePath - - definitionPath + - apiName + - apiType + - apiVersion + - basePath + - definitionPath type: object status: description: APIStatus defines the observed state of API properties: deploymentStatus: - description: - DeploymentStatus denotes the deployment status of the + description: DeploymentStatus denotes the deployment status of the API properties: accepted: diff --git a/adapter/internal/operator/constants/constants.go b/adapter/internal/operator/constants/constants.go index b9701ec45f..61222fc8b7 100644 --- a/adapter/internal/operator/constants/constants.go +++ b/adapter/internal/operator/constants/constants.go @@ -70,5 +70,7 @@ const ( // API Types const ( - GRPC = "gRPC" + GRAPHQL = "GraphQL" + REST = "REST" + GRPC = "GRPC" ) diff --git a/adapter/internal/operator/controllers/dp/api_controller.go b/adapter/internal/operator/controllers/dp/api_controller.go index 93ec7537e5..aec8d28afa 100644 --- a/adapter/internal/operator/controllers/dp/api_controller.go +++ b/adapter/internal/operator/controllers/dp/api_controller.go @@ -441,7 +441,6 @@ func (apiReconciler *APIReconciler) resolveAPIRefs(ctx context.Context, api dpv1 return nil, fmt.Errorf("error while resolving production gqlRouteref %s in namespace :%s has not found. %s", prodRouteRefs, namespace, err.Error()) } - } if len(sandRouteRefs) > 0 && apiState.APIDefinition.Spec.APIType == "GraphQL" { if apiState.SandGQLRoute, err = apiReconciler.resolveGQLRouteRefs(ctx, sandRouteRefs, namespace, @@ -452,19 +451,36 @@ func (apiReconciler *APIReconciler) resolveAPIRefs(ctx context.Context, api dpv1 } // handle gRPC APIs - if len(prodRouteRefs) > 0 && apiState.APIDefinition.Spec.APIType == "gRPC" { + if len(prodRouteRefs) > 0 && apiState.APIDefinition.Spec.APIType == constants.GRPC { if apiState.ProdGRPCRoute, err = apiReconciler.resolveGRPCRouteRefs(ctx, prodRouteRefs, namespace, api); err != nil { - return nil, fmt.Errorf("error while resolving production grpcRouteref %s in namespace :%s has not found. %s", + return nil, fmt.Errorf("error while resolving production grpcRouteref %s in namespace :%s was not found. %s", prodRouteRefs, namespace, err.Error()) } + if !apiReconciler.ods.IsGatewayAvailable(types.NamespacedName{ + Name: string(apiState.ProdGRPCRoute.GRPCRouteCombined.Spec.ParentRefs[0].Name), + Namespace: utils.GetNamespace(apiState.ProdGRPCRoute.GRPCRouteCombined.Spec.ParentRefs[0].Namespace, + apiState.ProdGRPCRoute.GRPCRouteCombined.Namespace), + }) { + return nil, fmt.Errorf("no gateway available for grpcpRouteref %s in namespace :%s was not found", + prodRouteRefs, namespace) + } } - if len(sandRouteRefs) > 0 && apiState.APIDefinition.Spec.APIType == "gRPC" { + + if len(sandRouteRefs) > 0 && apiState.APIDefinition.Spec.APIType == constants.GRPC { if apiState.SandGRPCRoute, err = apiReconciler.resolveGRPCRouteRefs(ctx, sandRouteRefs, namespace, api); err != nil { - return nil, fmt.Errorf("error while resolving sandbox grpcRouteref %s in namespace :%s has not found. %s", + return nil, fmt.Errorf("error while resolving sandbox grpcRouteref %s in namespace :%s was not found. %s", sandRouteRefs, namespace, err.Error()) } + if !apiReconciler.ods.IsGatewayAvailable(types.NamespacedName{ + Name: string(apiState.SandGRPCRoute.GRPCRouteCombined.Spec.ParentRefs[0].Name), + Namespace: utils.GetNamespace(apiState.SandGRPCRoute.GRPCRouteCombined.Spec.ParentRefs[0].Namespace, + apiState.SandGRPCRoute.GRPCRouteCombined.Namespace), + }) { + return nil, fmt.Errorf("no gateway available for grpcRouteref %s in namespace :%s was not found", + sandRouteRefs, namespace) + } } // Validate resource level extension refs resolved @@ -1093,92 +1109,107 @@ func (apiReconciler *APIReconciler) traverseAPIStateAndUpdateOwnerReferences(ctx // travserse through all the children of this API and trigger update owner reference if apiState.ProdHTTPRoute != nil { for _, httpRoute := range apiState.ProdHTTPRoute.HTTPRoutePartitions { - apiReconciler.retrieveParentAPIsAndUpdateOwnerReferene(ctx, httpRoute) + apiReconciler.retrieveParentAPIsAndUpdateOwnerReference(ctx, httpRoute) } } if apiState.SandHTTPRoute != nil { for _, httpRoute := range apiState.SandHTTPRoute.HTTPRoutePartitions { - apiReconciler.retrieveParentAPIsAndUpdateOwnerReferene(ctx, httpRoute) + apiReconciler.retrieveParentAPIsAndUpdateOwnerReference(ctx, httpRoute) } } if apiState.ProdGQLRoute != nil { for _, gqlRoute := range apiState.ProdGQLRoute.GQLRoutePartitions { - apiReconciler.retrieveParentAPIsAndUpdateOwnerReferene(ctx, gqlRoute) + apiReconciler.retrieveParentAPIsAndUpdateOwnerReference(ctx, gqlRoute) } } if apiState.SandGQLRoute != nil { for _, gqlRoute := range apiState.SandGQLRoute.GQLRoutePartitions { - apiReconciler.retrieveParentAPIsAndUpdateOwnerReferene(ctx, gqlRoute) + apiReconciler.retrieveParentAPIsAndUpdateOwnerReference(ctx, gqlRoute) } } if apiState.ProdGRPCRoute != nil { for _, grpcRoute := range apiState.ProdGRPCRoute.GRPCRoutePartitions { - apiReconciler.retrieveParentAPIsAndUpdateOwnerReferene(ctx, grpcRoute) + apiReconciler.retrieveParentAPIsAndUpdateOwnerReference(ctx, grpcRoute) } } if apiState.SandGRPCRoute != nil { for _, grpcRoute := range apiState.SandGRPCRoute.GRPCRoutePartitions { - apiReconciler.retrieveParentAPIsAndUpdateOwnerReferene(ctx, grpcRoute) + apiReconciler.retrieveParentAPIsAndUpdateOwnerReference(ctx, grpcRoute) } } for _, auth := range apiState.Authentications { - apiReconciler.retrieveParentAPIsAndUpdateOwnerReferene(ctx, &auth) + apiReconciler.retrieveParentAPIsAndUpdateOwnerReference(ctx, &auth) } for _, auth := range apiState.ResourceAuthentications { - apiReconciler.retrieveParentAPIsAndUpdateOwnerReferene(ctx, &auth) + apiReconciler.retrieveParentAPIsAndUpdateOwnerReference(ctx, &auth) } for _, ratelimit := range apiState.RateLimitPolicies { - apiReconciler.retrieveParentAPIsAndUpdateOwnerReferene(ctx, &ratelimit) + apiReconciler.retrieveParentAPIsAndUpdateOwnerReference(ctx, &ratelimit) } for _, ratelimit := range apiState.ResourceRateLimitPolicies { - apiReconciler.retrieveParentAPIsAndUpdateOwnerReferene(ctx, &ratelimit) + apiReconciler.retrieveParentAPIsAndUpdateOwnerReference(ctx, &ratelimit) } for _, apiPolicy := range apiState.APIPolicies { - apiReconciler.retrieveParentAPIsAndUpdateOwnerReferene(ctx, &apiPolicy) + apiReconciler.retrieveParentAPIsAndUpdateOwnerReference(ctx, &apiPolicy) } for _, apiPolicy := range apiState.ResourceAPIPolicies { - apiReconciler.retrieveParentAPIsAndUpdateOwnerReferene(ctx, &apiPolicy) + apiReconciler.retrieveParentAPIsAndUpdateOwnerReference(ctx, &apiPolicy) } for _, interceptorService := range apiState.InterceptorServiceMapping { - apiReconciler.retrieveParentAPIsAndUpdateOwnerReferene(ctx, &interceptorService) + apiReconciler.retrieveParentAPIsAndUpdateOwnerReference(ctx, &interceptorService) } if apiState.ProdHTTPRoute != nil { for _, backend := range apiState.ProdHTTPRoute.BackendMapping { if backend != nil { - apiReconciler.retrieveParentAPIsAndUpdateOwnerReferene(ctx, &backend.Backend) + apiReconciler.retrieveParentAPIsAndUpdateOwnerReference(ctx, &backend.Backend) } } } if apiState.SandHTTPRoute != nil { for _, backend := range apiState.SandHTTPRoute.BackendMapping { if backend != nil { - apiReconciler.retrieveParentAPIsAndUpdateOwnerReferene(ctx, &backend.Backend) + apiReconciler.retrieveParentAPIsAndUpdateOwnerReference(ctx, &backend.Backend) } } } if apiState.ProdGQLRoute != nil { for _, backend := range apiState.ProdGQLRoute.BackendMapping { if backend != nil { - apiReconciler.retrieveParentAPIsAndUpdateOwnerReferene(ctx, &backend.Backend) + apiReconciler.retrieveParentAPIsAndUpdateOwnerReference(ctx, &backend.Backend) } } } if apiState.SandGQLRoute != nil { for _, backend := range apiState.SandGQLRoute.BackendMapping { if backend != nil { - apiReconciler.retrieveParentAPIsAndUpdateOwnerReferene(ctx, &backend.Backend) + apiReconciler.retrieveParentAPIsAndUpdateOwnerReference(ctx, &backend.Backend) + } + } + } + + if apiState.ProdGRPCRoute != nil { + for _, backend := range apiState.ProdGRPCRoute.BackendMapping { + if &backend != nil { + apiReconciler.retrieveParentAPIsAndUpdateOwnerReference(ctx, &backend.Backend) + } + } + } + if apiState.SandGRPCRoute != nil { + for _, backend := range apiState.SandGRPCRoute.BackendMapping { + if &backend != nil { + apiReconciler.retrieveParentAPIsAndUpdateOwnerReference(ctx, &backend.Backend) } } } for _, backendJwt := range apiState.BackendJWTMapping { - apiReconciler.retrieveParentAPIsAndUpdateOwnerReferene(ctx, &backendJwt) + apiReconciler.retrieveParentAPIsAndUpdateOwnerReference(ctx, &backendJwt) } } -func (apiReconciler *APIReconciler) retrieveParentAPIsAndUpdateOwnerReferene(ctx context.Context, obj k8client.Object) { +func (apiReconciler *APIReconciler) retrieveParentAPIsAndUpdateOwnerReference(ctx context.Context, obj k8client.Object) { var requests []reconcile.Request switch obj.(type) { case *dpv1alpha1.Backend: @@ -1687,6 +1718,7 @@ func (apiReconciler *APIReconciler) getAPIsForScope(ctx context.Context, obj k8c if len(httpRouteList.Items) == 0 { loggers.LoggerAPKOperator.Debugf("HTTPRoutes for scope not found: %s", utils.NamespacedName(scope).String()) } + requests := []reconcile.Request{} for item := range httpRouteList.Items { httpRoute := httpRouteList.Items[item] @@ -1704,11 +1736,28 @@ func (apiReconciler *APIReconciler) getAPIsForScope(ctx context.Context, obj k8c 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)...) } + grpcRouteList := &gwapiv1a2.GRPCRouteList{} + if err := apiReconciler.client.List(ctx, grpcRouteList, &k8client.ListOptions{ + FieldSelector: fields.OneTermEqualSelector(grpcRouteScopeIndex, utils.NamespacedName(scope).String()), + }); err != nil { + loggers.LoggerAPKOperator.ErrorC(logging.PrintError(logging.Error2625, logging.CRITICAL, "Unable to find associated GRPCRoutes: %s", utils.NamespacedName(scope).String())) + return []reconcile.Request{} + } + + if len(grpcRouteList.Items) == 0 { + loggers.LoggerAPKOperator.Debugf("GRPCRoutes for scope not found: %s", utils.NamespacedName(scope).String()) + } + for item := range grpcRouteList.Items { + grpcRoute := grpcRouteList.Items[item] + requests = append(requests, apiReconciler.getAPIForGRPCRoute(ctx, &grpcRoute)...) + } + return requests } @@ -1755,6 +1804,23 @@ func (apiReconciler *APIReconciler) getAPIsForBackend(ctx context.Context, obj k requests = append(requests, apiReconciler.getAPIForGQLRoute(ctx, &gqlRoute)...) } + grpcRouteList := &gwapiv1a2.GRPCRouteList{} + if err := apiReconciler.client.List(ctx, grpcRouteList, &k8client.ListOptions{ + FieldSelector: fields.OneTermEqualSelector(backendGRPCRouteIndex, utils.NamespacedName(backend).String()), + }); err != nil { + loggers.LoggerAPKOperator.ErrorC(logging.PrintError(logging.Error2625, logging.CRITICAL, "Unable to find associated GRPCRoutes: %s", utils.NamespacedName(backend).String())) + return []reconcile.Request{} + } + + if len(grpcRouteList.Items) == 0 { + loggers.LoggerAPKOperator.Debugf("GRPCRoutes for Backend not found: %s", utils.NamespacedName(backend).String()) + } + + for item := range grpcRouteList.Items { + grpcRoute := grpcRouteList.Items[item] + requests = append(requests, apiReconciler.getAPIForGRPCRoute(ctx, &grpcRoute)...) + } + // Create API reconcile events when Backend reffered from InterceptorService interceptorServiceList := &dpv1alpha1.InterceptorServiceList{} if err := apiReconciler.client.List(ctx, interceptorServiceList, &k8client.ListOptions{ @@ -1798,11 +1864,28 @@ func (apiReconciler *APIReconciler) getAPIsForGateway(ctx context.Context, obj k return []reconcile.Request{} } + grpcRouteList := &gwapiv1a2.GRPCRouteList{} + if err := apiReconciler.client.List(ctx, grpcRouteList, &k8client.ListOptions{ + FieldSelector: fields.OneTermEqualSelector(gatewayGRPCRouteIndex, utils.NamespacedName(gateway).String()), + }); err != nil { + loggers.LoggerAPKOperator.ErrorC(logging.PrintError(logging.Error2625, logging.CRITICAL, "Unable to find associated GRPCRoutes: %s", utils.NamespacedName(gateway).String())) + return []reconcile.Request{} + } + + if len(grpcRouteList.Items) == 0 { + loggers.LoggerAPKOperator.Debugf("GRPCRoutes for Gateway not found: %s", utils.NamespacedName(gateway).String()) + return []reconcile.Request{} + } + requests := []reconcile.Request{} for item := range httpRouteList.Items { httpRoute := httpRouteList.Items[item] requests = append(requests, apiReconciler.getAPIForHTTPRoute(ctx, &httpRoute)...) } + for item := range grpcRouteList.Items { + grpcRoute := grpcRouteList.Items[item] + requests = append(requests, apiReconciler.getAPIForGRPCRoute(ctx, &grpcRoute)...) + } return requests } @@ -1879,6 +1962,40 @@ func addIndexes(ctx context.Context, mgr manager.Manager) error { return err } + if err := mgr.GetFieldIndexer().IndexField(ctx, &dpv1beta1.API{}, grpcRouteAPIIndex, + func(rawObj k8client.Object) []string { + api := rawObj.(*dpv1beta1.API) + if api.Spec.APIType != constants.GRPC { + return nil + } + var grpcRoutes []string + if len(api.Spec.Production) > 0 { + for _, ref := range api.Spec.Production[0].RouteRefs { + if ref != "" { + grpcRoutes = append(grpcRoutes, + types.NamespacedName{ + Namespace: api.Namespace, + Name: ref, + }.String()) + } + } + } + if len(api.Spec.Sandbox) > 0 { + for _, ref := range api.Spec.Sandbox[0].RouteRefs { + if ref != "" { + grpcRoutes = append(grpcRoutes, + types.NamespacedName{ + Namespace: api.Namespace, + Name: ref, + }.String()) + } + } + } + return grpcRoutes + }); err != nil { + return err + } + if err := mgr.GetFieldIndexer().IndexField(ctx, &dpv1beta1.API{}, configMapAPIDefinition, func(rawObj k8client.Object) []string { api := rawObj.(*dpv1beta1.API) @@ -1976,6 +2093,27 @@ func addIndexes(ctx context.Context, mgr manager.Manager) error { return err } + // Backend to GRPCRoute indexer + if err := mgr.GetFieldIndexer().IndexField(ctx, &gwapiv1a2.GRPCRoute{}, backendGRPCRouteIndex, + func(rawObj k8client.Object) []string { + grpcRoute := rawObj.(*gwapiv1a2.GRPCRoute) + var backends []string + for _, rule := range grpcRoute.Spec.Rules { + for _, backendRef := range rule.BackendRefs { + if backendRef.Kind != nil && *backendRef.Kind == constants.KindBackend { + backends = append(backends, types.NamespacedName{ + Namespace: utils.GetNamespace(backendRef.Namespace, + grpcRoute.ObjectMeta.Namespace), + Name: string(backendRef.Name), + }.String()) + } + } + } + return backends + }); err != nil { + return err + } + // Gateway to HTTPRoute indexer if err := mgr.GetFieldIndexer().IndexField(ctx, &gwapiv1.HTTPRoute{}, gatewayHTTPRouteIndex, func(rawObj k8client.Object) []string { @@ -1993,6 +2131,23 @@ func addIndexes(ctx context.Context, mgr manager.Manager) error { return err } + //Gateway to GRPCRoute indexer + if err := mgr.GetFieldIndexer().IndexField(ctx, &gwapiv1a2.GRPCRoute{}, gatewayGRPCRouteIndex, + func(rawObj k8client.Object) []string { + grpcRoute := rawObj.(*gwapiv1a2.GRPCRoute) + var gateways []string + for _, parentRef := range grpcRoute.Spec.ParentRefs { + gateways = append(gateways, types.NamespacedName{ + Namespace: utils.GetNamespace(parentRef.Namespace, + grpcRoute.Namespace), + Name: string(parentRef.Name), + }.String()) + } + return gateways + }); err != nil { + return err + } + // ConfigMap to Backend indexer if err := mgr.GetFieldIndexer().IndexField(ctx, &dpv1alpha1.Backend{}, configMapBackend, func(rawObj k8client.Object) []string { diff --git a/adapter/internal/operator/synchronizer/synchronizer.go b/adapter/internal/operator/synchronizer/synchronizer.go index 7f67c3c5d4..450e56d333 100644 --- a/adapter/internal/operator/synchronizer/synchronizer.go +++ b/adapter/internal/operator/synchronizer/synchronizer.go @@ -111,10 +111,10 @@ func HandleAPILifeCycleEvents(ch *chan *APIEvent, successChannel *chan SuccessEv func undeployAPIInGateway(apiEvent *APIEvent) error { var err error apiState := apiEvent.Events[0] - if apiState.APIDefinition.Spec.APIType == "REST" { + if apiState.APIDefinition.Spec.APIType == constants.REST { err = undeployRestAPIInGateway(apiState) } - if apiState.APIDefinition.Spec.APIType == "GraphQL" { + if apiState.APIDefinition.Spec.APIType == constants.GRAPHQL { err = undeployGQLAPIInGateway(apiState) } @@ -204,7 +204,7 @@ func deployMultipleAPIsInGateway(event *APIEvent, successChannel *chan SuccessEv } } - if apiState.APIDefinition.Spec.APIType == "gRPC" { + if apiState.APIDefinition.Spec.APIType == constants.GRPC { if apiState.ProdGRPCRoute != nil { _, updatedLabels, err := updateInternalMapsFromGRPCRoute(apiState, apiState.ProdGRPCRoute, constants.Production) if err != nil { diff --git a/common-controller/internal/operator/controllers/dp/ratelimitpolicy_controller.go b/common-controller/internal/operator/controllers/dp/ratelimitpolicy_controller.go index e794f530ff..b3f3bb2839 100644 --- a/common-controller/internal/operator/controllers/dp/ratelimitpolicy_controller.go +++ b/common-controller/internal/operator/controllers/dp/ratelimitpolicy_controller.go @@ -66,7 +66,7 @@ const ( // NewratelimitController creates a new ratelimitcontroller instance. func NewratelimitController(mgr manager.Manager, ratelimitStore *cache.RatelimitDataStore) error { - ratelimitReconsiler := &RateLimitPolicyReconciler{ + ratelimitReconciler := &RateLimitPolicyReconciler{ client: mgr.GetClient(), ods: ratelimitStore, } @@ -77,7 +77,7 @@ func NewratelimitController(mgr manager.Manager, ratelimitStore *cache.Ratelimit return err } - c, err := controller.New(constants.RatelimitController, mgr, controller.Options{Reconciler: ratelimitReconsiler}) + c, err := controller.New(constants.RatelimitController, mgr, controller.Options{Reconciler: ratelimitReconciler}) if err != nil { loggers.LoggerAPKOperator.ErrorC(logging.PrintError(logging.Error2663, logging.BLOCKER, "Error creating Ratelimit controller: %v", err.Error())) @@ -88,14 +88,14 @@ func NewratelimitController(mgr manager.Manager, ratelimitStore *cache.Ratelimit predicates := []predicate.Predicate{predicate.NewPredicateFuncs(utils.FilterByNamespaces(conf.CommonController.Operator.Namespaces))} if err := c.Watch(source.Kind(mgr.GetCache(), &dpv1beta1.API{}), - handler.EnqueueRequestsFromMapFunc(ratelimitReconsiler.getRatelimitForAPI), predicates...); err != nil { + handler.EnqueueRequestsFromMapFunc(ratelimitReconciler.getRatelimitForAPI), predicates...); err != nil { loggers.LoggerAPKOperator.ErrorC(logging.PrintError(logging.Error2611, logging.BLOCKER, "Error watching API resources: %v", err)) return err } if err := c.Watch(source.Kind(mgr.GetCache(), &gwapiv1.HTTPRoute{}), - handler.EnqueueRequestsFromMapFunc(ratelimitReconsiler.getRatelimitForHTTPRoute), predicates...); err != nil { + handler.EnqueueRequestsFromMapFunc(ratelimitReconciler.getRatelimitForHTTPRoute), predicates...); err != nil { loggers.LoggerAPKOperator.ErrorC(logging.PrintError(logging.Error2613, logging.BLOCKER, "Error watching HTTPRoute resources: %v", err)) return err @@ -124,7 +124,7 @@ func NewratelimitController(mgr manager.Manager, ratelimitStore *cache.Ratelimit // // For more details, check Reconcile and its Result here: // - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.15.0/pkg/reconcile -func (ratelimitReconsiler *RateLimitPolicyReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { +func (ratelimitReconciler *RateLimitPolicyReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { _ = log.FromContext(ctx) // Check whether the Ratelimit CR exist, if not consider as a DELETE event. loggers.LoggerAPKOperator.Infof("Reconciling ratelimit...") @@ -133,18 +133,18 @@ func (ratelimitReconsiler *RateLimitPolicyReconciler) Reconcile(ctx context.Cont var ratelimitPolicy dpv1alpha1.RateLimitPolicy // Check k8s RatelimitPolicy Availbility - if err := ratelimitReconsiler.client.Get(ctx, ratelimitKey, &ratelimitPolicy); err != nil { - resolveRateLimitAPIPolicyList, found := ratelimitReconsiler.ods.GetResolveRatelimitPolicy(req.NamespacedName) + if err := ratelimitReconciler.client.Get(ctx, ratelimitKey, &ratelimitPolicy); err != nil { + resolveRateLimitAPIPolicyList, found := ratelimitReconciler.ods.GetResolveRatelimitPolicy(req.NamespacedName) // If availble in cache Delete cache and xds if found && k8error.IsNotFound(err) { - ratelimitReconsiler.ods.DeleteResolveRatelimitPolicy(req.NamespacedName) + ratelimitReconciler.ods.DeleteResolveRatelimitPolicy(req.NamespacedName) xds.DeleteAPILevelRateLimitPolicies(resolveRateLimitAPIPolicyList) xds.DeleteResourceLevelRateLimitPolicies(resolveRateLimitAPIPolicyList) xds.UpdateRateLimiterPolicies(conf.CommonController.Server.Label) } - resolveCustomRateLimitPolicy, foundCustom := ratelimitReconsiler.ods.GetCachedCustomRatelimitPolicy(req.NamespacedName) + resolveCustomRateLimitPolicy, foundCustom := ratelimitReconciler.ods.GetCachedCustomRatelimitPolicy(req.NamespacedName) if foundCustom && k8error.IsNotFound(err) { - ratelimitReconsiler.ods.DeleteCachedCustomRatelimitPolicy(req.NamespacedName) + ratelimitReconciler.ods.DeleteCachedCustomRatelimitPolicy(req.NamespacedName) logger.Debug("Deleting CustomRateLimitPolicy : ", resolveCustomRateLimitPolicy) xds.DeleteCustomRateLimitPolicies(resolveCustomRateLimitPolicy) xds.UpdateRateLimiterPolicies(conf.CommonController.Server.Label) @@ -158,16 +158,16 @@ func (ratelimitReconsiler *RateLimitPolicyReconciler) Reconcile(ctx context.Cont } if ratelimitPolicy.Spec.Override != nil && ratelimitPolicy.Spec.Override.Custom != nil { - var customRateLimitPolicy = ratelimitReconsiler.marshelCustomRateLimit(ctx, ratelimitKey, ratelimitPolicy) - ratelimitReconsiler.ods.AddorUpdateCustomRatelimitToStore(ratelimitKey, customRateLimitPolicy) + var customRateLimitPolicy = ratelimitReconciler.marshelCustomRateLimit(ctx, ratelimitKey, ratelimitPolicy) + ratelimitReconciler.ods.AddorUpdateCustomRatelimitToStore(ratelimitKey, customRateLimitPolicy) xds.UpdateRateLimitXDSCacheForCustomPolicies(customRateLimitPolicy) xds.UpdateRateLimiterPolicies(conf.CommonController.Server.Label) } else { - if resolveRatelimitPolicyList, err := ratelimitReconsiler.marshelRateLimit(ctx, ratelimitKey, ratelimitPolicy); err != nil { + if resolveRatelimitPolicyList, err := ratelimitReconciler.marshelRateLimit(ctx, ratelimitKey, ratelimitPolicy); err != nil { return ctrl.Result{}, err } else if len(resolveRatelimitPolicyList) > 0 { - ratelimitReconsiler.ods.AddorUpdateResolveRatelimitToStore(ratelimitKey, resolveRatelimitPolicyList) + ratelimitReconciler.ods.AddorUpdateResolveRatelimitToStore(ratelimitKey, resolveRatelimitPolicyList) xds.UpdateRateLimitXDSCache(resolveRatelimitPolicyList) xds.UpdateRateLimiterPolicies(conf.CommonController.Server.Label) } @@ -176,7 +176,7 @@ func (ratelimitReconsiler *RateLimitPolicyReconciler) Reconcile(ctx context.Cont return ctrl.Result{}, nil } -func (ratelimitReconsiler *RateLimitPolicyReconciler) getRatelimitForAPI(ctx context.Context, obj k8client.Object) []reconcile.Request { +func (ratelimitReconciler *RateLimitPolicyReconciler) getRatelimitForAPI(ctx context.Context, obj k8client.Object) []reconcile.Request { api, ok := obj.(*dpv1beta1.API) if !ok { loggers.LoggerAPKOperator.ErrorC(logging.PrintError(logging.Error2622, logging.TRIVIAL, @@ -187,7 +187,7 @@ func (ratelimitReconsiler *RateLimitPolicyReconciler) getRatelimitForAPI(ctx con requests := []reconcile.Request{} ratelimitPolicyList := &dpv1alpha1.RateLimitPolicyList{} - if err := ratelimitReconsiler.client.List(ctx, ratelimitPolicyList, &k8client.ListOptions{ + if err := ratelimitReconciler.client.List(ctx, ratelimitPolicyList, &k8client.ListOptions{ FieldSelector: fields.OneTermEqualSelector(apiRateLimitIndex, NamespacedName(api).String()), }); err != nil { return []reconcile.Request{} @@ -195,14 +195,14 @@ func (ratelimitReconsiler *RateLimitPolicyReconciler) getRatelimitForAPI(ctx con for item := range ratelimitPolicyList.Items { ratelimitPolicy := ratelimitPolicyList.Items[item] - requests = append(requests, ratelimitReconsiler.AddRatelimitRequest(&ratelimitPolicy)...) + requests = append(requests, ratelimitReconciler.AddRatelimitRequest(&ratelimitPolicy)...) } return requests } // AddRatelimitRequest adds a request to reconcile for the given ratelimit policy -func (ratelimitReconsiler *RateLimitPolicyReconciler) AddRatelimitRequest(obj k8client.Object) []reconcile.Request { +func (ratelimitReconciler *RateLimitPolicyReconciler) AddRatelimitRequest(obj k8client.Object) []reconcile.Request { ratelimitPolicy, ok := obj.(*dpv1alpha1.RateLimitPolicy) if !ok { loggers.LoggerAPKOperator.ErrorC(logging.PrintError(logging.Error2622, logging.TRIVIAL, @@ -218,7 +218,7 @@ func (ratelimitReconsiler *RateLimitPolicyReconciler) AddRatelimitRequest(obj k8 }} } -func (ratelimitReconsiler *RateLimitPolicyReconciler) getRatelimitForHTTPRoute(ctx context.Context, obj k8client.Object) []reconcile.Request { +func (ratelimitReconciler *RateLimitPolicyReconciler) getRatelimitForHTTPRoute(ctx context.Context, obj k8client.Object) []reconcile.Request { httpRoute, ok := obj.(*gwapiv1.HTTPRoute) if !ok { loggers.LoggerAPKOperator.ErrorC(logging.PrintError(logging.Error2622, logging.TRIVIAL, @@ -229,14 +229,14 @@ func (ratelimitReconsiler *RateLimitPolicyReconciler) getRatelimitForHTTPRoute(c requests := []reconcile.Request{} ratelimitPolicyList := &dpv1alpha1.RateLimitPolicyList{} - if err := ratelimitReconsiler.client.List(ctx, ratelimitPolicyList, &k8client.ListOptions{ + if err := ratelimitReconciler.client.List(ctx, ratelimitPolicyList, &k8client.ListOptions{ FieldSelector: fields.OneTermEqualSelector(httprouteRateLimitIndex, NamespacedName(httpRoute).String()), }); err != nil { return []reconcile.Request{} } for item := range ratelimitPolicyList.Items { ratelimitPolicy := ratelimitPolicyList.Items[item] - requests = append(requests, ratelimitReconsiler.AddRatelimitRequest(&ratelimitPolicy)...) + requests = append(requests, ratelimitReconciler.AddRatelimitRequest(&ratelimitPolicy)...) } return requests @@ -316,7 +316,7 @@ func (ratelimitReconciler *RateLimitPolicyReconciler) marshelRateLimit(ctx conte return policyList, nil } -func (ratelimitReconsiler *RateLimitPolicyReconciler) getHTTPRouteResourceList(ctx context.Context, ratelimitKey types.NamespacedName, +func (ratelimitReconciler *RateLimitPolicyReconciler) getHTTPRouteResourceList(ctx context.Context, ratelimitKey types.NamespacedName, ratelimitPolicy dpv1alpha1.RateLimitPolicy, httpRefs []string) ([]dpv1alpha1.ResolveResource, error) { var resolveResourceList []dpv1alpha1.ResolveResource @@ -324,7 +324,7 @@ func (ratelimitReconsiler *RateLimitPolicyReconciler) getHTTPRouteResourceList(c for _, ref := range httpRefs { if ref != "" { - if err := ratelimitReconsiler.client.Get(ctx, types.NamespacedName{ + if err := ratelimitReconciler.client.Get(ctx, types.NamespacedName{ Namespace: ratelimitKey.Namespace, Name: ref}, &httpRoute); err != nil { @@ -362,7 +362,7 @@ func (ratelimitReconsiler *RateLimitPolicyReconciler) getHTTPRouteResourceList(c return resolveResourceList, nil } -func (ratelimitReconsiler *RateLimitPolicyReconciler) marshelCustomRateLimit(ctx context.Context, ratelimitKey types.NamespacedName, +func (ratelimitReconciler *RateLimitPolicyReconciler) marshelCustomRateLimit(ctx context.Context, ratelimitKey types.NamespacedName, ratelimitPolicy dpv1alpha1.RateLimitPolicy) dpv1alpha1.CustomRateLimitPolicyDef { var customRateLimitPolicy dpv1alpha1.CustomRateLimitPolicyDef // Custom Rate limit policy @@ -435,8 +435,8 @@ func GetNamespace(namespace *gwapiv1.Namespace, defaultNamespace string) string } // SetupWithManager sets up the controller with the Manager. -func (ratelimitReconsiler *RateLimitPolicyReconciler) SetupWithManager(mgr ctrl.Manager) error { +func (ratelimitReconciler *RateLimitPolicyReconciler) SetupWithManager(mgr ctrl.Manager) error { return ctrl.NewControllerManagedBy(mgr). For(&dpv1alpha1.RateLimitPolicy{}). - Complete(ratelimitReconsiler) + Complete(ratelimitReconciler) } diff --git a/common-go-libs/apis/dp/v1beta1/api_types.go b/common-go-libs/apis/dp/v1beta1/api_types.go index 96e929bfe8..943e9a1341 100644 --- a/common-go-libs/apis/dp/v1beta1/api_types.go +++ b/common-go-libs/apis/dp/v1beta1/api_types.go @@ -80,9 +80,9 @@ type APISpec struct { Sandbox []EnvConfig `json:"sandbox"` // APIType denotes the type of the API. - // Possible values could be REST, GraphQL, gRPC + // Possible values could be REST, GraphQL, GRPC // - // +kubebuilder:validation:Enum=REST;GraphQL;gRPC + // +kubebuilder:validation:Enum=REST;GraphQL;GRPC APIType string `json:"apiType"` // BasePath denotes the basepath of the API. diff --git a/common-go-libs/config/crd/bases/dp.wso2.com_apis.yaml b/common-go-libs/config/crd/bases/dp.wso2.com_apis.yaml index b3dee8a220..1fa8ea6721 100644 --- a/common-go-libs/config/crd/bases/dp.wso2.com_apis.yaml +++ b/common-go-libs/config/crd/bases/dp.wso2.com_apis.yaml @@ -420,11 +420,11 @@ spec: type: array apiType: description: APIType denotes the type of the API. Possible values - could be REST, GraphQL, gRPC + could be REST, GraphQL, GRPC enum: - REST - GraphQL - - gRPC + - GRPC type: string apiVersion: description: APIVersion is the version number of the API. diff --git a/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/api/APIFactory.java b/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/api/APIFactory.java index aa6e98eab2..89ec04d640 100644 --- a/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/api/APIFactory.java +++ b/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/api/APIFactory.java @@ -73,7 +73,6 @@ public void addApis(List apis) { // String apiKey = getApiKey(webSocketAPI); // newApis.put(apiKey, webSocketAPI); // } else - System.out.println(api.getApiType()); if (APIConstants.ApiType.GRAPHQL.equals(api.getApiType())) { GraphQLAPI graphQLAPI = new GraphQLAPI(); graphQLAPI.init(api); diff --git a/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/constants/APIConstants.java b/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/constants/APIConstants.java index 9a4f5c18fb..a911a06af1 100644 --- a/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/constants/APIConstants.java +++ b/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/constants/APIConstants.java @@ -270,7 +270,7 @@ public static class ApiType { public static final String WEB_SOCKET = "WS"; public static final String GRAPHQL = "GraphQL"; - public static final String GRPC = "gRPC"; + public static final String GRPC = "GRPC"; } /** diff --git a/helm-charts/templates/crds/dp.wso2.com_apis.yaml b/helm-charts/templates/crds/dp.wso2.com_apis.yaml index 9db6f95a04..488a91b203 100644 --- a/helm-charts/templates/crds/dp.wso2.com_apis.yaml +++ b/helm-charts/templates/crds/dp.wso2.com_apis.yaml @@ -433,11 +433,11 @@ spec: type: array apiType: description: APIType denotes the type of the API. Possible values - could be REST, GraphQL, gRPC + could be REST, GraphQL, GRPC enum: - REST - GraphQL - - gRPC + - GRPC type: string apiVersion: description: APIVersion is the version number of the API. diff --git a/helm-charts/values.yaml b/helm-charts/values.yaml index 5e0bf549d9..79d83dd5c8 100644 --- a/helm-charts/values.yaml +++ b/helm-charts/values.yaml @@ -59,8 +59,7 @@ wso2: gateway: listener: hostname: "gw.wso2.com" - service: - {} + service: {} # secretName: "idp-tls" # partitionServer: # enabled: false @@ -94,14 +93,14 @@ wso2: failureThreshold: 5 strategy: RollingUpdate replicas: 1 - imagePullPolicy: IfNotPresent - image: apk-config-deployer-service:1.1.0-SNAPSHOT - debug: true - # configs: - # tls: - # secretName: "my-secret" - # certKeyFilename: "tls.key" - # certFilename: "certchain.crt" + imagePullPolicy: Always + image: wso2/apk-config-deployer-service:1.1.0 + # debug: true + # configs: + # tls: + # secretName: "my-secret" + # certKeyFilename: "tls.key" + # certFilename: "certchain.crt" adapter: deployment: resources: @@ -242,20 +241,20 @@ wso2: periodSeconds: 20 failureThreshold: 5 strategy: RollingUpdate - imagePullPolicy: IfNotPresent - image: apk-enforcer:1.1.0-SNAPSHOT + imagePullPolicy: Always + image: wso2/apk-enforcer:1.1.0 security: sslHostname: "enforcer" - # logging: - # level: DEBUG - # configs: - # tls: - # secretName: "router-cert" - # certKeyFilename: "" - # certFilename: "" - # JWKSClient: - # skipSSLVerification: false - # hostnameVerifier: "AllowAll" +# logging: +# level: DEBUG +# configs: +# tls: +# secretName: "router-cert" +# certKeyFilename: "" +# certFilename: "" +# JWKSClient: +# skipSSLVerification: false +# hostnameVerifier: "AllowAll" metrics: enabled: false diff --git a/runtime/config-deployer-service/ballerina/APIClient.bal b/runtime/config-deployer-service/ballerina/APIClient.bal index d4acec0572..3a39995607 100644 --- a/runtime/config-deployer-service/ballerina/APIClient.bal +++ b/runtime/config-deployer-service/ballerina/APIClient.bal @@ -138,11 +138,6 @@ public class APIClient { _ = check self.setRoute(apiArtifact, apkConf, createdEndpoints.hasKey(PRODUCTION_TYPE) ? createdEndpoints.get(PRODUCTION_TYPE) : (), uniqueId, PRODUCTION_TYPE, organization); _ = check self.setRoute(apiArtifact, apkConf, createdEndpoints.hasKey(SANDBOX_TYPE) ? createdEndpoints.get(SANDBOX_TYPE) : (), uniqueId, SANDBOX_TYPE, organization); string|json generatedSwagger = check self.retrieveGeneratedSwaggerDefinition(apkConf, definition); - if generatedSwagger is string { - log:printInfo(generatedSwagger); - } else { - log:printInfo(generatedSwagger.toJsonString()); - } check self.retrieveGeneratedConfigmapForDefinition(apiArtifact, apkConf, generatedSwagger, uniqueId, organization); self.generateAndSetAPICRArtifact(apiArtifact, apkConf, organization); _ = check self.generateAndSetPolicyCRArtifact(apiArtifact, apkConf, organization); @@ -512,8 +507,6 @@ public class APIClient { private isolated function getAPIType(string apiType) returns string { if apiType.toUpperAscii() == "GRAPHQL" { return "GraphQL"; - } else if apiType.toUpperAscii() == "GRPC" { - return "gRPC"; } return apiType; } diff --git a/runtime/config-deployer-service/ballerina/Ballerina.toml b/runtime/config-deployer-service/ballerina/Ballerina.toml index 1f90067f00..25f786bbeb 100644 --- a/runtime/config-deployer-service/ballerina/Ballerina.toml +++ b/runtime/config-deployer-service/ballerina/Ballerina.toml @@ -389,9 +389,4 @@ version = "20231013" [[platform.java11.dependency]] groupId = "commons-lang" artifactId = "commons-lang" -version = "2.4" - -[[platform.java11.dependency]] -groupId = "org.wso2.apk" -artifactId = "org.wso2.apk.config" -version = "1.1.0-SNAPSHOT" +version = "2.4" \ No newline at end of file diff --git a/runtime/config-deployer-service/ballerina/ConfigGenreatorClient.bal b/runtime/config-deployer-service/ballerina/ConfigGenreatorClient.bal index 07f4f649ba..ac835cb147 100644 --- a/runtime/config-deployer-service/ballerina/ConfigGenreatorClient.bal +++ b/runtime/config-deployer-service/ballerina/ConfigGenreatorClient.bal @@ -189,6 +189,14 @@ public class ConfigGeneratorClient { string yamlString = check self.convertJsonToYaml(gqlRoute.toJsonString()); _ = check self.storeFile(yamlString, gqlRoute.metadata.name, zipDir); } + foreach model:GRPCRoute grpcRoute in apiArtifact.productionGrpcRoutes { + string yamlString = check self.convertJsonToYaml(grpcRoute.toJsonString()); + _ = check self.storeFile(yamlString, grpcRoute.metadata.name, zipDir); + } + foreach model:GRPCRoute grpcRoute in apiArtifact.sandboxGrpcRoutes { + string yamlString = check self.convertJsonToYaml(grpcRoute.toJsonString()); + _ = check self.storeFile(yamlString, grpcRoute.metadata.name, zipDir); + } foreach model:Backend backend in apiArtifact.backendServices { string yamlString = check self.convertJsonToYaml(backend.toJsonString()); _ = check self.storeFile(yamlString, backend.metadata.name, zipDir); diff --git a/runtime/config-deployer-service/ballerina/DeployerClient.bal b/runtime/config-deployer-service/ballerina/DeployerClient.bal index 943a525b47..3da0d6f928 100644 --- a/runtime/config-deployer-service/ballerina/DeployerClient.bal +++ b/runtime/config-deployer-service/ballerina/DeployerClient.bal @@ -84,7 +84,6 @@ public class DeployerClient { private isolated function deployAPIToK8s(model:APIArtifact apiArtifact) returns commons:APKError|model:API { do { - log:printInfo("DEPLOYING API TO K8s"); model:Partition apiPartition; model:API? existingAPI; model:Partition|() availablePartitionForAPI = check partitionResolver.getAvailablePartitionForAPI(apiArtifact.uniqueId, apiArtifact.organization); @@ -125,7 +124,6 @@ public class DeployerClient { check self.deployInterceptorServiceCRs(apiArtifact, ownerReference); check self.deployBackendJWTConfigs(apiArtifact, ownerReference); check self.deployAPIPolicyCRs(apiArtifact, ownerReference); - log:printInfo("REACHED THE POINT OF DEPLOYING ROUTES"); check self.deployRoutes(apiArtifact.productionHttpRoutes, apiArtifact.productionGqlRoutes, apiArtifact.productionGrpcRoutes, apiArtifact?.namespace, ownerReference); check self.deployRoutes(apiArtifact.sandboxHttpRoutes, apiArtifact.sandboxGqlRoutes, apiArtifact.sandboxGrpcRoutes, apiArtifact?.namespace, ownerReference); @@ -142,15 +140,12 @@ public class DeployerClient { return e909028(); } } else { - log:printInfo("NOT AN API??"); return e909028(); } } on fail var e { if e is commons:APKError { return e; } - log:printInfo("DEPLOYMENT FAAAAILED"); - log:printError("Internal Error occured while deploying API", e); return e909028(); } @@ -331,7 +326,6 @@ public class DeployerClient { if k8sAPIByNameAndNamespace is model:API { k8sAPI.metadata.resourceVersion = k8sAPIByNameAndNamespace.metadata.resourceVersion; http:Response deployAPICRResult = check updateAPICR(k8sAPI, apiArtifact?.namespace); - log:printInfo(deployAPICRResult.statusCode.toString()); if deployAPICRResult.statusCode == http:STATUS_OK { json responsePayLoad = check deployAPICRResult.getJsonPayload(); log:printDebug("Updated K8sAPI Successfully" + responsePayLoad.toJsonString()); diff --git a/runtime/config-deployer-service/ballerina/K8sClient.bal b/runtime/config-deployer-service/ballerina/K8sClient.bal index a68a138467..5655a79266 100644 --- a/runtime/config-deployer-service/ballerina/K8sClient.bal +++ b/runtime/config-deployer-service/ballerina/K8sClient.bal @@ -20,7 +20,6 @@ import ballerina/http; // under the License. // import ballerina/io; -import ballerina/log; import ballerina/url; import wso2/apk_common_lib as commons; @@ -119,7 +118,6 @@ isolated function deployAPICR(model:API api, string namespace) returns http:Resp isolated function updateAPICR(model:API api, string namespace) returns http:Response|http:ClientError { string endpoint = "/apis/dp.wso2.com/v1beta1/namespaces/" + namespace + "/apis/" + api.metadata.name; - log:printInfo("UPDATING API CR"); return k8sApiServerEp->put(endpoint, api, targetType = http:Response); } diff --git a/runtime/config-deployer-service/java/src/main/java/org/wso2/apk/config/DefinitionParserFactory.java b/runtime/config-deployer-service/java/src/main/java/org/wso2/apk/config/DefinitionParserFactory.java index 3041eaa22e..5f4476d8cd 100644 --- a/runtime/config-deployer-service/java/src/main/java/org/wso2/apk/config/DefinitionParserFactory.java +++ b/runtime/config-deployer-service/java/src/main/java/org/wso2/apk/config/DefinitionParserFactory.java @@ -25,7 +25,7 @@ public static APIDefinition getParser(API api) { if (APIConstants.ParserType.REST.name().equals(api.getType()) || APIConstants.ParserType.GRAPHQL.name().equals(api.getType())) { return new OAS3Parser(); - } else if (APIConstants.ParserType.GRPC.name().equals(api.getType())) { + } else if (APIConstants.ParserType.GRPC.name().equals(api.getType().toUpperCase())) { return new ProtoParser(); } else if (APIConstants.ParserType.ASYNC.name().equals(api.getType())) { return new AsyncApiParser(); @@ -37,7 +37,7 @@ public static APIDefinition getParser(String apiType) { if (APIConstants.ParserType.REST.name().equals(apiType) || APIConstants.ParserType.GRAPHQL.name().equals(apiType)) { return new OAS3Parser(); - } else if (APIConstants.ParserType.GRPC.name().equals(apiType)) { + } else if (APIConstants.ParserType.GRPC.name().equals(apiType.toUpperCase())) { return new ProtoParser(); } else if ("ASYNC".equals(apiType)) { return new AsyncApiParser();