Skip to content

Commit 4b339b8

Browse files
committed
fix(resolver): resolved dependent subscriptions don't detect updates
this occurred because we only check for updates when we have information about the currently installed CSV on the subscription status, which was omitted from dependent catalogs. the resolver now records the csv resolved into the subscription spec, and it is used to populate the installed csv status when available.
1 parent bfc2f94 commit 4b339b8

File tree

7 files changed

+51
-15
lines changed

7 files changed

+51
-15
lines changed

pkg/controller/operators/catalog/operator.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ func (o *Operator) nothingToUpdate(logger *logrus.Entry, sub *v1alpha1.Subscript
736736
}
737737

738738
func (o *Operator) ensureSubscriptionInstallPlanState(logger *logrus.Entry, sub *v1alpha1.Subscription) (*v1alpha1.Subscription, bool, error) {
739-
if sub.Status.Install != nil {
739+
if sub.Status.InstallPlanRef != nil {
740740
return sub, false, nil
741741
}
742742

@@ -765,6 +765,8 @@ func (o *Operator) ensureSubscriptionInstallPlanState(logger *logrus.Entry, sub
765765
out.Status.InstallPlanRef = ref
766766
out.Status.Install = v1alpha1.NewInstallPlanReference(ref)
767767
out.Status.State = v1alpha1.SubscriptionStateUpgradePending
768+
out.Status.CurrentCSV = out.Spec.StartingCSV
769+
out.Status.LastUpdated = timeNow()
768770

769771
updated, err := o.client.OperatorsV1alpha1().Subscriptions(sub.GetNamespace()).UpdateStatus(out)
770772
if err != nil {

pkg/controller/operators/catalog/operator_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -142,23 +142,23 @@ func TestExecutePlan(t *testing.T) {
142142
Resource: v1alpha1.StepResource{
143143
CatalogSource: "catalog",
144144
CatalogSourceNamespace: namespace,
145-
Group: "",
146-
Version: "v1",
147-
Kind: "Service",
148-
Name: "service",
149-
Manifest: toManifest(service("service", namespace)),
145+
Group: "",
146+
Version: "v1",
147+
Kind: "Service",
148+
Name: "service",
149+
Manifest: toManifest(service("service", namespace)),
150150
},
151151
Status: v1alpha1.StepStatusUnknown,
152152
},
153153
&v1alpha1.Step{
154154
Resource: v1alpha1.StepResource{
155155
CatalogSource: "catalog",
156156
CatalogSourceNamespace: namespace,
157-
Group: "operators.coreos.com",
158-
Version: "v1alpha1",
159-
Kind: "ClusterServiceVersion",
160-
Name: "csv",
161-
Manifest: toManifest(csv("csv", namespace, nil, nil)),
157+
Group: "operators.coreos.com",
158+
Version: "v1alpha1",
159+
Kind: "ClusterServiceVersion",
160+
Name: "csv",
161+
Manifest: toManifest(csv("csv", namespace, nil, nil)),
162162
},
163163
Status: v1alpha1.StepStatusUnknown,
164164
},

pkg/controller/registry/resolver/resolver.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ func (r *OperatorsV1alpha1Resolver) ResolveSteps(namespace string, sourceQuerier
105105

106106
// add steps for subscriptions for bundles that were added through resolution
107107
if !subExists {
108+
// explicitly track the resolved CSV as the starting CSV on the resolved subscriptions
109+
op.SourceInfo().StartingCSV = op.Identifier()
108110
subStep, err := NewSubscriptionStepResource(namespace, *op.SourceInfo())
109111
if err != nil {
110112
return nil, nil, err
@@ -147,15 +149,15 @@ func (r *OperatorsV1alpha1Resolver) sourceInfoToSubscriptions(subs []*v1alpha1.S
147149
for _, s := range subs {
148150
startingCSV := s.Spec.StartingCSV
149151
if s.Status.CurrentCSV != "" {
150-
// If a csv has previously been resolved for the operator, don't enable
152+
// If a csv has previously been resolved for the operator, don't enable
151153
// a starting csv search.
152154
startingCSV = ""
153155
}
154156
add[OperatorSourceInfo{
155-
Package: s.Spec.Package,
156-
Channel: s.Spec.Channel,
157+
Package: s.Spec.Package,
158+
Channel: s.Spec.Channel,
157159
StartingCSV: startingCSV,
158-
Catalog: CatalogKey{Name: s.Spec.CatalogSource, Namespace: s.Spec.CatalogSourceNamespace},
160+
Catalog: CatalogKey{Name: s.Spec.CatalogSource, Namespace: s.Spec.CatalogSourceNamespace},
159161
}] = s.DeepCopy()
160162
}
161163
return

pkg/controller/registry/resolver/resolver_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,7 @@ func subSteps(namespace, operatorName, pkgName, channelName string, catalog Cata
532532
Channel: channelName,
533533
CatalogSource: catalog.Name,
534534
CatalogSourceNamespace: catalog.Namespace,
535+
StartingCSV: operatorName,
535536
InstallPlanApproval: v1alpha1.ApprovalAutomatic,
536537
},
537538
}

pkg/controller/registry/resolver/steps.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ func NewSubscriptionStepResource(namespace string, info OperatorSourceInfo) (v1a
8383
CatalogSourceNamespace: info.Catalog.Namespace,
8484
Package: info.Package,
8585
Channel: info.Channel,
86+
StartingCSV: info.StartingCSV,
8687
InstallPlanApproval: v1alpha1.ApprovalAutomatic,
8788
},
8889
}, info.Catalog.Name, info.Catalog.Namespace)

test/e2e/installplan_e2e_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,30 @@ EXPECTED:
326326
}
327327

328328
t.Logf("All expected resources resolved")
329+
330+
// Verify that the dependent subscription is in a good state
331+
dependentSubscription, err := fetchSubscription(t, crc, testNamespace, strings.Join([]string{dependentPackageStable, dependentCatalogName, testNamespace}, "-"), subscriptionHasInstallPlanChecker)
332+
require.NoError(t, err)
333+
require.NotNil(t, dependentSubscription)
334+
require.NotNil(t, dependentSubscription.Status.InstallPlanRef)
335+
require.Equal(t, v1alpha1.SubscriptionState("AtLatestKnown"), dependentSubscription.Status.State)
336+
require.Equal(t, dependentCSV.GetName(), dependentSubscription.Status.CurrentCSV)
337+
338+
// TODO: update dependent subscription in catalog and wait for csv to update
339+
updatedDependentCSV := newCSV(dependentPackageStable+"v2", testNamespace, dependentPackageStable, *semver.New("0.1.1"), []apiextensions.CustomResourceDefinition{dependentCRD}, nil, dependentNamedStrategy)
340+
dependentManifests = []registry.PackageManifest{
341+
{
342+
PackageName: dependentPackageName,
343+
Channels: []registry.PackageChannel{
344+
{Name: stableChannel, CurrentCSVName: updatedDependentCSV.GetName()},
345+
},
346+
DefaultChannelName: stableChannel,
347+
},
348+
}
349+
updateInternalCatalog(t, c, crc, dependentCatalogName, testNamespace, []apiextensions.CustomResourceDefinition{dependentCRD}, []v1alpha1.ClusterServiceVersion{dependentCSV, updatedDependentCSV}, dependentManifests)
350+
351+
dependentSubscription, err = fetchSubscription(t, crc, testNamespace, strings.Join([]string{dependentPackageStable, dependentCatalogName, testNamespace}, "-"), subscriptionHasCurrentCSV(updatedDependentCSV.GetName()))
352+
require.NoError(t, err)
329353
}
330354

331355
func TestCreateInstallPlanWithPreExistingCRDOwners(t *testing.T) {

test/e2e/subscription_e2e_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,12 @@ func subscriptionStateAny(subscription *v1alpha1.Subscription) bool {
319319
subscriptionStateUpgradeAvailableChecker(subscription)
320320
}
321321

322+
func subscriptionHasCurrentCSV(currentCSV string) subscriptionStateChecker {
323+
return func(subscription *v1alpha1.Subscription) bool {
324+
return subscription.Status.CurrentCSV == currentCSV
325+
}
326+
}
327+
322328
func fetchSubscription(t *testing.T, crc versioned.Interface, namespace, name string, checker subscriptionStateChecker) (*v1alpha1.Subscription, error) {
323329
var fetchedSubscription *v1alpha1.Subscription
324330
var err error

0 commit comments

Comments
 (0)