@@ -1249,32 +1249,43 @@ func TestProcessSecurityPolicyObjectRefs(t *testing.T) {
12491249}
12501250
12511251func TestProcessServiceClusterForGatewayClass (t * testing.T ) {
1252+ gcName := "merged-gc"
1253+ nsName := "envoy-gateway-system"
12521254 testCases := []struct {
12531255 name string
12541256 gatewayClass * gwapiv1.GatewayClass
12551257 envoyProxy * egv1a1.EnvoyProxy
12561258 expectedSvcName string
1259+ serviceCluster []client.Object
12571260 }{
12581261 {
12591262 name : "when merged gateways and no hardcoded svc name is used" ,
12601263 gatewayClass : & gwapiv1.GatewayClass {
12611264 ObjectMeta : metav1.ObjectMeta {
1262- Name : "merged-gc" ,
1265+ Name : gcName ,
12631266 },
12641267 },
12651268 envoyProxy : nil ,
1266- expectedSvcName : proxy .ExpectedResourceHashedName ("merged-gc" ),
1269+ expectedSvcName : proxy .ExpectedResourceHashedName (gcName ),
1270+ serviceCluster : []client.Object {
1271+ & corev1.Service {
1272+ ObjectMeta : metav1.ObjectMeta {
1273+ Name : proxy .ExpectedResourceHashedName (gcName ),
1274+ Namespace : nsName ,
1275+ },
1276+ },
1277+ },
12671278 },
12681279 {
12691280 name : "when merged gateways and a hardcoded svc name is used" ,
12701281 gatewayClass : & gwapiv1.GatewayClass {
12711282 ObjectMeta : metav1.ObjectMeta {
1272- Name : "merged-gc" ,
1283+ Name : gcName ,
12731284 },
12741285 },
12751286 envoyProxy : & egv1a1.EnvoyProxy {
12761287 ObjectMeta : metav1.ObjectMeta {
1277- Name : "merged-gc" ,
1288+ Name : gcName ,
12781289 },
12791290 Spec : egv1a1.EnvoyProxySpec {
12801291 Provider : & egv1a1.EnvoyProxyProvider {
@@ -1288,6 +1299,25 @@ func TestProcessServiceClusterForGatewayClass(t *testing.T) {
12881299 },
12891300 },
12901301 expectedSvcName : "merged-gc-svc" ,
1302+ serviceCluster : []client.Object {
1303+ & corev1.Service {
1304+ ObjectMeta : metav1.ObjectMeta {
1305+ Name : "merged-gc-svc" ,
1306+ Namespace : nsName ,
1307+ },
1308+ },
1309+ },
1310+ },
1311+ {
1312+ name : "non-existent proxy service" ,
1313+ gatewayClass : & gwapiv1.GatewayClass {
1314+ ObjectMeta : metav1.ObjectMeta {
1315+ Name : gcName ,
1316+ },
1317+ },
1318+ envoyProxy : nil ,
1319+ expectedSvcName : proxy .ExpectedResourceHashedName (gcName ),
1320+ serviceCluster : nil ,
12911321 },
12921322 }
12931323
@@ -1299,6 +1329,10 @@ func TestProcessServiceClusterForGatewayClass(t *testing.T) {
12991329 resourceMap := newResourceMapping ()
13001330
13011331 r := newGatewayAPIReconciler (logger )
1332+ r .client = fakeclient .NewClientBuilder ().
1333+ WithScheme (envoygateway .GetScheme ()).
1334+ WithObjects (tc .serviceCluster ... ).
1335+ Build ()
13021336 r .namespace = "envoy-gateway-system"
13031337
13041338 r .processServiceClusterForGatewayClass (tc .envoyProxy , tc .gatewayClass , resourceMap )
@@ -1309,8 +1343,12 @@ func TestProcessServiceClusterForGatewayClass(t *testing.T) {
13091343 Name : gwapiv1 .ObjectName (tc .expectedSvcName ),
13101344 }
13111345 key := backendRefKey (& expectedRef )
1312- require .Contains (t , resourceMap .allAssociatedBackendRefs , key )
1313- require .Equal (t , expectedRef , resourceMap .allAssociatedBackendRefs [key ])
1346+ if tc .serviceCluster != nil {
1347+ require .Contains (t , resourceMap .allAssociatedBackendRefs , key )
1348+ require .Equal (t , expectedRef , resourceMap .allAssociatedBackendRefs [key ])
1349+ } else {
1350+ require .NotContains (t , resourceMap .allAssociatedBackendRefs , key )
1351+ }
13141352 })
13151353 }
13161354}
@@ -1324,6 +1362,7 @@ func TestProcessServiceClusterForGateway(t *testing.T) {
13241362 gatewayNamespacedMode bool
13251363 expectedSvcName string
13261364 expectedSvcNamespace string
1365+ serviceCluster []client.Object
13271366 }{
13281367 {
13291368 name : "no gateway namespaced mode with no hardcoded service name" ,
@@ -1377,6 +1416,14 @@ func TestProcessServiceClusterForGateway(t *testing.T) {
13771416 gatewayNamespacedMode : true ,
13781417 expectedSvcName : "my-gateway" ,
13791418 expectedSvcNamespace : "app-namespace" ,
1419+ serviceCluster : []client.Object {
1420+ & corev1.Service {
1421+ ObjectMeta : metav1.ObjectMeta {
1422+ Name : "my-gateway" ,
1423+ Namespace : "app-namespace" ,
1424+ },
1425+ },
1426+ },
13801427 },
13811428 {
13821429 name : "gateway namespaced mode with hardcoded service name" ,
@@ -1404,6 +1451,14 @@ func TestProcessServiceClusterForGateway(t *testing.T) {
14041451 gatewayNamespacedMode : true ,
14051452 expectedSvcName : "my-gateway-svc" ,
14061453 expectedSvcNamespace : "app-namespace" ,
1454+ serviceCluster : []client.Object {
1455+ & corev1.Service {
1456+ ObjectMeta : metav1.ObjectMeta {
1457+ Name : "my-gateway-svc" ,
1458+ Namespace : "app-namespace" ,
1459+ },
1460+ },
1461+ },
14071462 },
14081463 {
14091464 name : "no gateway namespaced mode with no hardcoded service name attached gatewayclass" ,
@@ -1443,6 +1498,10 @@ func TestProcessServiceClusterForGateway(t *testing.T) {
14431498 resourceMap := newResourceMapping ()
14441499
14451500 r := newGatewayAPIReconciler (logger )
1501+ r .client = fakeclient .NewClientBuilder ().
1502+ WithScheme (envoygateway .GetScheme ()).
1503+ WithObjects (tc .serviceCluster ... ).
1504+ Build ()
14461505 r .namespace = "envoy-gateway-system"
14471506 r .gatewayNamespaceMode = tc .gatewayNamespacedMode
14481507
@@ -1466,8 +1525,12 @@ func TestProcessServiceClusterForGateway(t *testing.T) {
14661525 Name : gwapiv1 .ObjectName (tc .expectedSvcName ),
14671526 }
14681527 key := backendRefKey (& expectedRef )
1469- require .Contains (t , resourceMap .allAssociatedBackendRefs , key )
1470- require .Equal (t , expectedRef , resourceMap .allAssociatedBackendRefs [key ])
1528+ if tc .serviceCluster != nil {
1529+ require .Contains (t , resourceMap .allAssociatedBackendRefs , key )
1530+ require .Equal (t , expectedRef , resourceMap .allAssociatedBackendRefs [key ])
1531+ } else {
1532+ require .NotContains (t , resourceMap .allAssociatedBackendRefs , key )
1533+ }
14711534 })
14721535 }
14731536}
0 commit comments