Skip to content

Commit f71913e

Browse files
authored
Add packagemanifest CRD in test ENV (#1080)
* Add packagemanifest CRD in test ENV Signed-off-by: Daniel Fan <[email protected]> * update test cases Signed-off-by: Daniel Fan <[email protected]> --------- Signed-off-by: Daniel Fan <[email protected]>
1 parent 2c3e50f commit f71913e

File tree

6 files changed

+212
-3
lines changed

6 files changed

+212
-3
lines changed

common/Makefile.common.mk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ fetch-test-crds:
8282
tar -zxf v${NAMESPACESCOPE_VERSION}.tar.gz ibm-namespace-scope-operator-${NAMESPACESCOPE_VERSION}/bundle/manifests && mv ibm-namespace-scope-operator-${NAMESPACESCOPE_VERSION}/bundle/manifests/operator.ibm.com_namespacescopes.yaml ${ENVCRDS_DIR}/operator.ibm.com_namespacescopes.yaml ;\
8383
rm -rf ibm-namespace-scope-operator-${NAMESPACESCOPE_VERSION} v${NAMESPACESCOPE_VERSION}.tar.gz ;\
8484
}
85+
@{ \
86+
cp ./controllers/testutil/packagemanifests_crd.yaml ${ENVCRDS_DIR}/packagemanifests_crd.yaml ;\
87+
}
8588

8689

8790
CONTROLLER_GEN ?= $(shell pwd)/common/bin/controller-gen

controllers/operandrequest/operandrequest_controller.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re
103103
if err := r.Client.Status().Patch(ctx, requestInstance, client.MergeFrom(existingInstance)); err != nil && !apierrors.IsNotFound(err) {
104104
reconcileErr = utilerrors.NewAggregate([]error{reconcileErr, fmt.Errorf("error while patching OperandRequest.Status: %v", err)})
105105
}
106+
if reconcileErr != nil {
107+
klog.Errorf("failed to patch status for OperandRequest %s: %v", req.NamespacedName.String(), reconcileErr)
108+
}
106109
}()
107110

108111
// Remove finalizer when DeletionTimestamp none zero
@@ -180,7 +183,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re
180183
}
181184

182185
klog.V(1).Infof("Finished reconciling OperandRequest: %s", req.NamespacedName)
183-
return ctrl.Result{RequeueAfter: constant.DefaultSyncPeriod}, nil
186+
return ctrl.Result{RequeueAfter: constant.DefaultSyncPeriod}, reconcileErr
184187
}
185188

186189
func (r *Reconciler) checkPermission(ctx context.Context, req ctrl.Request) bool {

controllers/operandrequest/reconcile_operator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ func checkSubAnnotationsForUninstall(reqName, reqNs, opName, installMode string,
763763
uninstallOperator = false
764764
}
765765

766-
if _, ok := sub.Labels[constant.OpreqLabel]; !ok {
766+
if value, ok := sub.Labels[constant.OpreqLabel]; !ok || value != "true" {
767767
uninstallOperator = false
768768
}
769769

controllers/operandrequest/reconcile_operator_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ func TestCheckSubAnnotationsForUninstall(t *testing.T) {
174174
reqNsNew + "." + reqNameB + "." + opNameV4 + "/request": opChannelV4,
175175
reqNsNew + "." + reqNameB + "." + opNameV4 + "/operatorNamespace": reqNsNew,
176176
},
177+
Labels: map[string]string{
178+
constant.OpreqLabel: "true",
179+
},
177180
},
178181
}
179182

@@ -198,6 +201,9 @@ func TestCheckSubAnnotationsForUninstall(t *testing.T) {
198201
reqNsNew + "." + reqNameB + "." + opNameV4 + "/request": opChannelV4,
199202
reqNsNew + "." + reqNameB + "." + opNameV4 + "/operatorNamespace": reqNsNew,
200203
},
204+
Labels: map[string]string{
205+
constant.OpreqLabel: "true",
206+
},
201207
},
202208
}
203209

@@ -224,6 +230,9 @@ func TestCheckSubAnnotationsForUninstall(t *testing.T) {
224230
reqNsOld + "." + reqNameD + "." + opNameD + "/request": opChannelD,
225231
reqNsOld + "." + reqNameD + "." + opNameD + "/operatorNamespace": reqNsOld,
226232
},
233+
Labels: map[string]string{
234+
constant.OpreqLabel: "true",
235+
},
227236
},
228237
}
229238

@@ -250,6 +259,9 @@ func TestCheckSubAnnotationsForUninstall(t *testing.T) {
250259
reqNsOld + "." + reqNameB + "." + opNameV4 + "/request": opChannelV4,
251260
reqNsOld + "." + reqNameB + "." + opNameV4 + "/operatorNamespace": reqNsOld,
252261
},
262+
Labels: map[string]string{
263+
constant.OpreqLabel: "true",
264+
},
253265
},
254266
}
255267

@@ -275,6 +287,9 @@ func TestCheckSubAnnotationsForUninstall(t *testing.T) {
275287
reqNsNew + "." + reqNameB + "." + opNameV4 + "/request": opChannelV4,
276288
reqNsNew + "." + reqNameB + "." + opNameV4 + "/operatorNamespace": reqNsNew,
277289
},
290+
Labels: map[string]string{
291+
constant.OpreqLabel: "true",
292+
},
278293
},
279294
}
280295

