Skip to content

Commit 6581d2e

Browse files
committed
add status
1 parent 4fd35e5 commit 6581d2e

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

api/adc/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ func ComposeGRPCServiceNameWithRule(namespace, name string, rule string) string
521521

522522
func ComposeServicesNameWithScheme(namespace, name string, rule string, scheme string) string {
523523
var p []byte
524-
plen := len(namespace) + len(name) + len(scheme) + 3
524+
plen := len(namespace) + len(name) + len(rule) + len(scheme) + 3
525525

526526
p = make([]byte, 0, plen)
527527
buf := bytes.NewBuffer(p)

internal/adc/translator/grpcroute.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ func (t *Translator) translateGatewayGRPCRouteMatch(match *gatewayv1.GRPCRouteMa
329329
matchType := ptr.Deref(match.Method.Type, gatewayv1.GRPCMethodMatchExact)
330330
if matchType == gatewayv1.GRPCMethodMatchExact &&
331331
service == "" && method == "" {
332-
return nil, fmt.Errorf("service and method cannot both be empty")
332+
return nil, fmt.Errorf("service and method cannot both be empty for exact match type")
333333
}
334334
}
335335

internal/provider/apisix/status.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,41 @@ func (d *apisixProvider) updateStatus(nnk types.NamespacedNameKind, condition me
144144
return cp
145145
}),
146146
})
147+
case types.KindGRPCRoute:
148+
parentRefs := d.client.ConfigManager.GetConfigRefsByResourceKey(nnk)
149+
log.Debugw("updating GRPCRoute status", zap.Any("parentRefs", parentRefs))
150+
gatewayRefs := map[types.NamespacedNameKind]struct{}{}
151+
for _, parentRef := range parentRefs {
152+
if parentRef.Kind == types.KindGateway {
153+
gatewayRefs[parentRef] = struct{}{}
154+
}
155+
}
156+
d.updater.Update(status.Update{
157+
NamespacedName: nnk.NamespacedName(),
158+
Resource: &gatewayv1.GRPCRoute{},
159+
Mutator: status.MutatorFunc(func(obj client.Object) client.Object {
160+
cp := obj.(*gatewayv1.GRPCRoute).DeepCopy()
161+
gatewayNs := cp.GetNamespace()
162+
for i, ref := range cp.Status.Parents {
163+
ns := gatewayNs
164+
if ref.ParentRef.Namespace != nil {
165+
ns = string(*ref.ParentRef.Namespace)
166+
}
167+
if ref.ParentRef.Kind == nil || *ref.ParentRef.Kind == types.KindGateway {
168+
nnk := types.NamespacedNameKind{
169+
Name: string(ref.ParentRef.Name),
170+
Namespace: ns,
171+
Kind: types.KindGateway,
172+
}
173+
if _, ok := gatewayRefs[nnk]; ok {
174+
ref.Conditions = cutils.MergeCondition(ref.Conditions, condition)
175+
cp.Status.Parents[i] = ref
176+
}
177+
}
178+
}
179+
return cp
180+
}),
181+
})
147182
}
148183
}
149184

0 commit comments

Comments
 (0)