Skip to content

Commit 458cd0f

Browse files
authored
destination: Test opaque ports resolution for external resources (#8275)
While looking into #8273, I wanted to confirm that the destination controller uses the default opaque ports configuration for arbitrary (unmeshed) IPs. This change adds a test that exercises resolution behavior for external IPs. Signed-off-by: Oliver Gould <ver@buoyant.io>
1 parent 363b8ff commit 458cd0f

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

controller/api/destination/server_test.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const podIPOpaque = "172.17.0.14"
2727
const podIPSkipped = "172.17.0.15"
2828
const podIPPolicy = "172.17.0.16"
2929
const podIPStatefulSet = "172.17.13.15"
30+
const externalIP = "192.168.1.20"
3031
const port uint32 = 8989
3132
const opaquePort uint32 = 4242
3233
const skippedPort uint32 = 24224
@@ -1069,6 +1070,68 @@ func TestGetProfiles(t *testing.T) {
10691070
t.Fatalf("Expected pod to support opaque traffic on port 4143")
10701071
}
10711072
})
1073+
1074+
t.Run("Return profile with opaque protocol when using an opaque port with an external IP", func(t *testing.T) {
1075+
server := makeServer(t)
1076+
stream := &bufferingGetProfileStream{
1077+
updates: []*pb.DestinationProfile{},
1078+
MockServerStream: util.NewMockServerStream(),
1079+
}
1080+
stream.Cancel()
1081+
1082+
_, err := toAddress(externalIP, 3306)
1083+
if err != nil {
1084+
t.Fatalf("Got error: %s", err)
1085+
}
1086+
err = server.GetProfile(&pb.GetDestination{
1087+
Scheme: "k8s",
1088+
Path: fmt.Sprintf("%s:%d", externalIP, 3306),
1089+
}, stream)
1090+
if err != nil {
1091+
t.Fatalf("Got error: %s", err)
1092+
}
1093+
1094+
// Test that the first update has a destination profile with an
1095+
// opaque protocol and opaque transport.
1096+
if len(stream.updates) == 0 {
1097+
t.Fatalf("Expected at least 1 update but got 0")
1098+
}
1099+
update := stream.updates[0]
1100+
if !update.OpaqueProtocol {
1101+
t.Fatalf("Expected port %d to be an opaque protocol, but it was not", 3306)
1102+
}
1103+
})
1104+
1105+
t.Run("Return profile with non-opaque protocol when using an arbitrary port with an external IP", func(t *testing.T) {
1106+
server := makeServer(t)
1107+
stream := &bufferingGetProfileStream{
1108+
updates: []*pb.DestinationProfile{},
1109+
MockServerStream: util.NewMockServerStream(),
1110+
}
1111+
stream.Cancel()
1112+
1113+
_, err := toAddress(externalIP, 80)
1114+
if err != nil {
1115+
t.Fatalf("Got error: %s", err)
1116+
}
1117+
err = server.GetProfile(&pb.GetDestination{
1118+
Scheme: "k8s",
1119+
Path: fmt.Sprintf("%s:%d", externalIP, 80),
1120+
}, stream)
1121+
if err != nil {
1122+
t.Fatalf("Got error: %s", err)
1123+
}
1124+
1125+
// Test that the first update has a destination profile with an
1126+
// opaque protocol and opaque transport.
1127+
if len(stream.updates) == 0 {
1128+
t.Fatalf("Expected at least 1 update but got 0")
1129+
}
1130+
update := stream.updates[0]
1131+
if update.OpaqueProtocol {
1132+
t.Fatalf("Expected port %d to be a non-opaque protocol, but it was opaque", 80)
1133+
}
1134+
})
10721135
}
10731136

10741137
func TestTokenStructure(t *testing.T) {

0 commit comments

Comments
 (0)