Skip to content

Commit 5e5d5fa

Browse files
committed
set conditions
Change-Id: I065470d6986fbe23ab053fbb77daa7f178981e9e
1 parent 261c169 commit 5e5d5fa

File tree

1 file changed

+51
-6
lines changed

1 file changed

+51
-6
lines changed

pkg/gateway/gateway.go

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,16 @@ func (c *Controller) syncGateway(key string) error {
9292

9393
// Update configuration
9494
resources := map[resourcev3.Type][]envoyproxytypes.Resource{}
95-
conditions := []metav1.Condition{}
96-
for _, listener := range gw.Spec.Listeners {
95+
gwConditions := []metav1.Condition{{
96+
Type: string(gatewayv1.GatewayConditionAccepted),
97+
Status: metav1.ConditionTrue,
98+
Reason: string(gatewayv1.GatewayReasonAccepted),
99+
ObservedGeneration: gw.Generation,
100+
LastTransitionTime: metav1.Now(),
101+
}}
102+
103+
lisStatus := make([]gatewayv1.ListenerStatus, len(gw.Spec.Listeners))
104+
for i, listener := range gw.Spec.Listeners {
97105
// Determine the Envoy protocol based on the Gateway API protocol
98106
var envoyProto corev3.SocketAddress_Protocol
99107
switch listener.Protocol {
@@ -115,19 +123,56 @@ func (c *Controller) syncGateway(key string) error {
115123
})
116124

117125
// Process HTTP Routes
126+
var attachedRoutes int32
118127
for _, route := range c.getHTTPRoutesForListener(gw, listener) {
119128
klog.V(2).Infof("Processing http route %s/%s for gw %s/%s", route.Namespace, route.Name, gw.Namespace, gw.Name)
120-
conditions = append(conditions, metav1.Condition{})
129+
gwConditions = append(gwConditions, metav1.Condition{})
121130
}
122131

123132
for _, route := range c.getGRPCRoutesForListener(gw, listener) {
124133
klog.V(2).Infof("Processing grpc route %s/%s for gw %s/%s", route.Namespace, route.Name, gw.Namespace, gw.Name)
125-
conditions = append(conditions, metav1.Condition{})
134+
gwConditions = append(gwConditions, metav1.Condition{})
126135
}
127136

128-
// Process GRPC Routes
137+
lisStatus[i] = gatewayv1.ListenerStatus{
138+
Name: listener.Name,
139+
AttachedRoutes: attachedRoutes,
140+
Conditions: []metav1.Condition{{
141+
Type: string(gatewayv1.ListenerConditionAccepted),
142+
Status: metav1.ConditionTrue,
143+
Reason: string(gatewayv1.ListenerReasonAccepted),
144+
ObservedGeneration: gw.Generation,
145+
LastTransitionTime: metav1.Now(),
146+
}},
147+
}
129148
}
130-
return c.UpdateXDSServer(context.Background(), containerName, resources)
149+
150+
err = c.UpdateXDSServer(context.Background(), containerName, resources)
151+
if err != nil {
152+
gwConditions, _ = UpdateConditionIfChanged(gwConditions, metav1.Condition{
153+
Type: string(gatewayv1.GatewayConditionProgrammed),
154+
Status: metav1.ConditionFalse,
155+
Reason: string(gatewayv1.GatewayReasonProgrammed),
156+
Message: err.Error(),
157+
ObservedGeneration: gw.Generation,
158+
LastTransitionTime: metav1.Now(),
159+
})
160+
161+
} else {
162+
gwConditions, _ = UpdateConditionIfChanged(gwConditions, metav1.Condition{
163+
Type: string(gatewayv1.GatewayConditionProgrammed),
164+
Status: metav1.ConditionTrue,
165+
Reason: string(gatewayv1.GatewayReasonProgrammed),
166+
ObservedGeneration: gw.Generation,
167+
LastTransitionTime: metav1.Now(),
168+
})
169+
}
170+
171+
gw.Status.Listeners = lisStatus
172+
gw.Status.Conditions = gwConditions
173+
174+
_, err = c.gwClient.GatewayV1().Gateways(gw.Namespace).UpdateStatus(context.Background(), gw, metav1.UpdateOptions{})
175+
return err
131176
}
132177

133178
// getHTTPRoutesForListener returns a slice of HTTPRoutes that reference the given Gateway and listener.

0 commit comments

Comments
 (0)