Skip to content

Commit 7e3a76e

Browse files
authored
Propagate trust domain to e/w gateway (#58428)
* Propagate trust domain to e/w gateway Signed-off-by: Keith Mattix II <keithmattix@microsoft.com> * Add release note Signed-off-by: Keith Mattix II <keithmattix@microsoft.com> * Remove extra space Signed-off-by: Keith Mattix II <keithmattix@microsoft.com> --------- Signed-off-by: Keith Mattix II <keithmattix@microsoft.com>
1 parent 90b77e3 commit 7e3a76e

File tree

3 files changed

+36
-16
lines changed

3 files changed

+36
-16
lines changed

pilot/pkg/serviceregistry/kube/controller/ambient/ambientindex_multicluster_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,8 @@ func TestMulticlusterAmbientIndex_TestServiceMerging(t *testing.T) {
551551
func TestMulticlusterAmbientIndex_SplitHorizon(t *testing.T) {
552552
test.SetForTest(t, &features.EnableAmbientMultiNetwork, true)
553553
s := newAmbientTestServer(t, testC, testNW, "")
554+
// Test that we're propagating the trust domain correctly
555+
s.meshConfig.Mesh().TrustDomain = s.DomainSuffix
554556
s.AddSecret("s1", "remote-cluster") // overlapping ips
555557
remoteClients := krt.NewCollection(s.remoteClusters, func(_ krt.HandlerContext, c *multicluster.Cluster) **remoteAmbientClients {
556558
cl := c.Client
@@ -635,6 +637,12 @@ func TestMulticlusterAmbientIndex_SplitHorizon(t *testing.T) {
635637
if len(gwwl.Workload.Addresses) != 1 {
636638
return fmt.Errorf("expected network gateway workload to have addresses, got %v", gwwl.Workload.Addresses)
637639
}
640+
if gwwl.Workload.TrustDomain != s.DomainSuffix {
641+
return fmt.Errorf("expected network gateway workload to have trust domain %s, got %s",
642+
s.DomainSuffix,
643+
gwwl.Workload.TrustDomain,
644+
)
645+
}
638646
expectedAddress := []uint8{172, 0, 1, 2}
639647
if !reflect.DeepEqual(gwwl.Workload.Addresses[0], expectedAddress) {
640648
return fmt.Errorf("expected network gateway workload to have address %s, got %s",

pilot/pkg/serviceregistry/kube/controller/ambient/workloads.go

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ func (a *index) WorkloadsCollection(
115115
opts.WithName("EndpointSliceWorkloads")...)
116116

117117
NetworkGatewayWorkloads := krt.NewManyFromNothing[model.WorkloadInfo](func(ctx krt.HandlerContext) []model.WorkloadInfo {
118-
return slices.Map(a.LookupAllNetworkGateway(ctx), convertGateway)
118+
meshCfg := krt.FetchOne(ctx, meshConfig.AsCollection())
119+
return slices.Map(a.LookupAllNetworkGateway(ctx), convertGateway(meshCfg))
119120
}, opts.WithName("NetworkGatewayWorkloads")...)
120121

121122
Workloads := krt.JoinCollection(
@@ -263,10 +264,11 @@ func MergedGlobalWorkloadsCollection(
263264
)
264265

265266
GlobalNetworkGatewayWorkloads := krt.NewManyFromNothing[model.WorkloadInfo](func(ctx krt.HandlerContext) []model.WorkloadInfo {
267+
meshCfg := krt.FetchOne(ctx, meshConfig.AsCollection())
266268
return slices.Map(LookupAllNetworkGateway(
267269
ctx,
268270
globalNetworks.NetworkGateways,
269-
), convertGateway)
271+
), convertGateway(meshCfg))
270272
}, opts.WithName("LocalNetworkGatewayWorkloads")...)
271273
LocalNetworkGatewayWorkloadsWithCluster := krt.MapCollection(
272274
GlobalNetworkGatewayWorkloads,
@@ -1544,22 +1546,25 @@ func gatewayUID(gw model.NetworkGateway) string {
15441546
// convertGateway always converts a NetworkGateway into a Workload.
15451547
// Workloads have a NetworkGateway field, which is effectively a pointer to another object (Service or Workload); in order
15461548
// to facilitate this we need to translate our Gateway model down into a WorkloadInfo ztunnel can understand.
1547-
func convertGateway(gw NetworkGateway) model.WorkloadInfo {
1548-
wl := &workloadapi.Workload{
1549-
Uid: gatewayUID(gw.NetworkGateway),
1550-
Name: gatewayUID(gw.NetworkGateway),
1551-
ServiceAccount: gw.ServiceAccount.Name,
1552-
Namespace: gw.ServiceAccount.Namespace,
1553-
Network: gw.Network.String(),
1554-
}
1549+
func convertGateway(mesh *MeshConfig) func(gw NetworkGateway) model.WorkloadInfo {
1550+
return func(gw NetworkGateway) model.WorkloadInfo {
1551+
wl := &workloadapi.Workload{
1552+
Uid: gatewayUID(gw.NetworkGateway),
1553+
Name: gatewayUID(gw.NetworkGateway),
1554+
ServiceAccount: gw.ServiceAccount.Name,
1555+
Namespace: gw.ServiceAccount.Namespace,
1556+
Network: gw.Network.String(),
1557+
TrustDomain: pickTrustDomain(mesh),
1558+
}
15551559

1556-
if ip, err := netip.ParseAddr(gw.Addr); err == nil {
1557-
wl.Addresses = append(wl.Addresses, ip.AsSlice())
1558-
} else {
1559-
wl.Hostname = gw.Addr
1560-
}
1560+
if ip, err := netip.ParseAddr(gw.Addr); err == nil {
1561+
wl.Addresses = append(wl.Addresses, ip.AsSlice())
1562+
} else {
1563+
wl.Hostname = gw.Addr
1564+
}
15611565

1562-
return precomputeWorkload(model.WorkloadInfo{Workload: wl})
1566+
return precomputeWorkload(model.WorkloadInfo{Workload: wl})
1567+
}
15631568
}
15641569

15651570
func getNetworkGatewayAddress(

releasenotes/notes/58427.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: release-notes/v2
2+
kind: bug-fix
3+
area: traffic-management
4+
issue: [58427]
5+
releaseNotes:
6+
- |
7+
**Fixed** an issue causing ambient multi-network connections to fail when using a custom trust domain.

0 commit comments

Comments
 (0)