@@ -52,6 +52,11 @@ var _ = Describe("Operator Controller Test", func() {
52
52
BeforeEach (func () {
53
53
opKey = types.NamespacedName {Name : fmt .Sprintf ("operator-test-%s" , rand .String (8 ))}
54
54
})
55
+ AfterEach (func () {
56
+ verifyInvariants (ctx , reconciler .Client , operator )
57
+ Expect (cl .DeleteAllOf (ctx , & operatorsv1alpha1.Operator {})).To (Succeed ())
58
+ Expect (cl .DeleteAllOf (ctx , & rukpakv1alpha1.BundleDeployment {})).To (Succeed ())
59
+ })
55
60
When ("the operator specifies a non-existent package" , func () {
56
61
var pkgName string
57
62
BeforeEach (func () {
@@ -137,7 +142,6 @@ var _ = Describe("Operator Controller Test", func() {
137
142
err := cl .Create (ctx , operator )
138
143
Expect (err ).NotTo (HaveOccurred ())
139
144
})
140
-
141
145
When ("the BundleDeployment does not exist" , func () {
142
146
BeforeEach (func () {
143
147
By ("running reconcile" )
@@ -210,16 +214,16 @@ var _ = Describe("Operator Controller Test", func() {
210
214
},
211
215
},
212
216
}
213
-
214
217
})
215
218
216
219
When ("the BundleDeployment spec is out of date" , func () {
217
- It ( "results in the expected BundleDeployment" , func () {
220
+ BeforeEach ( func () {
218
221
By ("modifying the BD spec and creating the object" )
219
222
bd .Spec .ProvisionerClassName = "core-rukpak-io-helm"
220
223
err := cl .Create (ctx , bd )
221
224
Expect (err ).NotTo (HaveOccurred ())
222
-
225
+ })
226
+ It ("results in the expected BundleDeployment" , func () {
223
227
By ("running reconcile" )
224
228
res , err := reconciler .Reconcile (ctx , ctrl.Request {NamespacedName : opKey })
225
229
Expect (res ).To (Equal (ctrl.Result {}))
@@ -508,17 +512,12 @@ var _ = Describe("Operator Controller Test", func() {
508
512
})
509
513
510
514
})
511
-
512
- AfterEach (func () {
513
- err := cl .Delete (ctx , bd )
514
- Expect (err ).NotTo (HaveOccurred ())
515
- })
516
-
517
515
})
518
516
When ("an out-of-date BundleDeployment exists" , func () {
517
+ var bd * rukpakv1alpha1.BundleDeployment
519
518
BeforeEach (func () {
520
519
By ("creating the expected BD" )
521
- err := cl . Create ( ctx , & rukpakv1alpha1.BundleDeployment {
520
+ bd = & rukpakv1alpha1.BundleDeployment {
522
521
ObjectMeta : metav1.ObjectMeta {Name : opKey .Name },
523
522
Spec : rukpakv1alpha1.BundleDeploymentSpec {
524
523
ProvisionerClassName : "foo" ,
@@ -534,7 +533,8 @@ var _ = Describe("Operator Controller Test", func() {
534
533
},
535
534
},
536
535
},
537
- })
536
+ }
537
+ err := cl .Create (ctx , bd )
538
538
Expect (err ).NotTo (HaveOccurred ())
539
539
540
540
By ("running reconcile" )
@@ -633,12 +633,6 @@ var _ = Describe("Operator Controller Test", func() {
633
633
err = cl .Create (ctx , operator )
634
634
Expect (err ).NotTo (HaveOccurred ())
635
635
})
636
-
637
- AfterEach (func () {
638
- err := cl .Delete (ctx , dupOperator )
639
- Expect (err ).NotTo (HaveOccurred ())
640
- })
641
-
642
636
It ("sets resolution failure status" , func () {
643
637
By ("running reconcile" )
644
638
res , err := reconciler .Reconcile (ctx , ctrl.Request {NamespacedName : opKey })
@@ -665,51 +659,6 @@ var _ = Describe("Operator Controller Test", func() {
665
659
Expect (cond .Message ).To (Equal ("installation has not been attempted as resolution failed" ))
666
660
})
667
661
})
668
- When ("the existing operator status is based on bundleDeployment" , func () {
669
- const pkgName = "prometheus"
670
- var (
671
- bd * rukpakv1alpha1.BundleDeployment
672
- )
673
- BeforeEach (func () {
674
- By ("creating the expected BundleDeployment" )
675
- bd = & rukpakv1alpha1.BundleDeployment {
676
- ObjectMeta : metav1.ObjectMeta {Name : opKey .Name },
677
- Spec : rukpakv1alpha1.BundleDeploymentSpec {
678
- ProvisionerClassName : "core-rukpak-io-plain" ,
679
- Template : & rukpakv1alpha1.BundleTemplate {
680
- Spec : rukpakv1alpha1.BundleSpec {
681
- ProvisionerClassName : "core-rukpak-io-registry" ,
682
- Source : rukpakv1alpha1.BundleSource {
683
- Type : rukpakv1alpha1 .SourceTypeImage ,
684
- Image : & rukpakv1alpha1.ImageSource {
685
- Ref : "quay.io/operatorhubio/prometheus@sha256:5b04c49d8d3eff6a338b56ec90bdf491d501fe301c9cdfb740e5bff6769a21ed" ,
686
- },
687
- },
688
- },
689
- },
690
- },
691
- }
692
- err := cl .Create (ctx , bd )
693
- Expect (err ).NotTo (HaveOccurred ())
694
-
695
- By ("creating the operator object" )
696
- operator = & operatorsv1alpha1.Operator {
697
- ObjectMeta : metav1.ObjectMeta {Name : opKey .Name },
698
- Spec : operatorsv1alpha1.OperatorSpec {
699
- PackageName : pkgName ,
700
- },
701
- }
702
- err = cl .Create (ctx , operator )
703
- Expect (err ).NotTo (HaveOccurred ())
704
-
705
- })
706
-
707
- AfterEach (func () {
708
- err := cl .Delete (ctx , bd )
709
- Expect (err ).NotTo (HaveOccurred ())
710
- })
711
-
712
- })
713
662
When ("the operator specifies a channel with version that exist" , func () {
714
663
var pkgName string
715
664
var pkgVer string
@@ -954,75 +903,64 @@ var _ = Describe("Operator Controller Test", func() {
954
903
Expect (cond .Message ).To (Equal ("installation has not been attempted as resolution failed" ))
955
904
})
956
905
})
957
- AfterEach (func () {
958
- verifyInvariants (ctx , operator )
906
+ When ("an invalid semver is provided that bypasses the regex validation" , func () {
907
+ var (
908
+ pkgName string
909
+ fakeClient client.Client
910
+ )
911
+ BeforeEach (func () {
912
+ opKey = types.NamespacedName {Name : fmt .Sprintf ("operator-validation-test-%s" , rand .String (8 ))}
959
913
960
- err := cl .Delete (ctx , operator )
961
- Expect (err ).To (Not (HaveOccurred ()))
962
- })
963
- })
964
- When ("an invalid semver is provided that bypasses the regex validation" , func () {
965
- var (
966
- operator * operatorsv1alpha1.Operator
967
- opKey types.NamespacedName
968
- pkgName string
969
- fakeClient client.Client
970
- )
971
- BeforeEach (func () {
972
- opKey = types.NamespacedName {Name : fmt .Sprintf ("operator-validation-test-%s" , rand .String (8 ))}
973
-
974
- By ("injecting creating a client with the bad operator CR" )
975
- pkgName = fmt .Sprintf ("exists-%s" , rand .String (6 ))
976
- operator = & operatorsv1alpha1.Operator {
977
- ObjectMeta : metav1.ObjectMeta {Name : opKey .Name },
978
- Spec : operatorsv1alpha1.OperatorSpec {
979
- PackageName : pkgName ,
980
- Version : "1.2.3-123abc_def" , // bad semver that matches the regex on the CR validation
981
- },
982
- }
983
-
984
- // this bypasses client/server-side CR validation and allows us to test the reconciler's validation
985
- fakeClient = fake .NewClientBuilder ().WithScheme (sch ).WithObjects (operator ).Build ()
986
-
987
- By ("changing the reconciler client to the fake client" )
988
- reconciler .Client = fakeClient
989
- })
990
- AfterEach (func () {
991
- By ("changing the reconciler client back to the real client" )
992
- reconciler .Client = cl
993
- })
914
+ By ("injecting creating a client with the bad operator CR" )
915
+ pkgName = fmt .Sprintf ("exists-%s" , rand .String (6 ))
916
+ operator = & operatorsv1alpha1.Operator {
917
+ ObjectMeta : metav1.ObjectMeta {Name : opKey .Name },
918
+ Spec : operatorsv1alpha1.OperatorSpec {
919
+ PackageName : pkgName ,
920
+ Version : "1.2.3-123abc_def" , // bad semver that matches the regex on the CR validation
921
+ },
922
+ }
994
923
995
- It ("should add an invalid spec condition and *not* re-enqueue for reconciliation" , func () {
996
- By ("running reconcile" )
997
- res , err := reconciler .Reconcile (ctx , ctrl.Request {NamespacedName : opKey })
998
- Expect (res ).To (Equal (ctrl.Result {}))
999
- Expect (err ).ToNot (HaveOccurred ())
1000
-
1001
- By ("fetching updated operator after reconcile" )
1002
- Expect (fakeClient .Get (ctx , opKey , operator )).NotTo (HaveOccurred ())
1003
-
1004
- By ("Checking the status fields" )
1005
- Expect (operator .Status .ResolvedBundleResource ).To (Equal ("" ))
1006
- Expect (operator .Status .InstalledBundleResource ).To (Equal ("" ))
1007
-
1008
- By ("checking the expected conditions" )
1009
- cond := apimeta .FindStatusCondition (operator .Status .Conditions , operatorsv1alpha1 .TypeResolved )
1010
- Expect (cond ).NotTo (BeNil ())
1011
- Expect (cond .Status ).To (Equal (metav1 .ConditionUnknown ))
1012
- Expect (cond .Reason ).To (Equal (operatorsv1alpha1 .ReasonResolutionUnknown ))
1013
- Expect (cond .Message ).To (Equal ("validation has not been attempted as spec is invalid" ))
1014
- cond = apimeta .FindStatusCondition (operator .Status .Conditions , operatorsv1alpha1 .TypeInstalled )
1015
- Expect (cond ).NotTo (BeNil ())
1016
- Expect (cond .Status ).To (Equal (metav1 .ConditionUnknown ))
1017
- Expect (cond .Reason ).To (Equal (operatorsv1alpha1 .ReasonInstallationStatusUnknown ))
1018
- Expect (cond .Message ).To (Equal ("installation has not been attempted as spec is invalid" ))
924
+ // this bypasses client/server-side CR validation and allows us to test the reconciler's validation
925
+ fakeClient = fake .NewClientBuilder ().WithScheme (sch ).WithObjects (operator ).Build ()
926
+
927
+ By ("changing the reconciler client to the fake client" )
928
+ reconciler .Client = fakeClient
929
+ })
930
+
931
+ It ("should add an invalid spec condition and *not* re-enqueue for reconciliation" , func () {
932
+ By ("running reconcile" )
933
+ res , err := reconciler .Reconcile (ctx , ctrl.Request {NamespacedName : opKey })
934
+ Expect (res ).To (Equal (ctrl.Result {}))
935
+ Expect (err ).ToNot (HaveOccurred ())
936
+
937
+ By ("fetching updated operator after reconcile" )
938
+ Expect (fakeClient .Get (ctx , opKey , operator )).NotTo (HaveOccurred ())
939
+
940
+ By ("Checking the status fields" )
941
+ Expect (operator .Status .ResolvedBundleResource ).To (Equal ("" ))
942
+ Expect (operator .Status .InstalledBundleResource ).To (Equal ("" ))
943
+
944
+ By ("checking the expected conditions" )
945
+ cond := apimeta .FindStatusCondition (operator .Status .Conditions , operatorsv1alpha1 .TypeResolved )
946
+ Expect (cond ).NotTo (BeNil ())
947
+ Expect (cond .Status ).To (Equal (metav1 .ConditionUnknown ))
948
+ Expect (cond .Reason ).To (Equal (operatorsv1alpha1 .ReasonResolutionUnknown ))
949
+ Expect (cond .Message ).To (Equal ("validation has not been attempted as spec is invalid" ))
950
+ cond = apimeta .FindStatusCondition (operator .Status .Conditions , operatorsv1alpha1 .TypeInstalled )
951
+ Expect (cond ).NotTo (BeNil ())
952
+ Expect (cond .Status ).To (Equal (metav1 .ConditionUnknown ))
953
+ Expect (cond .Reason ).To (Equal (operatorsv1alpha1 .ReasonInstallationStatusUnknown ))
954
+ Expect (cond .Message ).To (Equal ("installation has not been attempted as spec is invalid" ))
955
+ })
1019
956
})
957
+
1020
958
})
1021
959
})
1022
960
1023
- func verifyInvariants (ctx context.Context , op * operatorsv1alpha1.Operator ) {
961
+ func verifyInvariants (ctx context.Context , c client. Client , op * operatorsv1alpha1.Operator ) {
1024
962
key := client .ObjectKeyFromObject (op )
1025
- err := cl .Get (ctx , key , op )
963
+ err := c .Get (ctx , key , op )
1026
964
Expect (err ).To (BeNil ())
1027
965
1028
966
verifyConditionsInvariants (op )
0 commit comments