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

Delete unused organization related entries from internal map #1695

Merged
merged 5 commits 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
15 changes: 14 additions & 1 deletion adapter/internal/discovery/xds/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,20 @@ func RemoveAPICacheForEnv(adapterInternalAPI model.AdapterInternalAPI, envType s
}
}

// RemoveAPIFromOrgAPIMap removes api from orgAPI map
func RemoveAPIFromOrgAPIMap(uuid string, orgID string) {
if orgMap, ok := orgAPIMap[orgID]; ok {
for apiName := range orgMap {
if strings.Contains(apiName, uuid) {
delete(orgMap, apiName)
}
}
if len(orgMap) == 0 {
delete(orgAPIMap, orgID)
}
}
}

// 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 Expand Up @@ -906,7 +920,6 @@ func UpdateAPICache(vHosts []string, newLabels []string, newlistenersForRoutes [
endpointAddresses: endpoints,
enforcerAPI: oasParser.GetEnforcerAPI(adapterInternalAPI, vHost),
}

if _, ok := listenerToRouteArrayMap[newlistenersForRoutes[0]]; ok {
listenerToRouteArrayMap[newlistenersForRoutes[0]] = append(listenerToRouteArrayMap[newlistenersForRoutes[0]], routes...)
} else {
Expand Down
1 change: 1 addition & 0 deletions adapter/internal/operator/synchronizer/api_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type APIState struct {
InterceptorServiceMapping map[string]v1alpha1.InterceptorService
BackendJWTMapping map[string]v1alpha1.BackendJWT
APIDefinitionFile []byte
OldOrganizationID string
}

// HTTPRouteState holds the state of the deployed httpRoutes. This state is compared with
Expand Down
1 change: 1 addition & 0 deletions adapter/internal/operator/synchronizer/data_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func (ods *OperatorDataStore) processAPIState(apiNamespacedName types.Namespaced
cachedAPI := ods.apiStore[apiNamespacedName]

if apiState.APIDefinition.Generation > cachedAPI.APIDefinition.Generation {
cachedAPI.OldOrganizationID = cachedAPI.APIDefinition.Spec.Organization
cachedAPI.APIDefinition = apiState.APIDefinition
updated = true
events = append(events, "API Definition")
Expand Down
3 changes: 3 additions & 0 deletions adapter/internal/operator/synchronizer/synchronizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ 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 len(apiState.OldOrganizationID) != 0 {
xds.RemoveAPIFromOrgAPIMap(string((*apiState.APIDefinition).ObjectMeta.UID), apiState.OldOrganizationID)
}
if apiState.ProdHTTPRoute == nil {
var adapterInternalAPI model.AdapterInternalAPI
adapterInternalAPI.SetInfoAPICR(*apiState.APIDefinition)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,4 +365,22 @@ spec:
group: gateway.networking.k8s.io
kind: Gateway
name: default

---
# This is a API with wrong organization(jwt issuer not set).
# When test cases apply the correct API it should overrite the wrong value to correct value
apiVersion: dp.wso2.com/v1alpha1
kind: API
metadata:
name: all-http-methods-for-wildcard
namespace: gateway-integration-test-infra
spec:
apiDisplayName: API with Backend Base Path
apiType: REST
apiVersion: v1.0.0
context: /all-http-methods-for-wildcard/v1.0.0
isDefaultVersion: true
#definitionFileRef: definition-file
production:
- httpRouteRefs:
- all-http-methods-for-wildcard-httproute
organization: wso2-org1111