@@ -11,6 +11,7 @@ import (
11
11
"testing"
12
12
13
13
"github.com/stretchr/testify/require"
14
+ certificatesv1a1 "k8s.io/api/certificates/v1alpha1"
14
15
corev1 "k8s.io/api/core/v1"
15
16
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
16
17
"k8s.io/apimachinery/pkg/types"
@@ -20,6 +21,7 @@ import (
20
21
fakeclient "sigs.k8s.io/controller-runtime/pkg/client/fake"
21
22
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
22
23
gwapiv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
24
+ gwapiv1a3 "sigs.k8s.io/gateway-api/apis/v1alpha3"
23
25
24
26
egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1"
25
27
"github.com/envoyproxy/gateway/internal/envoygateway"
@@ -1341,3 +1343,126 @@ func TestValidateHTTPRouteFilerForReconcile(t *testing.T) {
1341
1343
})
1342
1344
}
1343
1345
}
1346
+
1347
+ func TestValidateClusterTrustBundleForReconcile (t * testing.T ) {
1348
+ gc := test .GetGatewayClass ("test-gc" , egv1a1 .GatewayControllerName , nil )
1349
+ gtw := test .GetGateway (types.NamespacedName {Namespace : "default" , Name : "scheduled-status-test" }, "test-gc" , 8080 )
1350
+ ctb := test .GetClusterTrustBundle ("fake-ctb" )
1351
+ backend := & egv1a1.Backend {
1352
+ ObjectMeta : metav1.ObjectMeta {
1353
+ Name : "backend-dynamic-resolver-clustertrustbundle" ,
1354
+ Namespace : "default" ,
1355
+ },
1356
+ Spec : egv1a1.BackendSpec {
1357
+ Type : ptr .To (egv1a1 .BackendTypeDynamicResolver ),
1358
+ TLS : & egv1a1.BackendTLSSettings {
1359
+ CACertificateRefs : []gwapiv1.LocalObjectReference {
1360
+ {
1361
+ Kind : gwapiv1 .Kind ("ClusterTrustBundle" ),
1362
+ Name : gwapiv1 .ObjectName (ctb .Name ),
1363
+ },
1364
+ },
1365
+ },
1366
+ },
1367
+ }
1368
+ btp := & gwapiv1a3.BackendTLSPolicy {
1369
+ ObjectMeta : metav1.ObjectMeta {
1370
+ Name : "backend-tls-policy-dynamic-resolver-clustertrustbundle" ,
1371
+ Namespace : "default" ,
1372
+ },
1373
+ Spec : gwapiv1a3.BackendTLSPolicySpec {
1374
+ Validation : gwapiv1a3.BackendTLSPolicyValidation {
1375
+ CACertificateRefs : []gwapiv1.LocalObjectReference {
1376
+ {
1377
+ Kind : gwapiv1 .Kind ("ClusterTrustBundle" ),
1378
+ Name : gwapiv1 .ObjectName (ctb .Name ),
1379
+ },
1380
+ },
1381
+ },
1382
+ },
1383
+ }
1384
+ ctp := test .GetClientTrafficPolicy (
1385
+ types.NamespacedName {Name : "fake-ctp" , Namespace : "default" },
1386
+ & egv1a1.ClientTLSSettings {
1387
+ ClientValidation : & egv1a1.ClientValidationContext {
1388
+ CACertificateRefs : []gwapiv1.SecretObjectReference {
1389
+ {
1390
+ Kind : ptr.To [gwapiv1.Kind ]("ClusterTrustBundle" ),
1391
+ Name : gwapiv1 .ObjectName (ctb .Name ),
1392
+ },
1393
+ },
1394
+ },
1395
+ })
1396
+
1397
+ testCases := []struct {
1398
+ name string
1399
+ configs []client.Object
1400
+ ctb * certificatesv1a1.ClusterTrustBundle
1401
+ expect bool
1402
+ }{
1403
+ {
1404
+ name : "referenced by Backend" ,
1405
+ configs : []client.Object {
1406
+ gc ,
1407
+ gtw ,
1408
+ backend ,
1409
+ },
1410
+ ctb : ctb ,
1411
+ expect : true ,
1412
+ },
1413
+ {
1414
+ name : "referenced by BackendTLSPolicy" ,
1415
+ configs : []client.Object {
1416
+ gc ,
1417
+ gtw ,
1418
+ btp ,
1419
+ },
1420
+ ctb : ctb ,
1421
+ expect : true ,
1422
+ },
1423
+ {
1424
+ name : "referenced by ClientTrafficPolicy" ,
1425
+ configs : []client.Object {
1426
+ gc ,
1427
+ gtw ,
1428
+ ctp ,
1429
+ },
1430
+ ctb : ctb ,
1431
+ expect : true ,
1432
+ },
1433
+ {
1434
+ name : "ClusterTrustBundle not referenced" ,
1435
+ configs : []client.Object {
1436
+ gc ,
1437
+ gtw ,
1438
+ },
1439
+ ctb : ctb ,
1440
+ expect : false ,
1441
+ },
1442
+ }
1443
+
1444
+ // Create the reconciler.
1445
+ logger := logging .DefaultLogger (os .Stdout , egv1a1 .LogLevelInfo )
1446
+
1447
+ r := gatewayAPIReconciler {
1448
+ classController : egv1a1 .GatewayControllerName ,
1449
+ log : logger ,
1450
+ backendCRDExists : true ,
1451
+ bTLSPolicyCRDExists : true ,
1452
+ ctpCRDExists : true ,
1453
+ }
1454
+
1455
+ for _ , tc := range testCases {
1456
+ r .client = fakeclient .NewClientBuilder ().
1457
+ WithScheme (envoygateway .GetScheme ()).
1458
+ WithObjects (tc .configs ... ).
1459
+ WithIndex (& egv1a1.Backend {}, clusterTrustBundleBackendIndex , clusterTrustBundleBackendIndexFunc ).
1460
+ WithIndex (& gwapiv1a3.BackendTLSPolicy {}, clusterTrustBundleBtlsIndex , clusterTrustBundleBtlsIndexFunc ).
1461
+ WithIndex (& egv1a1.ClientTrafficPolicy {}, clusterTrustBundlerCtpIndex , clusterTrustBundleCtpIndexFunc ).
1462
+ Build ()
1463
+ t .Run (tc .name , func (t * testing.T ) {
1464
+ res := r .validateClusterTrustBundleForReconcile (tc .ctb )
1465
+ require .Equal (t , tc .expect , res )
1466
+ })
1467
+ }
1468
+ }
0 commit comments