Skip to content

Commit

Permalink
update gateways from k8s client for services/deployments predicates
Browse files Browse the repository at this point in the history
Signed-off-by: shawnh2 <shawnhxh@outlook.com>
  • Loading branch information
shawnh2 committed Feb 22, 2024
1 parent 4c79ef9 commit 3b0e63f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion internal/gatewayapi/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ func (t *Translator) validateListenerConditions(listener *ListenerContext) (isRe
listener.SetCondition(gwapiv1.ListenerConditionResolvedRefs, metav1.ConditionTrue, gwapiv1.ListenerReasonResolvedRefs,
"Listener references have been resolved")
return true

}

// Any condition on the listener apart from Programmed=true indicates an error.
if !(lConditions[0].Type == string(gwapiv1.ListenerConditionProgrammed) && lConditions[0].Status == metav1.ConditionTrue) {
hasProgrammedCond := false
Expand Down
37 changes: 26 additions & 11 deletions internal/provider/kubernetes/predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,14 @@ func (r *gatewayAPIReconciler) validateServiceForReconcile(obj client.Object) bo
}
labels := svc.GetLabels()

// Check if the Service belongs to a Gateway, if so, update the Gateway status.
gtw := r.findOwningGateway(ctx, labels)
if gtw != nil {
r.updateStatusForGateway(ctx, gtw)
return false
// Only services in the configured namespace should be reconciled.
if svc.Namespace == r.namespace {
// Check if the Service belongs to a Gateway, if so, update the Gateway status.
gtw := r.findOwningGateway(ctx, labels)
if gtw != nil {
r.updateStatusForGateway(ctx, gtw)
return false
}
}

// Merged gateways will have only this label, update status of all Gateways under found GatewayClass.
Expand All @@ -226,9 +229,15 @@ func (r *gatewayAPIReconciler) validateServiceForReconcile(obj client.Object) bo
res, _ := r.resources.GatewayAPIResources.Load(string(r.classController))
if res != nil {
if (*res)[gclass] != nil && len((*res)[gclass].Gateways) > 0 {
for _, gw := range (*res)[gclass].Gateways {
gw := gw
r.updateStatusForGateway(ctx, gw)
for _, gtw := range (*res)[gclass].Gateways {
curGtw := new(gwapiv1.Gateway)
key := types.NamespacedName{Namespace: gtw.Namespace, Name: gtw.Name}
if err := r.client.Get(ctx, key, curGtw); err != nil {
r.log.Info("gateway not found", "gatewayclass", gclass, "name", key.String())
return false
}

r.updateStatusForGateway(ctx, curGtw)
}
}
}
Expand Down Expand Up @@ -383,9 +392,15 @@ func (r *gatewayAPIReconciler) validateDeploymentForReconcile(obj client.Object)
res, _ := r.resources.GatewayAPIResources.Load(string(r.classController))
if res != nil {
if (*res)[gclass] != nil && len((*res)[gclass].Gateways) > 0 {
for _, gw := range (*res)[gclass].Gateways {
gw := gw
r.updateStatusForGateway(ctx, gw)
for _, gtw := range (*res)[gclass].Gateways {
curGtw := new(gwapiv1.Gateway)
key := types.NamespacedName{Namespace: gtw.Namespace, Name: gtw.Name}
if err := r.client.Get(ctx, key, curGtw); err != nil {
r.log.Info("gateway not found", "gatewayclass", gclass, "name", key.String())
return false
}

r.updateStatusForGateway(ctx, curGtw)
}
}
}
Expand Down

0 comments on commit 3b0e63f

Please sign in to comment.