@@ -39,6 +39,7 @@ import (
39
39
"github.com/openshift/assisted-installer/src/k8s_client"
40
40
"github.com/openshift/assisted-installer/src/ops"
41
41
"github.com/openshift/assisted-service/models"
42
+ yaml "gopkg.in/yaml.v3"
42
43
)
43
44
44
45
func TestValidator (t * testing.T ) {
@@ -106,6 +107,15 @@ var (
106
107
testIngressConfigMap = map [string ]string {
107
108
"ca-bundle.crt" : "CA" ,
108
109
}
110
+
111
+ testOperatorManifests = map [string ]string {
112
+ "kube-descheduler" : "LS0tCmFwaVZlcnNpb246IG9wZXJhdG9yLm9wZW5zaGlmdC5pby92MQpraW5kOiBLdWJlRGVzY2hlZHVsZXIKbWV0YWRhdGE6CiAgbmFtZTogY2x1c3RlcgogIG5hbWVzcGFjZTogb3BlbnNoaWZ0LWt1YmUtZGVzY2hlZHVsZXItb3BlcmF0b3IKc3BlYzoKICBsb2dMZXZlbDogTm9ybWFsCiAgbW9kZTogUHJlZGljdGl2ZQogIG9wZXJhdG9yTG9nTGV2ZWw6IE5vcm1hbAogIHByb2ZpbGVzOgogICAgLSBBZmZpbml0eUFuZFRhaW50cwogIGRlc2NoZWR1bGluZ0ludGVydmFsU2Vjb25kczogMzYwMAogIG1hbmFnZW1lbnRTdGF0ZTogTWFuYWdlZAo=" ,
113
+ "nmstate" : "CmFwaVZlcnNpb246IG5tc3RhdGUuaW8vdjEKa2luZDogTk1TdGF0ZQptZXRhZGF0YToKICBuYW1lOiBubXN0YXRlCg==" ,
114
+ }
115
+
116
+ testMonitoredOperators = []models.MonitoredOperator {
117
+ {Name : "kube-descheduler" , Namespace : "openshift-kube-descheduler-operator" , OperatorType : "olm" , SubscriptionName : "cluster-kube-descheduler-operator" },
118
+ {Name : "nmstate" , Namespace : "openshift-nmstate" , OperatorType : "olm" , SubscriptionName : "kubernetes-nmstate-operator" }}
109
119
)
110
120
111
121
var _ = Describe ("installer HostRoleMaster role" , func () {
@@ -494,8 +504,7 @@ var _ = Describe("installer HostRoleMaster role", func() {
494
504
mockk8sclient .EXPECT ().ListNodes ().Return (nodes , nil ).Times (1 )
495
505
updateProgressSuccess (done , hosts )
496
506
configuringSuccess ()
497
- for name , v := range inventoryNamesIds {
498
- value := v
507
+ for name , value := range inventoryNamesIds {
499
508
mockRebootsNotifier .EXPECT ().Start (gomock .Any (), name , value .Host .ID , & value .Host .InfraEnvID , gomock .Any ()).Times (1 )
500
509
}
501
510
exit := assistedController .waitAndUpdateNodesStatus (false )
@@ -1436,6 +1445,58 @@ var _ = Describe("installer HostRoleMaster role", func() {
1436
1445
})
1437
1446
})
1438
1447
1448
+ Context ("PostInstallConfigsK8sClient" , func () {
1449
+ Context ("operator manifests" , func () {
1450
+ BeforeEach (func () {
1451
+ GeneralWaitInterval = 1 * time .Millisecond
1452
+ })
1453
+
1454
+ It ("success" , func () {
1455
+ mockAllCapabilitiesEnabled ()
1456
+
1457
+ operatorConfigMap := createConfigMap ()
1458
+
1459
+ mockk8sclient .EXPECT ().GetConfigMap ("assisted-installer" , "olm-operator-manifests" ).Return (operatorConfigMap , nil ).Times (1 )
1460
+ mockk8sclient .EXPECT ().ListJobs (gomock .Any ()).Return (& batchV1.JobList {}, nil ).AnyTimes ()
1461
+ mockk8sclient .EXPECT ().GetAllInstallPlansOfSubscription (gomock .Any ()).Return ([]olmv1alpha1.InstallPlan {}, nil ).Times (2 )
1462
+ mockRebootsNotifier .EXPECT ().GetKubeconfigPath (gomock .Any ()).Return ("" , nil ).Times (1 )
1463
+ randomCSV := uuid .New ().String ()
1464
+ mockk8sclient .EXPECT ().GetCSVFromSubscription ("openshift-kube-descheduler-operator" , "cluster-kube-descheduler-operator" ).Return (randomCSV , nil ).Times (1 )
1465
+ mockk8sclient .EXPECT ().GetCSV ("openshift-kube-descheduler-operator" , gomock .Any ()).Return (& olmv1alpha1.ClusterServiceVersion {Status : olmv1alpha1.ClusterServiceVersionStatus {Phase : olmv1alpha1 .CSVPhaseNone }}, nil ).Times (1 )
1466
+ mockk8sclient .EXPECT ().GetCSVFromSubscription ("openshift-nmstate" , "kubernetes-nmstate-operator" ).Return (randomCSV , nil ).Times (1 )
1467
+ mockk8sclient .EXPECT ().GetCSV ("openshift-nmstate" , gomock .Any ()).Return (& olmv1alpha1.ClusterServiceVersion {Status : olmv1alpha1.ClusterServiceVersionStatus {Phase : olmv1alpha1 .CSVPhaseNone }}, nil ).Times (1 )
1468
+ mockops .EXPECT ().CreateManifests (gomock .Any (), gomock .Any ()).Times (2 )
1469
+
1470
+ wg .Add (1 )
1471
+ assistedController .PostInstallConfigsK8sClient (context .TODO (), & wg , "" )
1472
+ wg .Wait ()
1473
+ })
1474
+
1475
+ It ("failure on CSVs" , func () {
1476
+ GeneralProgressUpdateInt = 1 * time .Millisecond
1477
+ mockAllCapabilitiesEnabled ()
1478
+
1479
+ operatorConfigMap := createConfigMap ()
1480
+
1481
+ mockk8sclient .EXPECT ().GetConfigMap ("assisted-installer" , "olm-operator-manifests" ).Return (operatorConfigMap , nil ).AnyTimes ()
1482
+ mockk8sclient .EXPECT ().ListJobs (gomock .Any ()).Return (& batchV1.JobList {}, nil ).AnyTimes ()
1483
+ mockk8sclient .EXPECT ().GetAllInstallPlansOfSubscription (gomock .Any ()).Return ([]olmv1alpha1.InstallPlan {}, nil ).AnyTimes ()
1484
+ mockRebootsNotifier .EXPECT ().GetKubeconfigPath (gomock .Any ()).Return ("" , nil ).AnyTimes ()
1485
+ mockk8sclient .EXPECT ().GetCSVFromSubscription ("openshift-kube-descheduler-operator" , "cluster-kube-descheduler-operator" ).Return ("" , fmt .Errorf ("dummy" )).AnyTimes ()
1486
+ mockk8sclient .EXPECT ().GetCSVFromSubscription ("openshift-nmstate" , "kubernetes-nmstate-operator" ).Return ("" , fmt .Errorf ("dummy" )).AnyTimes ()
1487
+
1488
+ wg .Add (1 )
1489
+ go func () {
1490
+ defer GinkgoRecover ()
1491
+ ctx , cancel := context .WithTimeout (context .TODO (), 10 * time .Millisecond )
1492
+ defer cancel ()
1493
+ assistedController .PostInstallConfigsK8sClient (ctx , & wg , "" )
1494
+ }()
1495
+ wg .Wait ()
1496
+ })
1497
+ })
1498
+ })
1499
+
1439
1500
Context ("update BMHs" , func () {
1440
1501
t := metav1 .Unix (98754 , 0 )
1441
1502
bmhStatus := metal3v1alpha1.BareMetalHostStatus {
@@ -2252,3 +2313,45 @@ func create3Hosts(currentStatus string, stage models.HostStage, nodeLabels strin
2252
2313
"node1" : {Host : & models.Host {InfraEnvID : infraEnvId , ID : & node1Id , NodeLabels : nodeLabels , Progress : & currentState , Status : & currentStatus }},
2253
2314
"node2" : {Host : & models.Host {InfraEnvID : infraEnvId , ID : & node2Id , NodeLabels : nodeLabels , Progress : & currentState , Status : & currentStatus }}}
2254
2315
}
2316
+
2317
+ func createConfigMap () * v1.ConfigMap {
2318
+ type operatorMetadata struct {
2319
+ Namespace string `yaml:"namespace"`
2320
+ SubscriptionName string `yaml:"subscriptionName"`
2321
+ Manifests []string `yaml:"manifests"`
2322
+ }
2323
+
2324
+ configMap := v1.ConfigMap {
2325
+ TypeMeta : metav1.TypeMeta {
2326
+ APIVersion : "v1" ,
2327
+ Kind : "ConfigMap" ,
2328
+ },
2329
+ ObjectMeta : metav1.ObjectMeta {
2330
+ Name : "olm-operator-manifests" ,
2331
+ Namespace : "assisted-installer" ,
2332
+ },
2333
+ Data : map [string ]string {},
2334
+ }
2335
+
2336
+ for _ , operator := range testMonitoredOperators {
2337
+ var manifestFileNames []string
2338
+ manifestContent , _ := testOperatorManifests [operator .Name ]
2339
+
2340
+ fileName := fmt .Sprintf ("%s-1.yaml" , operator .Name )
2341
+ configMap .Data [fileName ] = manifestContent
2342
+ manifestFileNames = append (manifestFileNames , fileName )
2343
+
2344
+ metadata := operatorMetadata {
2345
+ Namespace : operator .Namespace ,
2346
+ SubscriptionName : operator .SubscriptionName ,
2347
+ Manifests : manifestFileNames ,
2348
+ }
2349
+
2350
+ metadataYAML , _ := yaml .Marshal (metadata )
2351
+
2352
+ metadataKey := fmt .Sprintf ("%s.metadata.yaml" , operator .Name )
2353
+ configMap .Data [metadataKey ] = string (metadataYAML )
2354
+ }
2355
+
2356
+ return & configMap
2357
+ }
0 commit comments