Skip to content

GRPCRoute Support #1835

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

Merged
merged 9 commits into from
Apr 30, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Review feedback round 3
  • Loading branch information
ciarams87 committed Apr 30, 2024
commit 60c7dc98cd21ca4a2459a86e119b8e2637436040
106 changes: 51 additions & 55 deletions internal/mode/static/state/graph/route_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,76 +253,72 @@ func bindRouteToListeners(
return
}

bindRoutes := func(r *L7Route) {
for i := 0; i < len(r.ParentRefs); i++ {
attachment := &ParentRefAttachmentStatus{
AcceptedHostnames: make(map[string][]string),
}
ref := &r.ParentRefs[i]
ref.Attachment = attachment

path := field.NewPath("spec").Child("parentRefs").Index(ref.Idx)
for i := 0; i < len(route.ParentRefs); i++ {
attachment := &ParentRefAttachmentStatus{
AcceptedHostnames: make(map[string][]string),
}
ref := &route.ParentRefs[i]
ref.Attachment = attachment

attachableListeners, listenerExists := findAttachableListeners(
getSectionName(ref.SectionName),
gw.Listeners,
)
path := field.NewPath("spec").Child("parentRefs").Index(ref.Idx)

// Case 1: Attachment is not possible because the specified SectionName does not match any Listeners in the
// Gateway.
if !listenerExists {
attachment.FailedCondition = staticConds.NewRouteNoMatchingParent()
continue
}
attachableListeners, listenerExists := findAttachableListeners(
getSectionName(ref.SectionName),
gw.Listeners,
)

// Case 2: Attachment is not possible due to unsupported configuration
// Case 1: Attachment is not possible because the specified SectionName does not match any Listeners in the
// Gateway.
if !listenerExists {
attachment.FailedCondition = staticConds.NewRouteNoMatchingParent()
continue
}

if ref.Port != nil {
valErr := field.Forbidden(path.Child("port"), "cannot be set")
attachment.FailedCondition = staticConds.NewRouteUnsupportedValue(valErr.Error())
continue
}
// Case 2: Attachment is not possible due to unsupported configuration

// Case 3: the parentRef references an ignored Gateway resource.
if ref.Port != nil {
valErr := field.Forbidden(path.Child("port"), "cannot be set")
attachment.FailedCondition = staticConds.NewRouteUnsupportedValue(valErr.Error())
continue
}

referencesWinningGw := ref.Gateway.Namespace == gw.Source.Namespace && ref.Gateway.Name == gw.Source.Name
// Case 3: the parentRef references an ignored Gateway resource.

if !referencesWinningGw {
attachment.FailedCondition = staticConds.NewTODO("Gateway is ignored")
continue
}
referencesWinningGw := ref.Gateway.Namespace == gw.Source.Namespace && ref.Gateway.Name == gw.Source.Name

// Case 4: Attachment is not possible because Gateway is invalid
if !referencesWinningGw {
attachment.FailedCondition = staticConds.NewTODO("Gateway is ignored")
continue
}

if !gw.Valid {
attachment.FailedCondition = staticConds.NewRouteInvalidGateway()
continue
}
// Case 4: Attachment is not possible because Gateway is invalid

// Case 5 - winning Gateway
if !gw.Valid {
attachment.FailedCondition = staticConds.NewRouteInvalidGateway()
continue
}

// Try to attach Route to all matching listeners
// Case 5 - winning Gateway

cond, attached := tryToAttachRouteToListeners(
ref.Attachment,
attachableListeners,
r,
gw,
namespaces,
)
if !attached {
attachment.FailedCondition = cond
continue
}
if cond != (conditions.Condition{}) {
r.Conditions = append(r.Conditions, cond)
}
// Try to attach Route to all matching listeners

attachment.Attached = true
cond, attached := tryToAttachRouteToListeners(
ref.Attachment,
attachableListeners,
route,
gw,
namespaces,
)
if !attached {
attachment.FailedCondition = cond
continue
}
if cond != (conditions.Condition{}) {
route.Conditions = append(route.Conditions, cond)
}
}

bindRoutes(route)
attachment.Attached = true
}
}

// tryToAttachRouteToListeners tries to attach the route to the listeners that match the parentRef and the hostnames.
Expand Down