Skip to content

Commit 7c028d5

Browse files
committed
[gateway] Invoke PostVirtualHostModify extension hook during xDS translation
1 parent ce7fd1e commit 7c028d5

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

pkg/gateway/xds/translator/extension.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ import (
1616
"github.com/apoxy-dev/apoxy/pkg/gateway/ir"
1717
"github.com/apoxy-dev/apoxy/pkg/gateway/xds/types"
1818
"github.com/apoxy-dev/apoxy/pkg/log"
19+
"github.com/envoyproxy/gateway/proto/extension"
1920
clusterv3 "github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3"
2021
listenerv3 "github.com/envoyproxy/go-control-plane/envoy/config/listener/v3"
2122
routev3 "github.com/envoyproxy/go-control-plane/envoy/config/route/v3"
2223
cachetypes "github.com/envoyproxy/go-control-plane/pkg/cache/types"
2324
resourcev3 "github.com/envoyproxy/go-control-plane/pkg/resource/v3"
24-
"github.com/envoyproxy/gateway/proto/extension"
2525
"google.golang.org/grpc"
2626
"google.golang.org/grpc/credentials"
2727
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
@@ -163,7 +163,8 @@ func processExtensionPostRouteHook(
163163

164164
for _, r := range tCtx.XdsResources[resourcev3.RouteType] {
165165
routeCfg := r.(*routev3.RouteConfiguration)
166-
for _, vh := range routeCfg.GetVirtualHosts() {
166+
for vhIdx := range routeCfg.GetVirtualHosts() {
167+
vh := routeCfg.VirtualHosts[vhIdx]
167168
for i, route := range vh.GetRoutes() {
168169
log.Info("Processing extension post route hook", "route", route.GetName())
169170
reqCtx, cancel := context.WithTimeout(ctx, 2*time.Second)
@@ -178,6 +179,19 @@ func processExtensionPostRouteHook(
178179
vh.Routes[i] = resp.GetRoute()
179180
}
180181
}
182+
183+
log.Info("Processing extension post virtual host hook", "virtualHost", vh.GetName())
184+
vhCtx, vhCancel := context.WithTimeout(ctx, 2*time.Second)
185+
vhResp, err := c.PostVirtualHostModify(vhCtx, &extension.PostVirtualHostModifyRequest{
186+
VirtualHost: vh,
187+
})
188+
vhCancel()
189+
if err != nil {
190+
return err
191+
}
192+
if vhResp.GetVirtualHost() != nil {
193+
routeCfg.VirtualHosts[vhIdx] = vhResp.GetVirtualHost()
194+
}
181195
}
182196
}
183197

0 commit comments

Comments
 (0)