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 May 29, 2024
1 parent 4ec86b4 commit 9ecc10e
Show file tree
Hide file tree
Showing 12 changed files with 867 additions and 44 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)
}
})
}
}
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 9ecc10e

Please sign in to comment.