Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update routes when production or sandbox endpoints changed #1686

Merged
merged 1 commit into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions adapter/internal/discovery/xds/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,23 @@ func UpdateEnforcerRevokedTokens(revokedTokens []types.Resource) {
logger.LoggerXds.Infof("New Revoked token cache update for the label: " + label + " version: " + fmt.Sprint(version))
}

// RemoveAPICacheForEnv will remove all the internal mappings for a specific environment
func RemoveAPICacheForEnv(adapterInternalAPI model.AdapterInternalAPI, envType string) {
vHostIdentifier := GetvHostsIdentifier(adapterInternalAPI.UUID, envType)
var oldvHosts []string
if _, ok := orgIDAPIvHostsMap[adapterInternalAPI.OrganizationID]; ok {
oldvHosts = orgIDAPIvHostsMap[adapterInternalAPI.GetOrganizationID()][vHostIdentifier]
for _, oldvhost := range oldvHosts {
apiIdentifier := GenerateIdentifierForAPIWithUUID(oldvhost, adapterInternalAPI.UUID)
if orgMap, orgExists := orgAPIMap[adapterInternalAPI.GetOrganizationID()]; orgExists {
if _, apiExists := orgMap[apiIdentifier]; apiExists {
delete(orgAPIMap[adapterInternalAPI.GetOrganizationID()], apiIdentifier)
}
}
}
}
}

// UpdateAPICache updates the xDS cache related to the API Lifecycle event.
func UpdateAPICache(vHosts []string, newLabels []string, newlistenersForRoutes []string, adapterInternalAPI model.AdapterInternalAPI) error {
mutexForInternalMapUpdate.Lock()
Expand Down
8 changes: 8 additions & 0 deletions adapter/internal/operator/synchronizer/data_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ func (ods *OperatorDataStore) processAPIState(apiNamespacedName types.Namespaced
events = append(events, routeEvents...)
}
} else {
if cachedAPI.ProdHTTPRoute != nil {
updated = true
events = append(events, "Production")
}
cachedAPI.ProdHTTPRoute = nil
AmaliMatharaarachchi marked this conversation as resolved.
Show resolved Hide resolved
}
if apiState.SandHTTPRoute != nil {
Expand All @@ -97,6 +101,10 @@ func (ods *OperatorDataStore) processAPIState(apiNamespacedName types.Namespaced
events = append(events, routeEvents...)
}
} else {
if cachedAPI.SandHTTPRoute != nil {
updated = true
events = append(events, "Sandbox")
}
cachedAPI.SandHTTPRoute = nil
}
if len(apiState.Authentications) != len(cachedAPI.Authentications) {
Expand Down
10 changes: 10 additions & 0 deletions adapter/internal/operator/synchronizer/synchronizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,16 @@ func deleteAPIFromEnv(httpRoute *gwapiv1b1.HTTPRoute, apiState APIState) error {
// deployAPIInGateway deploys the related API in CREATE and UPDATE events.
func deployAPIInGateway(apiState APIState) error {
var err error
if apiState.ProdHTTPRoute == nil {
var adapterInternalAPI model.AdapterInternalAPI
adapterInternalAPI.SetInfoAPICR(*apiState.APIDefinition)
xds.RemoveAPICacheForEnv(adapterInternalAPI, constants.Production)
}
if apiState.SandHTTPRoute == nil {
var adapterInternalAPI model.AdapterInternalAPI
adapterInternalAPI.SetInfoAPICR(*apiState.APIDefinition)
xds.RemoveAPICacheForEnv(adapterInternalAPI, constants.Sandbox)
}
if apiState.ProdHTTPRoute != nil {
_, err = GenerateAdapterInternalAPI(apiState, apiState.ProdHTTPRoute, constants.Production)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ defaultVersion: true
endpointConfigurations:
production:
endpoint: "http://backend:80/anything"
sandbox:
endpoint: "http://backend:80/anything/sand"
operations:
- target: "/employee"
verb: "GET"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
name: "APIDefinitionEndpointDefault"
context: "/test-definition-default"
id: "default-api-definition-endpoint-test"
version: "3.14"
type: "REST"
defaultVersion: true
endpointConfigurations:
sandbox:
endpoint: "http://backend:80/anything/sand"
operations:
- target: "/employee"
verb: "GET"
authTypeEnabled: true
scopes: []
- target: "/employee"
verb: "POST"
authTypeEnabled: true
scopes: []
- target: "/employee/{employeeId}"
verb: "PUT"
authTypeEnabled: true
scopes: []
- target: "/employee/{employeeId}"
verb: "DELETE"
authTypeEnabled: true
scopes: []
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,24 @@ Feature: API Definition Endpoint
And I eventually receive 404 response code, not accepting
|429|

Scenario: Testing a deleted production endpoint
Given The system is ready
And I have a valid subscription
When I use the APK Conf file "artifacts/apk-confs/api_definition_default_without_production.yaml"
And the definition file "artifacts/definitions/employees_api.json"
And make the API deployment request
Then the response status code should be 200
Then I set headers
| Authorization | bearer ${accessToken} |
And I send "GET" request to "https://default.gw.wso2.com:9095/test-definition-default/3.14/api-definition" with body ""
And I eventually receive 404 response code, not accepting
| 429 |
| 200 |
And I send "GET" request to "https://default.gw.wso2.com:9095/test-definition-default/api-definition" with body ""
And I eventually receive 404 response code, not accepting
| 429 |
| 200 |


Scenario Outline: Undeploy API
Given The system is ready
Expand Down