-
Notifications
You must be signed in to change notification settings - Fork 97
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
Add http, https and multiple port support #1881
Merged
Tharsanan1
merged 3 commits into
wso2:main
from
Tharsanan1:support-multiple-ports-and-protocol
Jan 4, 2024
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package dataholder | ||
|
||
import ( | ||
k8types "k8s.io/apimachinery/pkg/types" | ||
gwapiv1b1 "sigs.k8s.io/gateway-api/apis/v1beta1" | ||
) | ||
|
||
// The following variables will be used to store the state of the apk. | ||
// This data should not be utilized by operator thread as its not designed for parallel access. | ||
var ( | ||
// This variable in the structure of gateway's namespaced name -> gateway | ||
gatewayMap map[string]gwapiv1b1.Gateway | ||
) | ||
|
||
func init() { | ||
gatewayMap = make(map[string]gwapiv1b1.Gateway) | ||
} | ||
|
||
// GetGatewayMap returns list of cached gateways | ||
func GetGatewayMap() map[string]gwapiv1b1.Gateway { | ||
return gatewayMap | ||
} | ||
|
||
// UpdateGateway caches the gateway | ||
func UpdateGateway(gateway gwapiv1b1.Gateway) { | ||
gatewayMap[k8types.NamespacedName{Name: gateway.Name, Namespace: gateway.Namespace}.String()] = gateway | ||
} | ||
|
||
// RemoveGateway removes the gateway from the cache | ||
func RemoveGateway(gateway gwapiv1b1.Gateway) { | ||
delete(gatewayMap, k8types.NamespacedName{Name: gateway.Name, Namespace: gateway.Namespace}.String()) | ||
} | ||
|
||
// GetAllGatewayListeners return the list of all the listeners that stored in the gateway cache | ||
func GetAllGatewayListeners() []gwapiv1b1.Listener { | ||
listeners := make([]gwapiv1b1.Listener, 0) | ||
for _, gateway := range gatewayMap { | ||
for _, listener := range gateway.Spec.Listeners { | ||
listeners = append(listeners, listener) | ||
} | ||
} | ||
return listeners | ||
} | ||
|
||
|
||
// GetListenersAsPortalPortMap returns a map that have a structure protocol -> port -> list of listeners for that port and protocol combination | ||
// Data is derived based on the current status of the gatwayMap cache | ||
func GetListenersAsPortalPortMap() map[string]map[uint32][]gwapiv1b1.Listener{ | ||
listenersAsPortalPortMap := make(map[string]map[uint32][]gwapiv1b1.Listener) | ||
for _, gateway := range gatewayMap { | ||
for _, listener := range gateway.Spec.Listeners { | ||
protocol := string(listener.Protocol) | ||
port := uint32(listener.Port) | ||
if portMap, portFound := listenersAsPortalPortMap[protocol]; portFound { | ||
if listenersList, listenerListFound := portMap[port]; listenerListFound { | ||
if (listenersList == nil) { | ||
listenersList = []gwapiv1b1.Listener{listener} | ||
} else { | ||
listenersList = append(listenersList, listener) | ||
} | ||
listenersAsPortalPortMap[protocol][port] = listenersList | ||
} else { | ||
listenerList := []gwapiv1b1.Listener{listener} | ||
listenersAsPortalPortMap[protocol][port] = listenerList | ||
} | ||
} else { | ||
listenersAsPortalPortMap[protocol] = make(map[uint32][]gwapiv1b1.Listener) | ||
listenerList := []gwapiv1b1.Listener{listener} | ||
listenersAsPortalPortMap[protocol][port] = listenerList | ||
} | ||
} | ||
} | ||
return listenersAsPortalPortMap | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this happen? I didn't get how there could be duplicate routes at this level.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without this check I faced only a part of routes added to the speific route config. Thats why i added this check