@@ -2,7 +2,6 @@ package catalog
22
33import (
44 "context"
5- "crypto/sha256"
65 "encoding/json"
76 "errors"
87 "fmt"
@@ -48,6 +47,7 @@ import (
4847 "k8s.io/client-go/tools/clientcmd"
4948 "k8s.io/client-go/tools/pager"
5049 "k8s.io/client-go/tools/record"
50+ "k8s.io/client-go/util/retry"
5151 "k8s.io/client-go/util/workqueue"
5252 utilclock "k8s.io/utils/clock"
5353
@@ -1342,9 +1342,6 @@ func (o *Operator) syncResolvingNamespace(obj interface{}) error {
13421342 return err
13431343 }
13441344
1345- // Remove resolutionfailed condition from subscriptions
1346- o .removeSubsCond (subs , v1alpha1 .SubscriptionResolutionFailed )
1347-
13481345 // Attempt to unpack bundles before installing
13491346 // Note: This should probably use the attenuated client to prevent users from resolving resources they otherwise don't have access to.
13501347 if len (bundleLookups ) > 0 {
@@ -1472,6 +1469,9 @@ func (o *Operator) syncResolvingNamespace(obj interface{}) error {
14721469 // Remove BundleUnpackFailed condition from subscriptions
14731470 o .removeSubsCond (subs , v1alpha1 .SubscriptionBundleUnpackFailed )
14741471
1472+ // Remove resolutionfailed condition from subscriptions
1473+ o .removeSubsCond (subs , v1alpha1 .SubscriptionResolutionFailed )
1474+
14751475 newSub := true
14761476 for _ , updatedSub := range updatedSubs {
14771477 updatedSub .Status .RemoveConditions (v1alpha1 .SubscriptionResolutionFailed )
@@ -1660,20 +1660,7 @@ func (o *Operator) createInstallPlan(namespace string, gen int, subs []*v1alpha1
16601660 return nil , nil
16611661 }
16621662
1663- sha , err := func () (string , error ) {
1664- jsonBytes , err := json .Marshal (steps )
1665- if err != nil {
1666- return "" , err
1667- }
1668- hash := sha256 .Sum256 (jsonBytes )
1669- return fmt .Sprintf ("%x" , hash ), nil
1670- }()
1671-
1672- if err != nil {
1673- return nil , err
1674- }
1675-
1676- var csvNames []string
1663+ csvNames := []string {}
16771664 catalogSourceMap := map [string ]struct {}{}
16781665 for _ , s := range steps {
16791666 if s .Resource .Kind == "ClusterServiceVersion" {
@@ -1682,7 +1669,7 @@ func (o *Operator) createInstallPlan(namespace string, gen int, subs []*v1alpha1
16821669 catalogSourceMap [s .Resource .CatalogSource ] = struct {}{}
16831670 }
16841671
1685- var catalogSources []string
1672+ catalogSources := []string {}
16861673 for s := range catalogSourceMap {
16871674 catalogSources = append (catalogSources , s )
16881675 }
@@ -1693,8 +1680,8 @@ func (o *Operator) createInstallPlan(namespace string, gen int, subs []*v1alpha1
16931680 }
16941681 ip := & v1alpha1.InstallPlan {
16951682 ObjectMeta : metav1.ObjectMeta {
1696- Name : fmt . Sprintf ( "install-%s" , sha ) ,
1697- Namespace : namespace ,
1683+ GenerateName : "install-" ,
1684+ Namespace : namespace ,
16981685 },
16991686 Spec : v1alpha1.InstallPlanSpec {
17001687 ClusterServiceVersionNames : csvNames ,
@@ -1708,8 +1695,7 @@ func (o *Operator) createInstallPlan(namespace string, gen int, subs []*v1alpha1
17081695 }
17091696
17101697 res , err := o .client .OperatorsV1alpha1 ().InstallPlans (namespace ).Create (context .TODO (), ip , metav1.CreateOptions {})
1711- if err != nil && ! apierrors .IsAlreadyExists (err ) {
1712-
1698+ if err != nil {
17131699 return nil , err
17141700 }
17151701
@@ -1719,10 +1705,11 @@ func (o *Operator) createInstallPlan(namespace string, gen int, subs []*v1alpha1
17191705 CatalogSources : catalogSources ,
17201706 BundleLookups : bundleLookups ,
17211707 }
1722-
1723- if _ , err = o . client . OperatorsV1alpha1 (). InstallPlans ( namespace ). UpdateStatus ( context . TODO (), res , metav1. UpdateOptions {}); err != nil {
1708+ res , err = o . client . OperatorsV1alpha1 (). InstallPlans ( namespace ). UpdateStatus ( context . TODO (), res , metav1. UpdateOptions {})
1709+ if err != nil {
17241710 return nil , err
17251711 }
1712+
17261713 return reference .GetReference (res )
17271714}
17281715
@@ -1766,6 +1753,7 @@ func (o *Operator) updateSubscriptionStatuses(subs []*v1alpha1.Subscription) ([]
17661753 errs []error
17671754 mu sync.Mutex
17681755 wg sync.WaitGroup
1756+ getOpts = metav1.GetOptions {}
17691757 updateOpts = metav1.UpdateOptions {}
17701758 )
17711759
@@ -1774,29 +1762,22 @@ func (o *Operator) updateSubscriptionStatuses(subs []*v1alpha1.Subscription) ([]
17741762 go func (sub * v1alpha1.Subscription ) {
17751763 defer wg .Done ()
17761764
1777- _ , err := o .client .OperatorsV1alpha1 ().Subscriptions (sub .Namespace ).UpdateStatus (context .TODO (), sub , updateOpts )
1778- if err != nil {
1765+ update := func () error {
1766+ // Update the status of the latest revision
1767+ latest , err := o .client .OperatorsV1alpha1 ().Subscriptions (sub .GetNamespace ()).Get (context .TODO (), sub .GetName (), getOpts )
1768+ if err != nil {
1769+ return err
1770+ }
1771+ latest .Status = sub .Status
1772+ * sub = * latest
1773+ _ , err = o .client .OperatorsV1alpha1 ().Subscriptions (sub .Namespace ).UpdateStatus (context .TODO (), latest , updateOpts )
1774+ return err
1775+ }
1776+ if err := retry .RetryOnConflict (retry .DefaultRetry , update ); err != nil {
17791777 mu .Lock ()
17801778 defer mu .Unlock ()
17811779 errs = append (errs , err )
17821780 }
1783-
1784- //update := func() error {
1785- // // Update the status of the latest revision
1786- // latest, err := o.client.OperatorsV1alpha1().Subscriptions(sub.GetNamespace()).Get(context.TODO(), sub.GetName(), getOpts)
1787- // if err != nil {
1788- // return err
1789- // }
1790- // latest.Status = sub.Status
1791- // *sub = *latest
1792- // _, err = o.client.OperatorsV1alpha1().Subscriptions(sub.Namespace).UpdateStatus(context.TODO(), latest, updateOpts)
1793- // return err
1794- //}
1795- //if err := retry.RetryOnConflict(retry.DefaultRetry, update); err != nil {
1796- // mu.Lock()
1797- // defer mu.Unlock()
1798- // errs = append(errs, err)
1799- //}
18001781 }(sub )
18011782 }
18021783 wg .Wait ()
@@ -2857,11 +2838,31 @@ func (o *Operator) getUpdatedOwnerReferences(refs []metav1.OwnerReference, names
28572838}
28582839
28592840func (o * Operator ) listSubscriptions (namespace string ) (subs []* v1alpha1.Subscription , err error ) {
2860- return o .lister .OperatorsV1alpha1 ().SubscriptionLister ().Subscriptions (namespace ).List (labels .Everything ())
2841+ list , err := o .client .OperatorsV1alpha1 ().Subscriptions (namespace ).List (context .TODO (), metav1.ListOptions {})
2842+ if err != nil {
2843+ return
2844+ }
2845+
2846+ subs = make ([]* v1alpha1.Subscription , 0 )
2847+ for i := range list .Items {
2848+ subs = append (subs , & list .Items [i ])
2849+ }
2850+
2851+ return
28612852}
28622853
28632854func (o * Operator ) listInstallPlans (namespace string ) (ips []* v1alpha1.InstallPlan , err error ) {
2864- return o .lister .OperatorsV1alpha1 ().InstallPlanLister ().InstallPlans (namespace ).List (labels .Everything ())
2855+ list , err := o .client .OperatorsV1alpha1 ().InstallPlans (namespace ).List (context .TODO (), metav1.ListOptions {})
2856+ if err != nil {
2857+ return
2858+ }
2859+
2860+ ips = make ([]* v1alpha1.InstallPlan , 0 )
2861+ for i := range list .Items {
2862+ ips = append (ips , & list .Items [i ])
2863+ }
2864+
2865+ return
28652866}
28662867
28672868// competingCRDOwnersExist returns true if there exists a CSV that owns at least one of the given CSVs owned CRDs (that's not the given CSV)
0 commit comments