@@ -714,3 +714,97 @@ func TestCreateInstallPlanWithPermissions(t *testing.T) {
714
714
require .Equal (t , 0 , len (expectedSteps ), "Actual resource steps do not match expected" )
715
715
716
716
}
717
+
718
+ func TestInstallPlanCRDValidation (t * testing.T ) {
719
+ // Tests if CRD validation works with the "minimum" property after being
720
+ // pulled from a CatalogSource's operator-registry.
721
+ defer cleaner .NotifyTestComplete (t , true )
722
+
723
+ crdPlural := genName ("ins" )
724
+ crdName := crdPlural + ".cluster.com"
725
+ var min float64 = 2
726
+ var max float64 = 256
727
+
728
+ // Create CRD with offending property
729
+ crd := apiextensions.CustomResourceDefinition {
730
+ ObjectMeta : metav1.ObjectMeta {
731
+ Name : crdName ,
732
+ },
733
+ Spec : apiextensions.CustomResourceDefinitionSpec {
734
+ Group : "cluster.com" ,
735
+ Version : "v1alpha1" ,
736
+ Names : apiextensions.CustomResourceDefinitionNames {
737
+ Plural : crdPlural ,
738
+ Singular : crdPlural ,
739
+ Kind : crdPlural ,
740
+ ListKind : "list" + crdPlural ,
741
+ },
742
+ Scope : "Namespaced" ,
743
+ Validation : & apiextensions.CustomResourceValidation {
744
+ OpenAPIV3Schema : & apiextensions.JSONSchemaProps {
745
+ Properties : map [string ]apiextensions.JSONSchemaProps {
746
+ "spec" : {
747
+ Type : "object" ,
748
+ Description : "Spec of a test object." ,
749
+ Properties : map [string ]apiextensions.JSONSchemaProps {
750
+ "scalar" : {
751
+ Type : "number" ,
752
+ Description : "Scalar value that should have a min and max." ,
753
+ Minimum : & min ,
754
+ Maximum : & max ,
755
+ },
756
+ },
757
+ },
758
+ },
759
+ },
760
+ },
761
+ },
762
+ }
763
+
764
+ // Create CSV
765
+ packageName := genName ("nginx-" )
766
+ stableChannel := "stable"
767
+ packageNameStable := packageName + "-" + stableChannel
768
+ namedStrategy := newNginxInstallStrategy (genName ("dep-" ), nil , nil )
769
+ csv := newCSV (packageNameStable , testNamespace , "" , * semver .New ("0.1.0" ), []apiextensions.CustomResourceDefinition {crd }, nil , namedStrategy )
770
+
771
+ // Create PackageManifests
772
+ manifests := []registry.PackageManifest {
773
+ {
774
+ PackageName : packageName ,
775
+ Channels : []registry.PackageChannel {
776
+ {Name : stableChannel , CurrentCSVName : packageNameStable },
777
+ },
778
+ DefaultChannelName : stableChannel ,
779
+ },
780
+ }
781
+
782
+ // Create the CatalogSource
783
+ c := newKubeClient (t )
784
+ crc := newCRClient (t )
785
+ catalogSourceName := genName ("mock-nginx-" )
786
+ _ , cleanupCatalogSource := createInternalCatalogSource (t , c , crc , catalogSourceName , testNamespace , manifests , []apiextensions.CustomResourceDefinition {crd }, []v1alpha1.ClusterServiceVersion {csv })
787
+ defer cleanupCatalogSource ()
788
+
789
+ // Attempt to get the catalog source before creating install plan
790
+ _ , err := fetchCatalogSource (t , crc , catalogSourceName , testNamespace , catalogSourceRegistryPodSynced )
791
+ require .NoError (t , err )
792
+
793
+ subscriptionName := genName ("sub-nginx-" )
794
+ cleanupSubscription := createSubscriptionForCatalog (t , crc , testNamespace , subscriptionName , catalogSourceName , packageName , stableChannel , v1alpha1 .ApprovalAutomatic )
795
+ defer cleanupSubscription ()
796
+
797
+ subscription , err := fetchSubscription (t , crc , testNamespace , subscriptionName , subscriptionHasInstallPlanChecker )
798
+ require .NoError (t , err )
799
+ require .NotNil (t , subscription )
800
+
801
+ installPlanName := subscription .Status .Install .Name
802
+
803
+ // Wait for InstallPlan to be status: Complete before checking resource presence
804
+ fetchedInstallPlan , err := fetchInstallPlan (t , crc , installPlanName , buildInstallPlanPhaseCheckFunc (v1alpha1 .InstallPlanPhaseComplete , v1alpha1 .InstallPlanPhaseFailed ))
805
+ require .NoError (t , err )
806
+ t .Logf ("Install plan %s fetched with status %s" , fetchedInstallPlan .GetName (), fetchedInstallPlan .Status .Phase )
807
+
808
+ require .Equal (t , v1alpha1 .InstallPlanPhaseComplete , fetchedInstallPlan .Status .Phase )
809
+
810
+ }
0 commit comments