Skip to content

Commit aa405a0

Browse files
author
Per Goncalves da Silva
committed
another go
Signed-off-by: Per Goncalves da Silva <[email protected]>
1 parent 1efb9bf commit aa405a0

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

pkg/api/client/clientset/versioned/fake/decorator.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ func NewReactionForwardingClientsetDecorator(objects []runtime.Object, options .
5353
for _, option := range options {
5454
option(decorator)
5555
}
56-
5756
return decorator
5857
}
5958

pkg/controller/operators/catalog/operator.go

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,25 +1477,30 @@ func (o *Operator) syncResolvingNamespace(obj interface{}) error {
14771477
o.removeSubsCond(subs, v1alpha1.SubscriptionResolutionFailed)
14781478

14791479
for _, updatedSub := range updatedSubs {
1480-
newSub := true
1480+
isNewSub := true
14811481
updatedSub.Status.RemoveConditions(v1alpha1.SubscriptionResolutionFailed)
14821482
for i, sub := range subs {
14831483
if sub.Name == updatedSub.Name && sub.Namespace == updatedSub.Namespace {
14841484
subs[i] = updatedSub
1485-
newSub = false
1485+
isNewSub = false
14861486
break
14871487
}
14881488
}
1489-
if newSub {
1489+
if isNewSub {
14901490
subs = append(subs, updatedSub)
1491-
continue
14921491
}
14931492
}
14941493

1494+
// *********************************** WARNING *********************************** //
1495+
// if updateSubscriptionStatuses call fails and the IP reference was changed //
1496+
// in this run, we'll be screwed because the IP would have been created but the //
1497+
// subscription won't carry its reference. And, if the CSV gets created by the IP, //
1498+
// it won't be associated with the Subscription -> perma-failure on resolution //
1499+
// ******************************************************************************* //
14951500
// Update subscriptions with all changes so far
14961501
_, updateErr := o.updateSubscriptionStatuses(subs)
14971502
if updateErr != nil {
1498-
logger.WithError(updateErr).Warn("failed to update subscription conditions")
1503+
logger.WithField("irreconcilable-resolution", namespace).WithError(updateErr).Warn("failed to patch subscription conditions")
14991504
return updateErr
15001505
}
15011506

@@ -1667,15 +1672,19 @@ func (o *Operator) ensureInstallPlan(logger *logrus.Entry, namespace string, gen
16671672
}
16681673
logger.Warn("no installplan found with matching generation, creating new one")
16691674

1670-
return o.createInstallPlan(namespace, gen, subs, installPlanApproval, steps, bundleLookups)
1675+
ip, err := o.createInstallPlan(namespace, gen, subs, installPlanApproval, steps, bundleLookups)
1676+
if err != nil {
1677+
return nil, err
1678+
}
1679+
return reference.GetReference(ip)
16711680
}
16721681

16731682
func (o *Operator) createInstallPlan(namespace string, gen int, subs []*v1alpha1.Subscription, installPlanApproval v1alpha1.Approval, steps []*v1alpha1.Step, bundleLookups []v1alpha1.BundleLookup) (*corev1.ObjectReference, error) {
16741683
if len(steps) == 0 && len(bundleLookups) == 0 {
16751684
return nil, nil
16761685
}
16771686

1678-
csvNames := []string{}
1687+
var csvNames []string
16791688
catalogSourceMap := map[string]struct{}{}
16801689
for _, s := range steps {
16811690
if s.Resource.Kind == "ClusterServiceVersion" {
@@ -1684,7 +1693,7 @@ func (o *Operator) createInstallPlan(namespace string, gen int, subs []*v1alpha1
16841693
catalogSourceMap[s.Resource.CatalogSource] = struct{}{}
16851694
}
16861695

1687-
catalogSources := []string{}
1696+
var catalogSources []string
16881697
for s := range catalogSourceMap {
16891698
catalogSources = append(catalogSources, s)
16901699
}
@@ -1720,12 +1729,18 @@ func (o *Operator) createInstallPlan(namespace string, gen int, subs []*v1alpha1
17201729
CatalogSources: catalogSources,
17211730
BundleLookups: bundleLookups,
17221731
}
1723-
res, err = o.client.OperatorsV1alpha1().InstallPlans(namespace).UpdateStatus(context.TODO(), res, metav1.UpdateOptions{})
1732+
1733+
// *************************** WARNING *************************** //
1734+
// If this call fails, the IP will never do anything since it //
1735+
// requires the steps to exist in .status //
1736+
// *************************************************************** //
1737+
newRes, err := o.client.OperatorsV1alpha1().InstallPlans(namespace).UpdateStatus(context.TODO(), res, metav1.UpdateOptions{})
17241738
if err != nil {
1739+
o.logger.WithField("irreconcilable-ip", res.GetName()).WithError(err).Warn("error updating installplan status after creation")
17251740
return nil, err
17261741
}
17271742

1728-
return reference.GetReference(res)
1743+
return reference.GetReference(newRes)
17291744
}
17301745

17311746
// setSubsCond will set the condition to the subscription if it doesn't already
@@ -1749,7 +1764,7 @@ func (o *Operator) setSubsCond(subs []*v1alpha1.Subscription, cond v1alpha1.Subs
17491764
return subList
17501765
}
17511766

1752-
// removeSubsCond removes the given condition from all of the subscriptions in the input
1767+
// removeSubsCond removes the given condition from all the subscriptions in the input
17531768
func (o *Operator) removeSubsCond(subs []*v1alpha1.Subscription, condType v1alpha1.SubscriptionConditionType) {
17541769
lastUpdated := o.now()
17551770
for _, sub := range subs {

pkg/controller/operators/catalog/operator_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2083,7 +2083,7 @@ func NewFakeOperator(ctx context.Context, namespace string, namespaces []string,
20832083
clientFake := fake.NewReactionForwardingClientsetDecorator(config.clientObjs, config.clientOptions...)
20842084
// TODO: Using the ReactionForwardingClientsetDecorator for k8s objects causes issues with adding Resources for discovery.
20852085
// For now, directly use a SimpleClientset instead.
2086-
k8sClientFake := k8sfake.NewSimpleClientset(config.k8sObjs...)
2086+
k8sClientFake := k8sfake.NewClientset(config.k8sObjs...)
20872087
k8sClientFake.Resources = apiResourcesForObjects(append(config.extObjs, config.regObjs...))
20882088
opClientFake := operatorclient.NewClient(k8sClientFake, apiextensionsfake.NewSimpleClientset(config.extObjs...), apiregistrationfake.NewSimpleClientset(config.regObjs...))
20892089
dynamicClientFake := fakedynamic.NewSimpleDynamicClient(runtime.NewScheme())

0 commit comments

Comments
 (0)