Skip to content

Commit f9425b4

Browse files
committed
fix(catalog): Fix subscriptions without a sourceNamespace hang forever
Signed-off-by: Vu Dinh <[email protected]>
1 parent 19e7914 commit f9425b4

File tree

2 files changed

+134
-1
lines changed

2 files changed

+134
-1
lines changed

pkg/controller/operators/catalog/subscriptions_test.go

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,133 @@ func TestSyncSubscriptions(t *testing.T) {
4949
},
5050
wantErr: fmt.Errorf("casting Subscription failed"),
5151
},
52+
{
53+
name: "NoStatus/NoCurrentCSV/MissingCatalogSourceNamespace",
54+
fields: fields{
55+
clientOptions: []clientfake.Option{clientfake.WithSelfLinks(t)},
56+
existingOLMObjs: []runtime.Object{
57+
&v1alpha1.Subscription{
58+
ObjectMeta: metav1.ObjectMeta{
59+
Name: "sub",
60+
Namespace: testNamespace,
61+
},
62+
Spec: &v1alpha1.SubscriptionSpec{
63+
CatalogSource: "src",
64+
},
65+
Status: v1alpha1.SubscriptionStatus{
66+
CurrentCSV: "",
67+
State: "",
68+
},
69+
},
70+
},
71+
resolveSteps: []*v1alpha1.Step{
72+
{
73+
Resolving: "csv.v.1",
74+
Resource: v1alpha1.StepResource{
75+
CatalogSource: "src",
76+
CatalogSourceNamespace: testNamespace,
77+
Group: v1alpha1.GroupName,
78+
Version: v1alpha1.GroupVersion,
79+
Kind: v1alpha1.ClusterServiceVersionKind,
80+
Name: "csv.v.1",
81+
Manifest: "{}",
82+
},
83+
},
84+
},
85+
resolveSubs: []*v1alpha1.Subscription{
86+
{
87+
TypeMeta: metav1.TypeMeta{
88+
Kind: v1alpha1.SubscriptionKind,
89+
APIVersion: v1alpha1.SchemeGroupVersion.String(),
90+
},
91+
ObjectMeta: metav1.ObjectMeta{
92+
Name: "sub",
93+
Namespace: testNamespace,
94+
},
95+
Spec: &v1alpha1.SubscriptionSpec{
96+
CatalogSource: "src",
97+
},
98+
Status: v1alpha1.SubscriptionStatus{
99+
CurrentCSV: "csv.v.1",
100+
State: "SubscriptionStateAtLatest",
101+
},
102+
},
103+
},
104+
},
105+
args: args{
106+
obj: &v1alpha1.Subscription{
107+
ObjectMeta: metav1.ObjectMeta{
108+
Name: "sub",
109+
Namespace: testNamespace,
110+
},
111+
Spec: &v1alpha1.SubscriptionSpec{
112+
CatalogSource: "src",
113+
},
114+
Status: v1alpha1.SubscriptionStatus{
115+
CurrentCSV: "",
116+
State: "",
117+
},
118+
},
119+
},
120+
wantSubscriptions: []*v1alpha1.Subscription{
121+
{
122+
TypeMeta: metav1.TypeMeta{
123+
Kind: v1alpha1.SubscriptionKind,
124+
APIVersion: v1alpha1.SubscriptionCRDAPIVersion,
125+
},
126+
ObjectMeta: metav1.ObjectMeta{
127+
Name: "sub",
128+
Namespace: testNamespace,
129+
},
130+
Spec: &v1alpha1.SubscriptionSpec{
131+
CatalogSource: "src",
132+
},
133+
Status: v1alpha1.SubscriptionStatus{
134+
CurrentCSV: "csv.v.1",
135+
State: v1alpha1.SubscriptionStateUpgradePending,
136+
Install: &v1alpha1.InstallPlanReference{
137+
Kind: v1alpha1.InstallPlanKind,
138+
APIVersion: v1alpha1.InstallPlanAPIVersion,
139+
},
140+
InstallPlanRef: &v1.ObjectReference{
141+
Namespace: testNamespace,
142+
Kind: v1alpha1.InstallPlanKind,
143+
APIVersion: v1alpha1.InstallPlanAPIVersion,
144+
},
145+
LastUpdated: now,
146+
},
147+
},
148+
},
149+
wantInstallPlan: &v1alpha1.InstallPlan{
150+
Spec: v1alpha1.InstallPlanSpec{
151+
ClusterServiceVersionNames: []string{
152+
"csv.v.1",
153+
},
154+
Approval: v1alpha1.ApprovalAutomatic,
155+
Approved: true,
156+
},
157+
Status: v1alpha1.InstallPlanStatus{
158+
Phase: v1alpha1.InstallPlanPhaseInstalling,
159+
CatalogSources: []string{
160+
"src",
161+
},
162+
Plan: []*v1alpha1.Step{
163+
{
164+
Resolving: "csv.v.1",
165+
Resource: v1alpha1.StepResource{
166+
CatalogSource: "src",
167+
CatalogSourceNamespace: testNamespace,
168+
Group: v1alpha1.GroupName,
169+
Version: v1alpha1.GroupVersion,
170+
Kind: v1alpha1.ClusterServiceVersionKind,
171+
Name: "csv.v.1",
172+
Manifest: "{}",
173+
},
174+
},
175+
},
176+
},
177+
},
178+
},
52179
{
53180
name: "NoStatus/NoCurrentCSV/FoundInCatalog",
54181
fields: fields{

pkg/controller/registry/resolver/resolver.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,18 +146,24 @@ func (r *OperatorsV1alpha1Resolver) sourceInfoForNewSubscriptions(namespace stri
146146

147147
func (r *OperatorsV1alpha1Resolver) sourceInfoToSubscriptions(subs []*v1alpha1.Subscription) (add map[OperatorSourceInfo]*v1alpha1.Subscription) {
148148
add = make(map[OperatorSourceInfo]*v1alpha1.Subscription)
149+
var sourceNamespace string
149150
for _, s := range subs {
150151
startingCSV := s.Spec.StartingCSV
151152
if s.Status.CurrentCSV != "" {
152153
// If a csv has previously been resolved for the operator, don't enable
153154
// a starting csv search.
154155
startingCSV = ""
155156
}
157+
if s.Spec.CatalogSourceNamespace == "" {
158+
sourceNamespace = s.GetNamespace()
159+
} else {
160+
sourceNamespace = s.Spec.CatalogSourceNamespace
161+
}
156162
add[OperatorSourceInfo{
157163
Package: s.Spec.Package,
158164
Channel: s.Spec.Channel,
159165
StartingCSV: startingCSV,
160-
Catalog: CatalogKey{Name: s.Spec.CatalogSource, Namespace: s.Spec.CatalogSourceNamespace},
166+
Catalog: CatalogKey{Name: s.Spec.CatalogSource, Namespace: sourceNamespace},
161167
}] = s.DeepCopy()
162168
}
163169
return

0 commit comments

Comments
 (0)