Skip to content

Commit

Permalink
Merge pull request #2379 from AmaliMatharaarachchi/conformance
Browse files Browse the repository at this point in the history
Update v1beta1 apis to v1
  • Loading branch information
AmaliMatharaarachchi authored May 29, 2024
2 parents 62c8df7 + 3d4d8f0 commit 217738f
Show file tree
Hide file tree
Showing 25 changed files with 207 additions and 214 deletions.
4 changes: 2 additions & 2 deletions adapter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@ Following are some tasks with the steps that a developer might do in operator de
return []reconcile.Request{}
}

httpRoute := &gwapiv1b1.HTTPRoute{}
httpRoute := &gwapiv1.HTTPRoute{}
if err := apiReconciler.client.Get(ctx, types.NamespacedName{
Name: string(apiPolicy.Spec.TargetRef.Name),
Namespace: utils.GetNamespace((*gwapiv1b1.Namespace)(apiPolicy.Spec.TargetRef.Namespace),
Namespace: utils.GetNamespace((*gwapiv1.Namespace)(apiPolicy.Spec.TargetRef.Namespace),
apiPolicy.Namespace),
}, httpRoute); err != nil {
loggers.LoggerAPKOperator.ErrorC(logging.ErrorDetails{
Expand Down
28 changes: 14 additions & 14 deletions adapter/internal/dataholder/dataholder.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,38 @@ package dataholder

import (
k8types "k8s.io/apimachinery/pkg/types"
gwapiv1b1 "sigs.k8s.io/gateway-api/apis/v1beta1"
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
)

// 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
gatewayMap map[string]gwapiv1.Gateway
)

func init() {
gatewayMap = make(map[string]gwapiv1b1.Gateway)
gatewayMap = make(map[string]gwapiv1.Gateway)
}

// GetGatewayMap returns list of cached gateways
func GetGatewayMap() map[string]gwapiv1b1.Gateway {
func GetGatewayMap() map[string]gwapiv1.Gateway {
return gatewayMap
}

// UpdateGateway caches the gateway
func UpdateGateway(gateway gwapiv1b1.Gateway) {
func UpdateGateway(gateway gwapiv1.Gateway) {
gatewayMap[k8types.NamespacedName{Name: gateway.Name, Namespace: gateway.Namespace}.String()] = gateway
}

// RemoveGateway removes the gateway from the cache
func RemoveGateway(gateway gwapiv1b1.Gateway) {
func RemoveGateway(gateway gwapiv1.Gateway) {
delete(gatewayMap, k8types.NamespacedName{Name: gateway.Name, Namespace: gateway.Namespace}.String())
}

// GetAllGatewayListenerSections return the list of all the listeners that stored in the gateway cache
func GetAllGatewayListenerSections() []gwapiv1b1.Listener {
listeners := make([]gwapiv1b1.Listener, 0)
func GetAllGatewayListenerSections() []gwapiv1.Listener {
listeners := make([]gwapiv1.Listener, 0)
for _, gateway := range gatewayMap {
listeners = append(listeners, gateway.Spec.Listeners...)
}
Expand All @@ -59,27 +59,27 @@ func GetAllGatewayListenerSections() []gwapiv1b1.Listener {

// 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)
func GetListenersAsPortalPortMap() map[string]map[uint32][]gwapiv1.Listener {
listenersAsPortalPortMap := make(map[string]map[uint32][]gwapiv1.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}
listenersList = []gwapiv1.Listener{listener}
} else {
listenersList = append(listenersList, listener)
}
listenersAsPortalPortMap[protocol][port] = listenersList
} else {
listenerList := []gwapiv1b1.Listener{listener}
listenerList := []gwapiv1.Listener{listener}
listenersAsPortalPortMap[protocol][port] = listenerList
}
} else {
listenersAsPortalPortMap[protocol] = make(map[uint32][]gwapiv1b1.Listener)
listenerList := []gwapiv1b1.Listener{listener}
listenersAsPortalPortMap[protocol] = make(map[uint32][]gwapiv1.Listener)
listenerList := []gwapiv1.Listener{listener}
listenersAsPortalPortMap[protocol][port] = listenerList
}
}
Expand Down
6 changes: 3 additions & 3 deletions adapter/internal/discovery/xds/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import (
wso2_resource "github.com/wso2/apk/adapter/pkg/discovery/protocol/resource/v3"
eventhubTypes "github.com/wso2/apk/adapter/pkg/eventhub/types"
semantic_version "github.com/wso2/apk/adapter/pkg/semanticversion"
gwapiv1b1 "sigs.k8s.io/gateway-api/apis/v1beta1"
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
)

// EnvoyInternalAPI struct use to hold envoy resources and adapter internal resources
Expand Down Expand Up @@ -318,7 +318,7 @@ func GenerateEnvoyResoucesForGateway(gatewayName string) ([]types.Resource,
// let the api decide which gateway section it refers to.
// because it was already there in httproute cr
listenerSection, found := common.FindElement(dataholder.GetAllGatewayListenerSections(),
func(listenerSection gwapiv1b1.Listener) bool {
func(listenerSection gwapiv1.Listener) bool {
if listenerSection.Hostname != nil && common.MatchesHostname(vhost, string(*listenerSection.Hostname)) {
// if the envoy side vhost matches to a hostname in gateway, then it is a match
if listener.Name == common.GetEnvoyListenerName(string(listenerSection.Protocol), uint32(listenerSection.Port)) {
Expand Down Expand Up @@ -649,7 +649,7 @@ func UpdateOrgAPIMap(vHosts, newLabels map[string]struct{}, listener string, sec
}

// UpdateGatewayCache updates the xDS cache related to the Gateway Lifecycle event.
func UpdateGatewayCache(gateway *gwapiv1b1.Gateway, resolvedListenerCerts map[string]map[string][]byte,
func UpdateGatewayCache(gateway *gwapiv1.Gateway, resolvedListenerCerts map[string]map[string][]byte,
gwLuaScript string, customRateLimitPolicies []*model.CustomRateLimitPolicy) error {
listeners := oasParser.GetProductionListener(gateway, resolvedListenerCerts, gwLuaScript)
gatewayLabelConfigMap[gateway.Name].listeners = listeners
Expand Down
4 changes: 2 additions & 2 deletions adapter/internal/oasparser/config_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
envoy "github.com/wso2/apk/adapter/internal/oasparser/envoyconf"
"github.com/wso2/apk/adapter/internal/oasparser/model"
"github.com/wso2/apk/adapter/pkg/discovery/api/wso2/discovery/api"
gwapiv1b1 "sigs.k8s.io/gateway-api/apis/v1beta1"
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
)

// GetGlobalClusters generates initial internal clusters for given environment.
Expand Down Expand Up @@ -73,7 +73,7 @@ func GetGlobalClusters() ([]*clusterv3.Cluster, []*corev3.Address) {
// The provided set of envoy routes will be assigned under the virtual host
//
// The RouteConfiguration is named as "default"
func GetProductionListener(gateway *gwapiv1b1.Gateway, resolvedListenerCerts map[string]map[string][]byte, gwLuaScript string) []*listenerv3.Listener {
func GetProductionListener(gateway *gwapiv1.Gateway, resolvedListenerCerts map[string]map[string][]byte, gwLuaScript string) []*listenerv3.Listener {
listeners := envoy.CreateListenerByGateway(gateway, resolvedListenerCerts, gwLuaScript)
return listeners
}
Expand Down
3 changes: 1 addition & 2 deletions adapter/internal/oasparser/envoyconf/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import (
"google.golang.org/protobuf/types/known/anypb"
"google.golang.org/protobuf/types/known/durationpb"
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
gwapiv1b1 "sigs.k8s.io/gateway-api/apis/v1beta1"
)

// CreateRoutesConfigForRds generates the default RouteConfiguration.
Expand Down Expand Up @@ -73,7 +72,7 @@ func CreateRoutesConfigForRds(vHosts []*routev3.VirtualHost, httpListeners strin
// The relevant private keys and certificates (for securedListener) are fetched from the filepath
// mentioned in the adapter configuration. These certificate, key values are added
// as inline records (base64 encoded).
func CreateListenerByGateway(gateway *gwapiv1b1.Gateway, resolvedListenerCerts map[string]map[string][]byte, gwLuaScript string) []*listenerv3.Listener {
func CreateListenerByGateway(gateway *gwapiv1.Gateway, resolvedListenerCerts map[string]map[string][]byte, gwLuaScript string) []*listenerv3.Listener {
conf := config.ReadConfigs()
// Prepare a map that contains all the listerners identified in all of the gateways that reconciled so far.
// This map contains port - listeners per protocol with port
Expand Down
8 changes: 4 additions & 4 deletions adapter/internal/oasparser/envoyconf/listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ import (
"github.com/stretchr/testify/assert"
"github.com/wso2/apk/adapter/config"
"github.com/wso2/apk/adapter/internal/oasparser/model"
gwapiv1b1 "sigs.k8s.io/gateway-api/apis/v1beta1"
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
)

func TestCreateListenerWithRds(t *testing.T) {
// TODO: (Vajira) Add more test scenarios
gateway := new(gwapiv1b1.Gateway)
gateway := new(gwapiv1.Gateway)
gateway.Name = "default"
listenerObj := new(gwapiv1b1.Listener)
listenerObj := new(gwapiv1.Listener)
listenerObj.Name = "httpslistener"
var hostname gwapiv1b1.Hostname
var hostname gwapiv1.Hostname
hostname = "0.0.0.0"
listenerObj.Hostname = &hostname
listenerObj.Port = 9095
Expand Down
Loading

0 comments on commit 217738f

Please sign in to comment.