@@ -3,6 +3,7 @@ package e2e
3
3
import (
4
4
"encoding/json"
5
5
"fmt"
6
+ "reflect"
6
7
"strings"
7
8
"sync"
8
9
"testing"
@@ -24,6 +25,7 @@ import (
24
25
corev1 "k8s.io/api/core/v1"
25
26
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
26
27
k8serrors "k8s.io/apimachinery/pkg/api/errors"
28
+ "k8s.io/apimachinery/pkg/api/resource"
27
29
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
28
30
"k8s.io/apimachinery/pkg/util/wait"
29
31
"k8s.io/client-go/tools/clientcmd"
@@ -1327,11 +1329,30 @@ func TestCreateNewSubscriptionWithPodConfig(t *testing.T) {
1327
1329
podVolumeMounts := []corev1.VolumeMount {
1328
1330
corev1.VolumeMount {Name : testVolumeName , MountPath : "/test" },
1329
1331
}
1332
+ podTolerations := []corev1.Toleration {
1333
+ corev1.Toleration {
1334
+ Key : "my-toleration-key" ,
1335
+ Value : "my-toleration-value" ,
1336
+ Effect : corev1 .TaintEffectNoSchedule ,
1337
+ Operator : corev1 .TolerationOpEqual ,
1338
+ },
1339
+ }
1340
+ podResources := corev1.ResourceRequirements {
1341
+ Limits : corev1.ResourceList {
1342
+ corev1 .ResourceCPU : resource .MustParse ("100m" ),
1343
+ },
1344
+ Requests : corev1.ResourceList {
1345
+ corev1 .ResourceCPU : resource .MustParse ("100m" ),
1346
+ corev1 .ResourceMemory : resource .MustParse ("128Mi" ),
1347
+ },
1348
+ }
1330
1349
1331
1350
podConfig := v1alpha1.SubscriptionConfig {
1332
1351
Env : podEnv ,
1333
1352
Volumes : podVolumes ,
1334
1353
VolumeMounts : podVolumeMounts ,
1354
+ Tolerations : podTolerations ,
1355
+ Resources : podResources ,
1335
1356
}
1336
1357
1337
1358
permissions := deploymentPermissions (t )
@@ -1358,7 +1379,7 @@ func TestCreateNewSubscriptionWithPodConfig(t *testing.T) {
1358
1379
expected := podEnv
1359
1380
expected = append (expected , proxyEnv ... )
1360
1381
1361
- checkDeploymentWithPodConfiguration (t , kubeClient , csv , podConfig .Env , podConfig .Volumes , podConfig .VolumeMounts )
1382
+ checkDeploymentWithPodConfiguration (t , kubeClient , csv , podConfig .Env , podConfig .Volumes , podConfig .VolumeMounts , podConfig . Tolerations , podConfig . Resources )
1362
1383
}
1363
1384
1364
1385
func TestCreateNewSubscriptionWithDependencies (t * testing.T ) {
@@ -1402,7 +1423,7 @@ func TestCreateNewSubscriptionWithDependencies(t *testing.T) {
1402
1423
1403
1424
}
1404
1425
1405
- func checkDeploymentWithPodConfiguration (t * testing.T , client operatorclient.ClientInterface , csv * v1alpha1.ClusterServiceVersion , envVar []corev1.EnvVar , volumes []corev1.Volume , volumeMounts []corev1.VolumeMount ) {
1426
+ func checkDeploymentWithPodConfiguration (t * testing.T , client operatorclient.ClientInterface , csv * v1alpha1.ClusterServiceVersion , envVar []corev1.EnvVar , volumes []corev1.Volume , volumeMounts []corev1.VolumeMount , tolerations []corev1. Toleration , resources corev1. ResourceRequirements ) {
1406
1427
resolver := install.StrategyResolver {}
1407
1428
1408
1429
strategy , err := resolver .UnmarshalStrategy (csv .Spec .InstallStrategy )
@@ -1450,6 +1471,28 @@ func checkDeploymentWithPodConfiguration(t *testing.T, client operatorclient.Cli
1450
1471
return
1451
1472
}
1452
1473
1474
+ findTolerations := func (tolerations []corev1.Toleration , toleration corev1.Toleration ) (foundToleration * corev1.Toleration , found bool ) {
1475
+ for i := range tolerations {
1476
+ if reflect .DeepEqual (toleration , tolerations [i ]) {
1477
+ found = true
1478
+ foundToleration = & toleration
1479
+
1480
+ break
1481
+ }
1482
+ }
1483
+
1484
+ return
1485
+ }
1486
+
1487
+ findResources := func (existingResource corev1.ResourceRequirements , podResource corev1.ResourceRequirements ) (foundResource * corev1.ResourceRequirements , found bool ) {
1488
+ if reflect .DeepEqual (existingResource , podResource ) {
1489
+ found = true
1490
+ foundResource = & podResource
1491
+ }
1492
+
1493
+ return
1494
+ }
1495
+
1453
1496
check := func (container * corev1.Container ) {
1454
1497
for _ , e := range envVar {
1455
1498
existing , found := findEnvVar (container .Env , e .Name )
@@ -1464,6 +1507,11 @@ func checkDeploymentWithPodConfiguration(t *testing.T, client operatorclient.Cli
1464
1507
require .NotNil (t , existing )
1465
1508
require .Equalf (t , v .MountPath , existing .MountPath , "VolumeMount MountPath does not match %s=%s" , v .Name , v .MountPath )
1466
1509
}
1510
+
1511
+ existing , found := findResources (container .Resources , resources )
1512
+ require .Truef (t , found , "Resources not injected. Resource=%v" , resources )
1513
+ require .NotNil (t , existing )
1514
+ require .Equalf (t , * existing , resources , "Resource=%v does not match expected Resource=%v" , existing , resources )
1467
1515
}
1468
1516
1469
1517
for _ , deploymentSpec := range strategyDetailsDeployment .DeploymentSpecs {
@@ -1475,6 +1523,12 @@ func checkDeploymentWithPodConfiguration(t *testing.T, client operatorclient.Cli
1475
1523
require .NotNil (t , existing )
1476
1524
require .Equalf (t , v .ConfigMap .LocalObjectReference .Name , existing .ConfigMap .LocalObjectReference .Name , "volume ConfigMap Names does not match %s=%s" , v .Name , v .ConfigMap .LocalObjectReference .Name )
1477
1525
}
1526
+ for _ , toleration := range tolerations {
1527
+ existing , found := findTolerations (deployment .Spec .Template .Spec .Tolerations , toleration )
1528
+ require .Truef (t , found , "Toleration not injected. Toleration=%v" , toleration )
1529
+ require .NotNil (t , existing )
1530
+ require .Equalf (t , * existing , toleration , "Toleration=%v does not match expected Toleration=%v" , existing , toleration )
1531
+ }
1478
1532
1479
1533
for i := range deployment .Spec .Template .Spec .Containers {
1480
1534
check (& deployment .Spec .Template .Spec .Containers [i ])
0 commit comments