Skip to content

Commit

Permalink
add status update for httproute gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
AmaliMatharaarachchi committed Jun 3, 2024
1 parent 66ee8e9 commit 25ab53f
Show file tree
Hide file tree
Showing 15 changed files with 876 additions and 49 deletions.
51 changes: 44 additions & 7 deletions adapter/internal/discovery/xds/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
package common

import (
"sync"
"fmt"
"regexp"
"strings"
"sync"

discovery "github.com/envoyproxy/go-control-plane/envoy/service/discovery/v3"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const nodeIDArrayMaxLength int = 20
Expand All @@ -38,12 +40,13 @@ type NodeQueue struct {
// CheckEntryAndSwapToEnd function does the following. Recently accessed entry is removed last.
// Array should have a maximum length. If the the provided nodeId may or may not be within the array.
//
// 1. If the array's maximum length is not reached after adding the new element and the element is not inside the array,
// append the element to the end.
// 2. If the array is at maximum length and element is not within the array, the new entry should be appended to the end
// and the 0th element should be removed.
// 3. If the array is at the maximum length and element is inside the array, the new element should be appended and the already
// existing entry should be removed from the position.
// 1. If the array's maximum length is not reached after adding the new element and the element is not inside the array,
// append the element to the end.
// 2. If the array is at maximum length and element is not within the array, the new entry should be appended to the end
// and the 0th element should be removed.
// 3. If the array is at the maximum length and element is inside the array, the new element should be appended and the already
// existing entry should be removed from the position.
//
// Returns the modified array and true if the entry is a new addition.
func (nodeQueue *NodeQueue) checkEntryAndMoveToEnd(nodeID string) (isNewAddition bool) {
matchedIndex := -1
Expand Down Expand Up @@ -131,3 +134,37 @@ func MatchesHostname(domain, pattern string) bool {

return matched
}

// PointerCopy returns a pointer to a new memory location containing a copy of the input value.
func PointerCopy[T any](x T) *T {
return &x
}

// AreConditionsSame checks if two metav1.Condition objects have the same attributes.
// It returns true if all the attributes (Type, Status, Reason, Message, ObservedGeneration)
// are equal, otherwise it returns false.
func AreConditionsSame(condition1 metav1.Condition, condition2 metav1.Condition) bool {
return condition1.Type == condition2.Type &&
condition1.Status == condition2.Status &&
condition1.Reason == condition2.Reason &&
condition1.Message == condition2.Message &&
condition1.ObservedGeneration == condition2.ObservedGeneration
}

// BothListContainsSameConditions checks if two lists of metav1.Conditions contain the same conditions.
// It returns true if all conditions in conditionList1 are found in conditionList2.
func BothListContainsSameConditions(conditionList1 []metav1.Condition, conditionList2 []metav1.Condition) bool {
for _, condition1 := range conditionList1 {
flag := false
for _, condition2 := range conditionList2 {
flag = AreConditionsSame(condition1, condition2)
if flag {
continue
}
}
if !flag {
return false
}
}
return true
}
22 changes: 22 additions & 0 deletions adapter/internal/discovery/xds/common/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,25 @@ func generateNodeArray(length int) []string {
}
return array
}

func TestMatchDomain(t *testing.T) {
tests := []struct {
domain string
pattern string
expected bool
}{
{"test.google.com", "*.google.com", true},
{"test.google2.com", "*.google.com", false},
{"sub.test.google.com", "*.google.com", true},
{"sub.test.google2.com", "*.google.com", false},
}

for _, tt := range tests {
t.Run(tt.domain, func(t *testing.T) {
actual := MatchesHostname(tt.domain, tt.pattern)
if actual != tt.expected {
t.Errorf("Expected %v, but got %v", tt.expected, actual)
}
})
}
}
2 changes: 1 addition & 1 deletion adapter/internal/discovery/xds/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ func GenerateEnvoyResoucesForGateway(gatewayName string) ([]types.Resource,
// Find gateway listeners that has $systemHost as its hostname and add the system routeConfig referencing those listeners
gatewayListeners := dataholder.GetAllGatewayListenerSections()
for _, listener := range gatewayListeners {
if systemHost == string(*listener.Hostname) {
if listener.Hostname != nil && systemHost == string(*listener.Hostname) {
var vhostToRouteArrayFilteredMapForSystemEndpoints = make(map[string][]*routev3.Route)
vhostToRouteArrayFilteredMapForSystemEndpoints[systemHost] = vhostToRouteArrayMap[systemHost]
routeConfigName := common.GetEnvoyRouteConfigName(common.GetEnvoyListenerName(string(listener.Protocol), uint32(listener.Port)), string(listener.Name))
Expand Down
10 changes: 7 additions & 3 deletions adapter/internal/oasparser/envoyconf/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func CreateListenerByGateway(gateway *gwapiv1.Gateway, resolvedListenerCerts map
}
protocolListenerMap[listener.Protocol][port] = append(protocolListenerMap[listener.Protocol][port], listener)
}
loggers.LoggerAPKOperator.Infof("CreateListenerByGateway is called. ProtocolListenerMap: %+v", protocolListenerMap)
loggers.LoggerAPKOperator.Debugf("CreateListenerByGateway is called. ProtocolListenerMap: %+v, gateway %+v", protocolListenerMap, gateway.Spec.Listeners)
listenerList := make([]*listenerv3.Listener, 0)
for protocol, protocolPort := range protocolListenerMap {
for port, listeners := range protocolPort {
Expand All @@ -109,9 +109,13 @@ func CreateListenerByGateway(gateway *gwapiv1.Gateway, resolvedListenerCerts map
end`)
}
listenerName = common.GetEnvoyListenerName(string(protocol), port)
filterChainMatch := &listenerv3.FilterChainMatch{
ServerNames: []string{string(*listenerObj.Hostname)},
var filterChainMatch *listenerv3.FilterChainMatch
if listenerObj.Hostname != nil {
filterChainMatch = &listenerv3.FilterChainMatch{
ServerNames: []string{string(*listenerObj.Hostname)},
}
}

var transportSocket *corev3.TransportSocket
if protocol == gwapiv1.HTTPSProtocolType {
publicCertData := resolvedListenerCerts[string(listenerObj.Name)]["tls.crt"]
Expand Down
3 changes: 3 additions & 0 deletions adapter/internal/operator/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ const (
ApplicationController string = "ApplicationController"
SubscriptionController string = "SubscriptionController"
TokenIssuerController string = "TokenIssuerController"
HTTPRouteController string = "HttpRouteController"
GatewayClassController string = "GatewayClassController"
)

// API events related constants
const (
Create string = "CREATED"
Update string = "UPDATED"
Delete string = "DELETED"
Accept string = "Accepted"
)

// Environment variable names and default values
Expand Down
Loading

0 comments on commit 25ab53f

Please sign in to comment.