@@ -647,15 +647,15 @@ func TestUpdateInstallPlan(t *testing.T) {
647
647
t .Run ("UpdateSingleExistingCRDOwner" , func (t * testing.T ) {
648
648
defer cleaner .NotifyTestComplete (t , true )
649
649
650
- mainPackageName := genName ("nginx-" )
650
+ mainPackageName := genName ("nginx-update- " )
651
651
652
652
mainPackageStable := fmt .Sprintf ("%s-stable" , mainPackageName )
653
653
654
654
stableChannel := "stable"
655
655
656
656
mainNamedStrategy := newNginxInstallStrategy (genName ("dep-" ), nil , nil )
657
657
658
- crdPlural := genName ("ins-" )
658
+ crdPlural := genName ("ins-update- " )
659
659
crdName := crdPlural + ".cluster.com"
660
660
mainCRD := apiextensions.CustomResourceDefinition {
661
661
ObjectMeta : metav1.ObjectMeta {
@@ -708,16 +708,6 @@ func TestUpdateInstallPlan(t *testing.T) {
708
708
},
709
709
}
710
710
711
- expectedCRDVersions := map [v1beta1.CustomResourceDefinitionVersion ]struct {}{}
712
- for _ , version := range updatedCRD .Spec .Versions {
713
- key := v1beta1.CustomResourceDefinitionVersion {
714
- Name : version .Name ,
715
- Served : version .Served ,
716
- Storage : version .Storage ,
717
- }
718
- expectedCRDVersions [key ] = struct {}{}
719
- }
720
-
721
711
mainCSV := newCSV (mainPackageStable , testNamespace , "" , semver .MustParse ("0.1.0" ), []apiextensions.CustomResourceDefinition {mainCRD }, nil , mainNamedStrategy )
722
712
723
713
c := newKubeClient (t )
@@ -726,7 +716,7 @@ func TestUpdateInstallPlan(t *testing.T) {
726
716
require .NoError (t , crc .OperatorsV1alpha1 ().Subscriptions (testNamespace ).DeleteCollection (& metav1.DeleteOptions {}, metav1.ListOptions {}))
727
717
}()
728
718
729
- mainCatalogName := genName ("mock-ocs-main-" )
719
+ mainCatalogName := genName ("mock-ocs-main-update- " )
730
720
731
721
// Create separate manifests for each CatalogSource
732
722
mainManifests := []registry.PackageManifest {
@@ -746,7 +736,7 @@ func TestUpdateInstallPlan(t *testing.T) {
746
736
_ , err := fetchCatalogSource (t , crc , mainCatalogName , testNamespace , catalogSourceRegistryPodSynced )
747
737
require .NoError (t , err )
748
738
749
- subscriptionName := genName ("sub-nginx-" )
739
+ subscriptionName := genName ("sub-nginx-update- " )
750
740
subscriptionCleanup := createSubscriptionForCatalog (t , crc , testNamespace , subscriptionName , mainCatalogName , mainPackageName , stableChannel , "" , v1alpha1 .ApprovalAutomatic )
751
741
defer subscriptionCleanup ()
752
742
@@ -775,47 +765,213 @@ func TestUpdateInstallPlan(t *testing.T) {
775
765
_ , err = awaitCSV (t , crc , testNamespace , mainCSV .GetName (), csvAnyChecker )
776
766
require .NoError (t , err )
777
767
778
- // Create new CSV to replace the one CSV
779
- updatedCSV := newCSV (mainPackageStable + "-v2" , testNamespace , mainPackageStable , semver .MustParse ("0.1.1" ), []apiextensions.CustomResourceDefinition {mainCRD }, nil , mainNamedStrategy )
768
+ updateInternalCatalog (t , c , crc , mainCatalogName , testNamespace , []apiextensions.CustomResourceDefinition {updatedCRD }, []v1alpha1.ClusterServiceVersion {mainCSV }, mainManifests )
769
+
770
+ // Update the subscription resource
771
+ err = crc .OperatorsV1alpha1 ().Subscriptions (testNamespace ).DeleteCollection (metav1 .NewDeleteOptions (0 ), metav1.ListOptions {})
772
+ require .NoError (t , err )
773
+
774
+ // existing cleanup should remove this
775
+ createSubscriptionForCatalog (t , crc , testNamespace , subscriptionName , mainCatalogName , mainPackageName , stableChannel , "" , v1alpha1 .ApprovalAutomatic )
776
+
777
+ // Wait for subscription to update
778
+ updatedSubscription , err := fetchSubscription (t , crc , testNamespace , subscriptionName , subscriptionHasInstallPlanChecker )
779
+ require .NoError (t , err )
780
+
781
+ // Verify installplan created and installed
782
+ fetchedUpdatedInstallPlan , err := fetchInstallPlan (t , crc , updatedSubscription .Status .InstallPlanRef .Name , buildInstallPlanPhaseCheckFunc (v1alpha1 .InstallPlanPhaseComplete ))
783
+ require .NoError (t , err )
784
+ require .NotEqual (t , fetchedInstallPlan .GetName (), fetchedUpdatedInstallPlan .GetName ())
785
+
786
+ // Wait for csv to update
787
+ _ , err = awaitCSV (t , crc , testNamespace , mainCSV .GetName (), csvAnyChecker )
788
+ require .NoError (t , err )
789
+
790
+ // Get the CRD to see if it is updated
791
+ fetchedCRD , err := c .ApiextensionsV1beta1Interface ().ApiextensionsV1beta1 ().CustomResourceDefinitions ().Get (crdName , metav1.GetOptions {})
792
+ require .NoError (t , err )
793
+ require .Equal (t , len (fetchedCRD .Spec .Versions ), len (updatedCRD .Spec .Versions ), "The CRD versions counts don't match" )
794
+
795
+ fetchedCRDVersions := map [v1beta1.CustomResourceDefinitionVersion ]struct {}{}
796
+ for _ , version := range fetchedCRD .Spec .Versions {
797
+ key := v1beta1.CustomResourceDefinitionVersion {
798
+ Name : version .Name ,
799
+ Served : version .Served ,
800
+ Storage : version .Storage ,
801
+ }
802
+ fetchedCRDVersions [key ] = struct {}{}
803
+ }
804
+
805
+ for _ , version := range updatedCRD .Spec .Versions {
806
+ key := v1beta1.CustomResourceDefinitionVersion {
807
+ Name : version .Name ,
808
+ Served : version .Served ,
809
+ Storage : version .Storage ,
810
+ }
811
+ _ , ok := fetchedCRDVersions [key ]
812
+ require .True (t , ok , "couldn't find %v in fetched CRD versions: %#v" , key , fetchedCRDVersions )
813
+ }
814
+ })
815
+
816
+ t .Run ("UpdatePreexistingCRDFailed" , func (t * testing.T ) {
817
+ defer cleaner .NotifyTestComplete (t , true )
818
+
819
+ c := newKubeClient (t )
820
+ crc := newCRClient (t )
821
+ defer func () {
822
+ require .NoError (t , crc .OperatorsV1alpha1 ().Subscriptions (testNamespace ).DeleteCollection (& metav1.DeleteOptions {}, metav1.ListOptions {}))
823
+ }()
824
+
825
+ mainPackageName := genName ("nginx-update2-" )
826
+
827
+ mainPackageStable := fmt .Sprintf ("%s-stable" , mainPackageName )
828
+
829
+ stableChannel := "stable"
830
+
831
+ mainNamedStrategy := newNginxInstallStrategy (genName ("dep-" ), nil , nil )
832
+
833
+ crdPlural := genName ("ins-update2-" )
834
+ crdName := crdPlural + ".cluster.com"
835
+ mainCRD := apiextensions.CustomResourceDefinition {
836
+ ObjectMeta : metav1.ObjectMeta {
837
+ Name : crdName ,
838
+ },
839
+ Spec : apiextensions.CustomResourceDefinitionSpec {
840
+ Group : "cluster.com" ,
841
+ Versions : []apiextensions.CustomResourceDefinitionVersion {
842
+ {
843
+ Name : "v1alpha1" ,
844
+ Served : true ,
845
+ Storage : true ,
846
+ },
847
+ },
848
+ Names : apiextensions.CustomResourceDefinitionNames {
849
+ Plural : crdPlural ,
850
+ Singular : crdPlural ,
851
+ Kind : crdPlural ,
852
+ ListKind : "list" + crdPlural ,
853
+ },
854
+ Scope : "Namespaced" ,
855
+ },
856
+ }
857
+
858
+ updatedCRD := apiextensions.CustomResourceDefinition {
859
+ ObjectMeta : metav1.ObjectMeta {
860
+ Name : crdName ,
861
+ },
862
+ Spec : apiextensions.CustomResourceDefinitionSpec {
863
+ Group : "cluster.com" ,
864
+ Versions : []apiextensions.CustomResourceDefinitionVersion {
865
+ {
866
+ Name : "v1alpha1" ,
867
+ Served : true ,
868
+ Storage : true ,
869
+ },
870
+ {
871
+ Name : "v1alpha2" ,
872
+ Served : true ,
873
+ Storage : false ,
874
+ },
875
+ },
876
+ Names : apiextensions.CustomResourceDefinitionNames {
877
+ Plural : crdPlural ,
878
+ Singular : crdPlural ,
879
+ Kind : crdPlural ,
880
+ ListKind : "list" + crdPlural ,
881
+ },
882
+ Scope : "Namespaced" ,
883
+ },
884
+ }
885
+
886
+ expectedCRDVersions := map [v1beta1.CustomResourceDefinitionVersion ]struct {}{}
887
+ for _ , version := range mainCRD .Spec .Versions {
888
+ key := v1beta1.CustomResourceDefinitionVersion {
889
+ Name : version .Name ,
890
+ Served : version .Served ,
891
+ Storage : version .Storage ,
892
+ }
893
+ expectedCRDVersions [key ] = struct {}{}
894
+ }
895
+
896
+ // Create the initial CSV
897
+ cleanupCRD , err := createCRD (c , mainCRD )
898
+ require .NoError (t , err )
899
+ defer cleanupCRD ()
900
+
901
+ mainCSV := newCSV (mainPackageStable , testNamespace , "" , semver .MustParse ("0.1.0" ), nil , nil , mainNamedStrategy )
902
+
903
+ mainCatalogName := genName ("mock-ocs-main-update2-" )
780
904
781
- // Update manifest
782
- updatedManifests := []registry.PackageManifest {
905
+ // Create separate manifests for each CatalogSource
906
+ mainManifests := []registry.PackageManifest {
783
907
{
784
908
PackageName : mainPackageName ,
785
909
Channels : []registry.PackageChannel {
786
- {Name : stableChannel , CurrentCSVName : updatedCSV . GetName () },
910
+ {Name : stableChannel , CurrentCSVName : mainPackageStable },
787
911
},
788
912
DefaultChannelName : stableChannel ,
789
913
},
790
914
}
791
915
792
- updateInternalCatalog (t , c , crc , mainCatalogName , testNamespace , []apiextensions.CustomResourceDefinition {updatedCRD }, []v1alpha1.ClusterServiceVersion {mainCSV , updatedCSV }, updatedManifests )
916
+ // Create the catalog sources
917
+ _ , cleanupMainCatalogSource := createInternalCatalogSource (t , c , crc , mainCatalogName , testNamespace , mainManifests , []apiextensions.CustomResourceDefinition {updatedCRD }, []v1alpha1.ClusterServiceVersion {mainCSV })
918
+ defer cleanupMainCatalogSource ()
919
+ // Attempt to get the catalog source before creating install plan
920
+ _ , err = fetchCatalogSource (t , crc , mainCatalogName , testNamespace , catalogSourceRegistryPodSynced )
921
+ require .NoError (t , err )
793
922
794
- // Wait for subscription to update
795
- updatedSubscription , err := fetchSubscription (t , crc , testNamespace , subscriptionName , subscriptionHasCurrentCSV (updatedCSV .GetName ()))
923
+ subscriptionName := genName ("sub-nginx-update2-" )
924
+ subscriptionCleanup := createSubscriptionForCatalog (t , crc , testNamespace , subscriptionName , mainCatalogName , mainPackageName , stableChannel , "" , v1alpha1 .ApprovalAutomatic )
925
+ defer subscriptionCleanup ()
926
+
927
+ subscription , err := fetchSubscription (t , crc , testNamespace , subscriptionName , subscriptionHasInstallPlanChecker )
796
928
require .NoError (t , err )
929
+ require .NotNil (t , subscription )
930
+ require .NotNil (t , subscription .Status .InstallPlanRef )
931
+ require .Equal (t , mainCSV .GetName (), subscription .Status .CurrentCSV )
797
932
798
- // Verify installplan created and installed
799
- fetchedUpdatedInstallPlan , err := fetchInstallPlan (t , crc , updatedSubscription .Status .InstallPlanRef .Name , buildInstallPlanPhaseCheckFunc (v1alpha1 .InstallPlanPhaseComplete ))
933
+ installPlanName := subscription .Status .InstallPlanRef .Name
934
+
935
+ // Wait for InstallPlan to be status: Complete before checking resource presence
936
+ fetchedInstallPlan , err := fetchInstallPlan (t , crc , installPlanName , buildInstallPlanPhaseCheckFunc (v1alpha1 .InstallPlanPhaseComplete ))
800
937
require .NoError (t , err )
801
- require .NotEqual (t , fetchedInstallPlan .GetName (), fetchedUpdatedInstallPlan .GetName ())
802
938
803
- // Wait for csv to update
804
- _ , err = awaitCSV (t , crc , testNamespace , updatedCSV .GetName (), csvAnyChecker )
939
+ require .Equal (t , v1alpha1 .InstallPlanPhaseComplete , fetchedInstallPlan .Status .Phase )
940
+
941
+ // Fetch installplan again to check for unnecessary control loops
942
+ fetchedInstallPlan , err = fetchInstallPlan (t , crc , fetchedInstallPlan .GetName (), func (fip * v1alpha1.InstallPlan ) bool {
943
+ compareResources (t , fetchedInstallPlan , fip )
944
+ return true
945
+ })
946
+ require .NoError (t , err )
947
+
948
+ // Verify CSV is created
949
+ _ , err = awaitCSV (t , crc , testNamespace , mainCSV .GetName (), csvAnyChecker )
805
950
require .NoError (t , err )
806
951
807
952
// Get the CRD to see if it is updated
808
953
fetchedCRD , err := c .ApiextensionsV1beta1Interface ().ApiextensionsV1beta1 ().CustomResourceDefinitions ().Get (crdName , metav1.GetOptions {})
809
954
require .NoError (t , err )
955
+ require .Equal (t , len (fetchedCRD .Spec .Versions ), len (mainCRD .Spec .Versions ), "The CRD versions counts don't match" )
810
956
957
+ fetchedCRDVersions := map [v1beta1.CustomResourceDefinitionVersion ]struct {}{}
811
958
for _ , version := range fetchedCRD .Spec .Versions {
812
959
key := v1beta1.CustomResourceDefinitionVersion {
813
960
Name : version .Name ,
814
961
Served : version .Served ,
815
962
Storage : version .Storage ,
816
963
}
817
- _ , ok := expectedCRDVersions [key ]
818
- require .True (t , ok , "couldn't find %v in expected CRD versions: %#v" , key , expectedCRDVersions )
964
+ fetchedCRDVersions [key ] = struct {}{}
965
+ }
966
+
967
+ for _ , version := range mainCRD .Spec .Versions {
968
+ key := v1beta1.CustomResourceDefinitionVersion {
969
+ Name : version .Name ,
970
+ Served : version .Served ,
971
+ Storage : version .Storage ,
972
+ }
973
+ _ , ok := fetchedCRDVersions [key ]
974
+ require .True (t , ok , "couldn't find %v in fetched CRD versions: %#v" , key , fetchedCRDVersions )
819
975
}
820
976
})
821
977
}
0 commit comments