@@ -287,4 +302,28 @@ func TestCheckSubAnnotationsForUninstall(t *testing.T) {
287302
assert.NotContains(t, sub.Annotations, reqNsNew+"."+reqNameA+"."+opNameV4+"/operatorNamespace")
288303
assert.Contains(t, sub.Annotations, reqNsNew+"."+reqNameB+"."+opNameV4+"/request")
289304
assert.Contains(t, sub.Annotations, reqNsNew+"."+reqNameB+"."+opNameV4+"/operatorNamespace")
305+
306+
// Test case 8: uninstallOperator is false, uninstallOperand is true for operator with general installMode
307+
// The operator should be NOT uninstalled because operator is not been managed by ODLM.
308+
// The operand should be uninstalled because no other OperandRequest is requesting the same operand.
309+
sub = &olmv1alpha1.Subscription{
310+
ObjectMeta: metav1.ObjectMeta{
311+
Namespace: reqNsOld,
312+
Annotations: map[string]string{
313+
reqNsOld + "." + reqNameA + "." + opNameV4 + "/request": opChannelV4,
314+
reqNsOld + "." + reqNameA + "." + opNameV4 + "/operatorNamespace": reqNsOld,
315+
},
316+
Labels: map[string]string{
317+
constant.OpreqLabel: "false",
318+
},
319+
},
320+
}
321+
322+
uninstallOperator, uninstallOperand = checkSubAnnotationsForUninstall(reqNameA, reqNsOld, opNameV4, operatorv1alpha1.InstallModeNamespace, sub)
323+
324+
assert.False(t, uninstallOperator)
325+
assert.True(t, uninstallOperand)
326+
327+
assert.NotContains(t, sub.Annotations, reqNsOld+"."+reqNameA+"."+opNameV4+"/request")
328+
assert.NotContains(t, sub.Annotations, reqNsOld+"."+reqNameA+"."+opNameV4+"/operatorNamespace")
290329
}

controllers/operator/manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func (m *ODLMOperator) GetCatalogSourceAndChannelFromPackage(ctx context.Context
154154
switch number {
155155
case 0:
156156
klog.V(2).Infof("Not found PackageManifest %s in the namespace %s has channel %s", packageName, namespace, channel)
157-
return "", "", "", nil
157+
return opregCatalog, opregCatalogNs, channel, nil
158158
default:
159159
// Check if the CatalogSource and CatalogSource namespace are specified in OperandRegistry
160160
if opregCatalog != "" && opregCatalogNs != "" {
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
apiVersion: apiextensions.k8s.io/v1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
name: packagemanifests.packages.operators.coreos.com
5+
spec:
6+
group: packages.operators.coreos.com
7+
versions:
8+
- name: v1
9+
served: true
10+
storage: true
11+
schema:
12+
openAPIV3Schema:
13+
type: object
14+
properties:
15+
spec:
16+
type: object
17+
status:
18+
type: object
19+
properties:
20+
catalogSource:
21+
type: string
22+
catalogSourceDisplayName:
23+
type: string
24+
catalogSourcePublisher:
25+
type: string
26+
catalogSourceNamespace:
27+
type: string
28+
provider:
29+
type: object
30+
properties:
31+
name:
32+
type: string
33+
url:
34+
type: string
35+
packageName:
36+
type: string
37+
deprecation:
38+
type: object
39+
properties:
40+
message:
41+
type: string
42+
channels:
43+
type: array
44+
items:
45+
type: object
46+
properties:
47+
name:
48+
type: string
49+
currentCSV:
50+
type: string
51+
currentCSVDesc:
52+
type: object
53+
properties:
54+
displayName:
55+
type: string
56+
icon:
57+
type: array
58+
items:
59+
type: object
60+
properties:
61+
base64data:
62+
type: string
63+
mediatype:
64+
type: string
65+
version:
66+
type: object
67+
properties:
68+
version:
69+
type: string
70+
provider:
71+
type: object
72+
properties:
73+
name:
74+
type: string
75+
url:
76+
type: string
77+
annotations:
78+
type: object
79+
additionalProperties:
80+
type: string
81+
keywords:
82+
type: array
83+
items:
84+
type: string
85+
links:
86+
type: array
87+
items:
88+
type: object
89+
properties:
90+
name:
91+
type: string
92+
url:
93+
type: string
94+
maintainers:
95+
type: array
96+
items:
97+
type: object
98+
properties:
99+
name:
100+
type: string
101+
email:
102+
type: string
103+
maturity:
104+
type: string
105+
longDescription:
106+
type: string
107+
installModes:
108+
type: array
109+
items:
110+
type: object
111+
properties:
112+
type:
113+
type: string
114+
supported:
115+
type: boolean
116+
customResourceDefinitions:
117+
type: object
118+
apiServiceDefinitions:
119+
type: object
120+
nativeAPIs:
121+
type: array
122+
items:
123+
type: object
124+
properties:
125+
group:
126+
type: string
127+
version:
128+
type: string
129+
kind:
130+
type: string
131+
minKubeVersion:
132+
type: string
133+
relatedImages:
134+
type: array
135+
items:
136+
type: string
137+
deprecation:
138+
type: object
139+
properties:
140+
message:
141+
type: string
142+
entries:
143+
type: array
144+
items:
145+
type: object
146+
properties:
147+
name:
148+
type: string
149+
version:
150+
type: string
151+
deprecation:
152+
type: object
153+
properties:
154+
message:
155+
type: string
156+
defaultChannel:
157+
type: string
158+
names:
159+
plural: packagemanifests
160+
singular: packagemanifest
161+
kind: PackageManifest
162+
shortNames:
163+
- pm
164+
scope: Namespaced

0 commit comments

Comments
 (0)