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

feat(meshexternalservice): support MeshExternalService in MeshGateway and MeshHTTPRoute #11383

Merged
merged 15 commits into from
Sep 13, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,92 @@ var _ = Describe("MeshHTTPRoute", func() {
proxy: proxy,
}
}()),
Entry("gateway-default-meshexternalservice", func() outboundsTestCase {
meshExtSvc := meshexternalservice_api.MeshExternalServiceResource{
Meta: &test_model.ResourceMeta{Name: "example", Mesh: "default"},
Spec: &meshexternalservice_api.MeshExternalService{
Match: meshexternalservice_api.Match{
Type: pointer.To(meshexternalservice_api.HostnameGeneratorType),
Port: 9090,
Protocol: core_mesh.ProtocolHTTP,
},
Endpoints: []meshexternalservice_api.Endpoint{
{
Address: "example.com",
Port: pointer.To(meshexternalservice_api.Port(10000)),
},
},
},
Status: &meshexternalservice_api.MeshExternalServiceStatus{
VIP: meshexternalservice_api.VIP{
IP: "10.20.20.1",
},
},
}
gateway := &core_mesh.MeshGatewayResource{
Meta: &test_model.ResourceMeta{Name: "sample-gateway", Mesh: "default"},
Spec: &mesh_proto.MeshGateway{
Selectors: []*mesh_proto.Selector{
{
Match: map[string]string{
mesh_proto.ServiceTag: "sample-gateway",
},
},
},
Conf: &mesh_proto.MeshGateway_Conf{
Listeners: []*mesh_proto.MeshGateway_Listener{
{
Protocol: mesh_proto.MeshGateway_Listener_HTTP,
Port: 8080,
},
},
},
},
}
meshHttpRoute := api.MeshHTTPRouteResource{
Meta: &test_model.ResourceMeta{Name: "http-route", Mesh: "default"},
Spec: &api.MeshHTTPRoute{
TargetRef: builders.TargetRefMeshGateway("sample-gateway"),
To: []api.To{
{
TargetRef: common_api.TargetRef{
Kind: common_api.MeshExternalService,
Name: "example",
},
Rules: []api.Rule{
{
Matches: []api.Match{{
Path: &api.PathMatch{
Type: api.PathPrefix,
Value: "/",
},
}},
Default: api.RuleConf{
BackendRefs: &[]common_api.BackendRef{{
TargetRef: common_api.TargetRef{
Kind: common_api.MeshExternalService,
Name: "external",
},
Port: pointer.To(uint32(9090)),
Weight: pointer.To(uint(100)),
}},
},
},
},
},
},
},
}

dp, proxy := dppForMeshExternalService(&meshExtSvc)
egress := builders.ZoneEgress().WithPort(10002).Build()
mc := meshContextWithResources(dp.Build(), &meshExtSvc, egress, gateway, &meshHttpRoute)

return outboundsTestCase{
xdsContext: *xds_builders.Context().WithMeshContext(mc).Build(),
proxy: proxy,
}
}()),
Entry("httproute-meshexternalservice", func() outboundsTestCase {
meshExtSvc := meshexternalservice_api.MeshExternalServiceResource{
Meta: &test_model.ResourceMeta{Name: "example", Mesh: "default"},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
resources:
- name: default_example___extsvc_9090
resource:
'@type': type.googleapis.com/envoy.config.cluster.v3.Cluster
edsClusterConfig:
edsConfig:
ads: {}
initialFetchTimeout: 0s
resourceApiVersion: V3
name: default_example___extsvc_9090
transportSocket:
name: envoy.transport_sockets.tls
typedConfig:
'@type': type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
commonTlsContext:
alpnProtocols:
- kuma
combinedValidationContext:
defaultValidationContext:
matchTypedSubjectAltNames:
- matcher:
exact: spiffe://default/zone-egress
sanType: URI
validationContextSdsSecretConfig:
name: mesh_ca:secret:default
sdsConfig:
ads: {}
resourceApiVersion: V3
tlsCertificateSdsSecretConfigs:
- name: identity_cert:secret:default
sdsConfig:
ads: {}
resourceApiVersion: V3
sni: afce62f771ed74b78.example.9090.default.mes
type: EDS
typedExtensionProtocolOptions:
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
'@type': type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions
explicitHttpConfig:
httpProtocolOptions: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
resources:
- name: default_example___extsvc_9090
resource:
'@type': type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment
clusterName: default_example___extsvc_9090
endpoints:
- lbEndpoints:
- endpoint:
address:
socketAddress:
address: 127.0.0.1
portValue: 10002
loadBalancingWeight: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
resources:
- name: outbound:10.20.20.1:9090
resource:
'@type': type.googleapis.com/envoy.config.listener.v3.Listener
address:
socketAddress:
address: 10.20.20.1
portValue: 9090
filterChains:
- filters:
- name: envoy.filters.network.http_connection_manager
typedConfig:
'@type': type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
httpFilters:
- name: envoy.filters.http.router
typedConfig:
'@type': type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
normalizePath: true
routeConfig:
name: default_example___extsvc_9090
requestHeadersToAdd:
- header:
key: x-kuma-tags
value: '&kuma.io/protocol=http&&kuma.io/service=web&'
validateClusters: false
virtualHosts:
- domains:
- '*'
name: default_example___extsvc_9090
routes:
- match:
prefix: /
name: 9Zuf5Tg79OuZcQITwBbQykxAk2u4fRKrwYn3//AL4Yo=
route:
autoHostRewrite: true
cluster: default_example___extsvc_9090
timeout: 0s
statPrefix: default_example___extsvc_9090
metadata:
filterMetadata:
io.kuma.tags: {}
name: outbound:10.20.20.1:9090
trafficDirection: OUTBOUND

This file was deleted.

This file was deleted.

This file was deleted.

3 changes: 2 additions & 1 deletion pkg/plugins/runtime/gateway/cluster_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ func (c *ClusterGenerator) GenerateClusters(ctx context.Context, xdsCtx xds_cont
log.Info("skipping backendRef", "backendRef", dest.BackendRef.LegacyBackendRef)
continue
}
isExternalCluster = dest.BackendRef.LegacyBackendRef.Kind == "MeshExternalService"
isExternalService := xdsCtx.Mesh.IsExternalService(service)
isExternalCluster = isExternalService && !xdsCtx.Mesh.Resource.ZoneEgressEnabled()
} else {
service = dest.Destination[mesh_proto.ServiceTag]

Expand Down
7 changes: 7 additions & 0 deletions pkg/test/resources/builders/targetref_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,10 @@ func TargetRefMeshExternalService(name string) common_api.TargetRef {
Name: name,
}
}

func TargetRefMeshGateway(name string) *common_api.TargetRef {
return &common_api.TargetRef{
Kind: common_api.MeshGateway,
Name: name,
}
}
2 changes: 2 additions & 0 deletions pkg/xds/envoy/tags/match.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ func FromTargetRef(targetRef common_api.TargetRef) (Tags, bool) {
switch targetRef.Kind {
case common_api.MeshService:
service = targetRef.Name
case common_api.MeshExternalService:
service = targetRef.Name
case common_api.MeshServiceSubset:
service = targetRef.Name
tags = targetRef.Tags
Expand Down
Loading
Loading