Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(meshtrace): add support for real resources #12173

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions pkg/plugins/policies/meshtrace/plugin/v1alpha1/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ import (
"strings"

envoy_listener "github.com/envoyproxy/go-control-plane/envoy/config/listener/v3"
envoy_resource "github.com/envoyproxy/go-control-plane/pkg/resource/v3"

mesh_proto "github.com/kumahq/kuma/api/mesh/v1alpha1"
core_plugins "github.com/kumahq/kuma/pkg/core/plugins"
core_mesh "github.com/kumahq/kuma/pkg/core/resources/apis/mesh"
"github.com/kumahq/kuma/pkg/core/resources/model"
"github.com/kumahq/kuma/pkg/core/xds"
xds_types "github.com/kumahq/kuma/pkg/core/xds/types"
"github.com/kumahq/kuma/pkg/plugins/policies/core/matchers"
core_rules "github.com/kumahq/kuma/pkg/plugins/policies/core/rules"
policies_xds "github.com/kumahq/kuma/pkg/plugins/policies/core/xds"
"github.com/kumahq/kuma/pkg/plugins/policies/core/xds/meshroute"
api "github.com/kumahq/kuma/pkg/plugins/policies/meshtrace/api/v1alpha1"
plugin_xds "github.com/kumahq/kuma/pkg/plugins/policies/meshtrace/plugin/xds"
"github.com/kumahq/kuma/pkg/util/pointer"
Expand Down Expand Up @@ -56,6 +59,9 @@ func (p plugin) Apply(rs *xds.ResourceSet, ctx xds_context.Context, proxy *xds.P
if err := applyToGateway(policies.SingleItemRules, listeners.Gateway, ctx.Mesh.Resources.MeshLocalResources, proxy.Dataplane); err != nil {
return err
}
if err := applyToRealResources(ctx, policies.SingleItemRules, rs, proxy); err != nil {
return err
}

return nil
}
Expand Down Expand Up @@ -137,6 +143,33 @@ func applyToOutbounds(
return nil
}

func applyToRealResources(
ctx xds_context.Context,
rules core_rules.SingleItemRules,
rs *xds.ResourceSet,
proxy *xds.Proxy,
) error {
for uri, resType := range rs.IndexByOrigin(xds.NonMeshExternalService) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not MES?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we don't support policies on Egress, thought maybe no point to add it now

service, _, _, found := meshroute.GetServiceProtocolPortFromRef(ctx.Mesh, &model.RealResourceBackendRef{
Resource: &uri,
})
if !found {
continue
}
for typ, resources := range resType {
switch typ {
case envoy_resource.ListenerType:
for _, listener := range resources {
if err := configureListener(rules, proxy.Dataplane, listener.Resource.(*envoy_listener.Listener), service); err != nil {
return err
}
}
}
}
}
return nil
}

func configureListener(rules core_rules.SingleItemRules, dataplane *core_mesh.DataplaneResource, listener *envoy_listener.Listener, destination string) error {
serviceName := dataplane.Spec.GetIdentifyingService()
if len(rules.Rules) == 0 {
Expand Down
Loading
Loading