Skip to content

Commit

Permalink
Fix bugs during gRPC API invocation
Browse files Browse the repository at this point in the history
  • Loading branch information
sgayangi committed Aug 27, 2024
1 parent 4dccd03 commit d022fac
Show file tree
Hide file tree
Showing 18 changed files with 318 additions and 165 deletions.
2 changes: 1 addition & 1 deletion adapter/internal/oasparser/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
29 changes: 25 additions & 4 deletions adapter/internal/oasparser/envoyconf/routes_with_clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
132 changes: 58 additions & 74 deletions adapter/internal/operator/config/crd/bases/dp.wso2.com_apis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -370,46 +364,43 @@ 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
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
Expand All @@ -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.
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -501,7 +486,7 @@ spec:
type: string
type: array
required:
- routeRefs
- routeRefs
type: object
maxItems: 1
nullable: true
Expand All @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion adapter/internal/operator/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,7 @@ const (

// API Types
const (
GRPC = "gRPC"
GRAPHQL = "GraphQL"
REST = "REST"
GRPC = "GRPC"
)
Loading

0 comments on commit d022fac

Please sign in to comment.