@@ -677,6 +677,93 @@ func TestClusterExtensionInstallationSucceeds(t *testing.T) {
677677 require .NoError (t , cl .DeleteAllOf (ctx , & ocv1.ClusterExtension {}))
678678}
679679
680+ func TestClusterExtensionInstallationFailsWithNoServiceAccount (t * testing.T ) {
681+ cl , reconciler := newClientAndReconciler (t )
682+ reconciler .Unpacker = & MockUnpacker {
683+ result : & source.Result {
684+ State : source .StateUnpacked ,
685+ Bundle : fstest.MapFS {},
686+ },
687+ }
688+
689+ ctx := context .Background ()
690+ extKey := types.NamespacedName {Name : fmt .Sprintf ("cluster-extension-test-%s" , rand .String (8 ))}
691+
692+ t .Log ("When the cluster extension specifies a channel with version that exist" )
693+ t .Log ("By initializing cluster state" )
694+ pkgName := "prometheus"
695+ pkgVer := "1.0.0"
696+ pkgChan := "beta"
697+ namespace := fmt .Sprintf ("test-ns-%s" , rand .String (8 ))
698+ serviceAccount := fmt .Sprintf ("test-does-not-exist-%s" , rand .String (8 ))
699+
700+ clusterExtension := & ocv1.ClusterExtension {
701+ ObjectMeta : metav1.ObjectMeta {Name : extKey .Name },
702+ Spec : ocv1.ClusterExtensionSpec {
703+ Source : ocv1.SourceConfig {
704+ SourceType : "Catalog" ,
705+ Catalog : & ocv1.CatalogSource {
706+ PackageName : pkgName ,
707+ Version : pkgVer ,
708+ Channels : []string {pkgChan },
709+ },
710+ },
711+ Namespace : namespace ,
712+ ServiceAccount : ocv1.ServiceAccountReference {
713+ Name : serviceAccount ,
714+ },
715+ },
716+ }
717+ err := cl .Create (ctx , clusterExtension )
718+ require .NoError (t , err )
719+
720+ t .Log ("It sets resolution success status" )
721+ t .Log ("By running reconcile" )
722+ reconciler .Resolver = resolve .Func (func (_ context.Context , _ * ocv1.ClusterExtension , _ * ocv1.BundleMetadata ) (* declcfg.Bundle , * bsemver.Version , * declcfg.Deprecation , error ) {
723+ v := bsemver .MustParse ("1.0.0" )
724+ return & declcfg.Bundle {
725+ Name : "prometheus.v1.0.0" ,
726+ Package : "prometheus" ,
727+ Image :
"quay.io/operatorhubio/[email protected] " ,
728+ }, & v , nil , nil
729+ })
730+ reconciler .Applier = & MockApplier {
731+ objs : []client.Object {},
732+ }
733+ reconciler .Manager = & MockManagedContentCacheManager {
734+ cache : & MockManagedContentCache {},
735+ }
736+ res , err := reconciler .Reconcile (ctx , ctrl.Request {NamespacedName : extKey })
737+ require .Equal (t , ctrl.Result {}, res )
738+ require .NoError (t , err )
739+
740+ t .Log ("By fetching updated cluster extension after reconcile" )
741+ require .NoError (t , cl .Get (ctx , extKey , clusterExtension ))
742+
743+ t .Log ("By checking the status fields" )
744+ require .Equal (t , ocv1.BundleMetadata {Name : "prometheus.v1.0.0" , Version : "1.0.0" }, clusterExtension .Status .Install .Bundle )
745+
746+ t .Log ("By checking the expected installed conditions" )
747+ installedCond := apimeta .FindStatusCondition (clusterExtension .Status .Conditions , ocv1 .TypeInstalled )
748+ t .Log ("By checking the installed conditions message" , installedCond .Message )
749+ require .NotNil (t , installedCond )
750+ t .Log ("By checking the installed conditions status" , installedCond .Status )
751+ t .Log ("By checking the installed conditions reason" , installedCond .Reason )
752+ require .Equal (t , metav1 .ConditionTrue , installedCond .Status )
753+ require .Equal (t , ocv1 .ReasonSucceeded , installedCond .Reason )
754+
755+ t .Log ("By checking the expected progressing conditions" )
756+ progressingCond := apimeta .FindStatusCondition (clusterExtension .Status .Conditions , ocv1 .TypeProgressing )
757+ t .Log ("Progressing condition message" , progressingCond .Message )
758+ require .NotNil (t , progressingCond )
759+ t .Log ("Progressing condition status" , progressingCond .Status )
760+ t .Log ("Progressing condition reason" , progressingCond .Reason )
761+ //require.Equal(t, metav1.ConditionTrue, progressingCond.Status)
762+ require .Equal (t , ocv1 .ReasonFailed , progressingCond .Reason )
763+
764+ //require.NoError(t, cl.DeleteAllOf(ctx, &ocv1.ClusterExtension{}))
765+ }
766+
680767func TestClusterExtensionDeleteFinalizerFails (t * testing.T ) {
681768 cl , reconciler := newClientAndReconciler (t )
682769 reconciler .Unpacker = & MockUnpacker {
0 commit comments