Skip to content

Commit

Permalink
feat: add MeshGateway support to MeshAccessLog
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Beaumont <[email protected]>
  • Loading branch information
michaelbeaumont committed Oct 5, 2022
1 parent 13f2034 commit 5311e8b
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions pkg/plugins/policies/meshaccesslog/plugin/v1alpha1/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import (
"github.com/kumahq/kuma/pkg/plugins/policies/matchers"
api "github.com/kumahq/kuma/pkg/plugins/policies/meshaccesslog/api/v1alpha1"
plugin_xds "github.com/kumahq/kuma/pkg/plugins/policies/meshaccesslog/plugin/xds"
"github.com/kumahq/kuma/pkg/plugins/runtime/gateway"
xds_context "github.com/kumahq/kuma/pkg/xds/context"
"github.com/kumahq/kuma/pkg/xds/envoy"
"github.com/kumahq/kuma/pkg/xds/generator"
xds_topology "github.com/kumahq/kuma/pkg/xds/topology"
)

var _ core_plugins.PolicyPlugin = &plugin{}
Expand Down Expand Up @@ -58,6 +60,9 @@ func (p plugin) Apply(rs *core_xds.ResourceSet, ctx xds_context.Context, proxy *
if err := applyToDirectAccess(policies.ToRules, listeners.directAccess, proxy.Dataplane); err != nil {
return err
}
if err := applyToGateway(policies.ToRules, listeners.gateway, ctx.Mesh.Resources.MeshLocalResources, proxy.Dataplane); err != nil {
return err
}

return nil
}
Expand Down Expand Up @@ -153,9 +158,50 @@ func applyToDirectAccess(
return nil
}

func applyToGateway(
rules xds.ToRules, gatewayListeners map[xds.InboundListener]*envoy_listener.Listener, resources xds_context.ResourceMap, dataplane *core_mesh.DataplaneResource,
) error {
var gateways *core_mesh.MeshGatewayResourceList
if rawList := resources[core_mesh.MeshGatewayType]; rawList != nil {
gateways = rawList.(*core_mesh.MeshGatewayResourceList)
} else {
return nil
}

gateway := xds_topology.SelectGateway(gateways.Items, dataplane.Spec.Matches)
if gateway == nil {
return nil
}

for _, listener := range gateway.Spec.GetConf().GetListeners() {
address := dataplane.Spec.GetNetworking().Address
port := listener.GetPort()
listener, ok := gatewayListeners[xds.InboundListener{
Address: address,
Port: port,
}]
if !ok {
continue
}

if err := configureOutbound(
rules,
dataplane,
xds.Subset{},
mesh_proto.MatchAllTag,
listener,
); err != nil {
return err
}
}

return nil
}

type listeners struct {
inbound map[xds.InboundListener]*envoy_listener.Listener
outbound map[mesh_proto.OutboundInterface]*envoy_listener.Listener
gateway map[xds.InboundListener]*envoy_listener.Listener
ipv4Passthrough *envoy_listener.Listener
ipv6Passthrough *envoy_listener.Listener
directAccess map[generator.Endpoint]*envoy_listener.Listener
Expand All @@ -165,6 +211,7 @@ func gatherListeners(rs *core_xds.ResourceSet) listeners {
listeners := listeners{
inbound: map[xds.InboundListener]*envoy_listener.Listener{},
outbound: map[mesh_proto.OutboundInterface]*envoy_listener.Listener{},
gateway: map[xds.InboundListener]*envoy_listener.Listener{},
directAccess: map[generator.Endpoint]*envoy_listener.Listener{},
}

Expand Down Expand Up @@ -195,6 +242,11 @@ func gatherListeners(rs *core_xds.ResourceSet) listeners {
Address: address.GetAddress(),
Port: address.GetPortValue(),
}] = listener
case gateway.OriginGateway:
listeners.gateway[xds.InboundListener{
Address: address.GetAddress(),
Port: address.GetPortValue(),
}] = listener
default:
continue
}
Expand Down

0 comments on commit 5311e8b

Please sign in to comment.