@@ -74,20 +74,19 @@ var _ = Describe("v1beta1 inference service controller", func() {
74
74
}
75
75
)
76
76
77
- Context ("When creating inference service with raw kube predictor" , func () {
78
- configs := map [string ]string {
79
- "explainers" : `{
77
+ configs := map [string ]string {
78
+ "explainers" : `{
80
79
"alibi": {
81
80
"image": "kserve/alibi-explainer",
82
81
"defaultImageVersion": "latest"
83
82
}
84
83
}` ,
85
- "ingress" : `{
84
+ "ingress" : `{
86
85
"ingressGateway": "knative-serving/knative-ingress-gateway",
87
86
"localGateway": "knative-serving/knative-local-gateway",
88
87
"localGatewayService": "knative-local-gateway.istio-system.svc.cluster.local"
89
88
}` ,
90
- "storageInitializer" : `{
89
+ "storageInitializer" : `{
91
90
"image" : "kserve/storage-initializer:latest",
92
91
"memoryRequest": "100Mi",
93
92
"memoryLimit": "1Gi",
@@ -97,7 +96,8 @@ var _ = Describe("v1beta1 inference service controller", func() {
97
96
"caBundleVolumeMountPath": "/etc/ssl/custom-certs",
98
97
"enableDirectPvcVolumeMount": false
99
98
}` ,
100
- }
99
+ }
100
+ Context ("When creating inference service with raw kube predictor" , func () {
101
101
102
102
It ("Should have ingress/service/deployment/hpa created" , func () {
103
103
By ("By creating a new InferenceService" )
@@ -1383,6 +1383,199 @@ var _ = Describe("v1beta1 inference service controller", func() {
1383
1383
ShouldNot (Succeed ())
1384
1384
})
1385
1385
})
1386
+
1387
+ Context ("When updating ISVC envs" , func () {
1388
+ It ("Should reconcile the deployment if isvc envs are updated" , func () {
1389
+ defaultEnvs := []v1.EnvVar {
1390
+ {
1391
+ Name : "env1" ,
1392
+ Value : "val1" ,
1393
+ },
1394
+ {
1395
+ Name : "env2" ,
1396
+ Value : "val2" ,
1397
+ },
1398
+ {
1399
+ Name : "env3" ,
1400
+ Value : "val3" ,
1401
+ },
1402
+ }
1403
+
1404
+ // Create configmap
1405
+ var configMap = & v1.ConfigMap {
1406
+ ObjectMeta : metav1.ObjectMeta {
1407
+ Name : constants .InferenceServiceConfigMapName ,
1408
+ Namespace : constants .KServeNamespace ,
1409
+ },
1410
+ Data : configs ,
1411
+ }
1412
+ Expect (k8sClient .Create (context .TODO (), configMap )).NotTo (HaveOccurred ())
1413
+ defer k8sClient .Delete (context .TODO (), configMap )
1414
+ // Create ServingRuntime
1415
+ servingRuntime := & v1alpha1.ServingRuntime {
1416
+ ObjectMeta : metav1.ObjectMeta {
1417
+ Name : "tf-serving-raw" ,
1418
+ Namespace : "default" ,
1419
+ },
1420
+ Spec : v1alpha1.ServingRuntimeSpec {
1421
+ SupportedModelFormats : []v1alpha1.SupportedModelFormat {
1422
+ {
1423
+ Name : "tensorflow" ,
1424
+ Version : proto .String ("1" ),
1425
+ AutoSelect : proto .Bool (true ),
1426
+ },
1427
+ },
1428
+ ServingRuntimePodSpec : v1alpha1.ServingRuntimePodSpec {
1429
+ Containers : []v1.Container {
1430
+ {
1431
+ Name : "kserve-container" ,
1432
+ Image : "tensorflow/serving:1.14.0" ,
1433
+ Command : []string {"/usr/bin/tensorflow_model_server" },
1434
+ Args : []string {
1435
+ "--port=9000" ,
1436
+ "--rest_api_port=8080" ,
1437
+ "--model_base_path=/mnt/models" ,
1438
+ "--rest_api_timeout_in_ms=60000" ,
1439
+ },
1440
+ Resources : defaultResource ,
1441
+ },
1442
+ },
1443
+ },
1444
+ Disabled : proto .Bool (false ),
1445
+ },
1446
+ }
1447
+ k8sClient .Create (context .TODO (), servingRuntime )
1448
+ defer k8sClient .Delete (context .TODO (), servingRuntime )
1449
+ serviceName := "raw-test-env"
1450
+ var expectedRequest = reconcile.Request {NamespacedName : types.NamespacedName {Name : serviceName , Namespace : "default" }}
1451
+ var serviceKey = expectedRequest .NamespacedName
1452
+ // create isvc
1453
+ var storageUri = "s3://test/mnist/export"
1454
+ isvcOriginal := & v1beta1.InferenceService {
1455
+ ObjectMeta : metav1.ObjectMeta {
1456
+ Name : serviceKey .Name ,
1457
+ Namespace : serviceKey .Namespace ,
1458
+ Annotations : map [string ]string {
1459
+ "serving.kserve.io/deploymentMode" : "RawDeployment" ,
1460
+ "serving.kserve.io/autoscalerClass" : "hpa" ,
1461
+ "serving.kserve.io/metrics" : "cpu" ,
1462
+ "serving.kserve.io/targetUtilizationPercentage" : "75" ,
1463
+ },
1464
+ },
1465
+ Spec : v1beta1.InferenceServiceSpec {
1466
+ Predictor : v1beta1.PredictorSpec {
1467
+ ComponentExtensionSpec : v1beta1.ComponentExtensionSpec {
1468
+ MinReplicas : v1beta1 .GetIntReference (1 ),
1469
+ MaxReplicas : 3 ,
1470
+ },
1471
+ Tensorflow : & v1beta1.TFServingSpec {
1472
+ PredictorExtensionSpec : v1beta1.PredictorExtensionSpec {
1473
+
1474
+ StorageURI : & storageUri ,
1475
+ RuntimeVersion : proto .String ("1.14.0" ),
1476
+ Container : v1.Container {
1477
+ Name : constants .InferenceServiceContainerName ,
1478
+ Resources : defaultResource ,
1479
+ Env : defaultEnvs ,
1480
+ },
1481
+ },
1482
+ },
1483
+ },
1484
+ },
1485
+ }
1486
+
1487
+ isvcOriginal .DefaultInferenceService (nil , nil , & v1beta1.SecurityConfig {AutoMountServiceAccountToken : false }, nil )
1488
+ Expect (k8sClient .Create (ctx , isvcOriginal )).Should (Succeed ())
1489
+
1490
+ inferenceService := & v1beta1.InferenceService {}
1491
+ Eventually (func () bool {
1492
+ err := k8sClient .Get (ctx , serviceKey , inferenceService )
1493
+ if err != nil {
1494
+ return false
1495
+ }
1496
+ return true
1497
+ }, timeout , interval ).Should (BeTrue ())
1498
+
1499
+ deployed1 := & appsv1.Deployment {}
1500
+ predictorDeploymentKey := types.NamespacedName {Name : constants .PredictorServiceName (serviceKey .Name ),
1501
+ Namespace : serviceKey .Namespace }
1502
+ Eventually (func () error {
1503
+ return k8sClient .Get (context .TODO (), predictorDeploymentKey , deployed1 )
1504
+ }, timeout , interval ).Should (Succeed ())
1505
+ Expect (deployed1 .Spec .Template .Spec .Containers [0 ].Env ).To (ContainElements (defaultEnvs ))
1506
+
1507
+ // Now, update the isvc with new env
1508
+ newEnvs := []v1.EnvVar {
1509
+ {
1510
+ Name : "newEnv1" ,
1511
+ Value : "newValue1" ,
1512
+ },
1513
+ {
1514
+ Name : "newEnv2" ,
1515
+ Value : "delete" ,
1516
+ },
1517
+ }
1518
+
1519
+ // Update the isvc to add new envs
1520
+ fmt .Fprintln (GinkgoWriter , "### Adding new envs" )
1521
+ isvcUpdated1 := & v1beta1.InferenceService {}
1522
+ Eventually (func () bool {
1523
+ // get the latest deployed version
1524
+ err := k8sClient .Get (ctx , serviceKey , inferenceService )
1525
+ if err != nil {
1526
+ return false
1527
+ }
1528
+
1529
+ isvcUpdated1 = inferenceService .DeepCopy ()
1530
+ isvcUpdated1 .Spec .Predictor .Model .Env = append (isvcUpdated1 .Spec .Predictor .Model .Env , newEnvs ... )
1531
+ err = k8sClient .Update (ctx , isvcUpdated1 )
1532
+ if err != nil {
1533
+ return false
1534
+ }
1535
+ return true
1536
+ }, timeout , interval ).Should (BeTrue ())
1537
+
1538
+ // The deployment should be reconciled
1539
+ deployed2 := & appsv1.Deployment {}
1540
+ appendedEnvs := append (defaultEnvs , newEnvs ... )
1541
+ Eventually (func () []v1.EnvVar {
1542
+ _ = k8sClient .Get (context .TODO (), predictorDeploymentKey , deployed2 )
1543
+ return deployed2 .Spec .Template .Spec .Containers [0 ].Env
1544
+ }, timeout , interval ).Should (ContainElements (appendedEnvs ))
1545
+
1546
+ // Now remove the default envs and update the isvc
1547
+ fmt .Fprintln (GinkgoWriter , "### Removing default envs" )
1548
+ isvcUpdated2 := & v1beta1.InferenceService {}
1549
+ Eventually (func () bool {
1550
+ // get the latest deployed version
1551
+ err := k8sClient .Get (ctx , serviceKey , isvcUpdated1 )
1552
+ if err != nil {
1553
+ return false
1554
+ }
1555
+
1556
+ isvcUpdated2 = isvcUpdated1 .DeepCopy ()
1557
+ isvcUpdated2 .Spec .Predictor .Model .Env = newEnvs
1558
+ // Make sure the default envs were removed before updating the isvc
1559
+ Expect (isvcUpdated2 .Spec .Predictor .Model .Env ).ToNot (ContainElements (defaultEnvs ))
1560
+
1561
+ err = k8sClient .Update (ctx , isvcUpdated2 )
1562
+ if err != nil {
1563
+ return false
1564
+ }
1565
+ return true
1566
+ }, timeout , interval ).Should (BeTrue ())
1567
+
1568
+ deployed3 := & appsv1.Deployment {}
1569
+ Eventually (func () []v1.EnvVar {
1570
+ _ = k8sClient .Get (context .TODO (), predictorDeploymentKey , deployed3 )
1571
+ return deployed3 .Spec .Template .Spec .Containers [0 ].Env
1572
+ }, timeout , interval ).Should (Not (ContainElements (defaultEnvs )))
1573
+
1574
+ Expect (deployed3 .Spec .Template .Spec .Containers [0 ].Env ).ToNot (ContainElement (HaveField ("Value" , "env_marked_for_deletion" )))
1575
+ Expect (deployed3 .Spec .Template .Spec .Containers [0 ].Env ).To (ContainElements (newEnvs ))
1576
+ })
1577
+ })
1578
+
1386
1579
Context ("When creating inference service with raw kube predictor and empty ingressClassName" , func () {
1387
1580
configs := map [string ]string {
1388
1581
"explainers" : `{
0 commit comments