Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
update test cases
Signed-off-by: Daniel Fan <[email protected]>
  • Loading branch information
Daniel-Fan committed Sep 16, 2024
commit f1f61bfa1171abe5b83038803a0f83876ad73cf2
5 changes: 4 additions & 1 deletion controllers/operandrequest/operandrequest_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re
if err := r.Client.Status().Patch(ctx, requestInstance, client.MergeFrom(existingInstance)); err != nil && !apierrors.IsNotFound(err) {
reconcileErr = utilerrors.NewAggregate([]error{reconcileErr, fmt.Errorf("error while patching OperandRequest.Status: %v", err)})
}
if reconcileErr != nil {
klog.Errorf("failed to patch status for OperandRequest %s: %v", req.NamespacedName.String(), reconcileErr)
}
}()

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

klog.V(1).Infof("Finished reconciling OperandRequest: %s", req.NamespacedName)
return ctrl.Result{RequeueAfter: constant.DefaultSyncPeriod}, nil
return ctrl.Result{RequeueAfter: constant.DefaultSyncPeriod}, reconcileErr
}

func (r *Reconciler) checkPermission(ctx context.Context, req ctrl.Request) bool {
Expand Down
2 changes: 1 addition & 1 deletion controllers/operandrequest/reconcile_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ func checkSubAnnotationsForUninstall(reqName, reqNs, opName, installMode string,
uninstallOperator = false
}

if _, ok := sub.Labels[constant.OpreqLabel]; !ok {
if value, ok := sub.Labels[constant.OpreqLabel]; !ok || value != "true" {
uninstallOperator = false
}

Expand Down
39 changes: 39 additions & 0 deletions controllers/operandrequest/reconcile_operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ func TestCheckSubAnnotationsForUninstall(t *testing.T) {
reqNsNew + "." + reqNameB + "." + opNameV4 + "/request": opChannelV4,
reqNsNew + "." + reqNameB + "." + opNameV4 + "/operatorNamespace": reqNsNew,
},
Labels: map[string]string{
constant.OpreqLabel: "true",
},
},
}

Expand All @@ -198,6 +201,9 @@ func TestCheckSubAnnotationsForUninstall(t *testing.T) {
reqNsNew + "." + reqNameB + "." + opNameV4 + "/request": opChannelV4,
reqNsNew + "." + reqNameB + "." + opNameV4 + "/operatorNamespace": reqNsNew,
},
Labels: map[string]string{
constant.OpreqLabel: "true",
},
},
}

Expand All @@ -224,6 +230,9 @@ func TestCheckSubAnnotationsForUninstall(t *testing.T) {
reqNsOld + "." + reqNameD + "." + opNameD + "/request": opChannelD,
reqNsOld + "." + reqNameD + "." + opNameD + "/operatorNamespace": reqNsOld,
},
Labels: map[string]string{
constant.OpreqLabel: "true",
},
},
}

Expand All @@ -250,6 +259,9 @@ func TestCheckSubAnnotationsForUninstall(t *testing.T) {
reqNsOld + "." + reqNameB + "." + opNameV4 + "/request": opChannelV4,
reqNsOld + "." + reqNameB + "." + opNameV4 + "/operatorNamespace": reqNsOld,
},
Labels: map[string]string{
constant.OpreqLabel: "true",
},
},
}

Expand All @@ -275,6 +287,9 @@ func TestCheckSubAnnotationsForUninstall(t *testing.T) {
reqNsNew + "." + reqNameB + "." + opNameV4 + "/request": opChannelV4,
reqNsNew + "." + reqNameB + "." + opNameV4 + "/operatorNamespace": reqNsNew,
},
Labels: map[string]string{
constant.OpreqLabel: "true",
},
},
}

Expand All @@ -287,4 +302,28 @@ func TestCheckSubAnnotationsForUninstall(t *testing.T) {
assert.NotContains(t, sub.Annotations, reqNsNew+"."+reqNameA+"."+opNameV4+"/operatorNamespace")
assert.Contains(t, sub.Annotations, reqNsNew+"."+reqNameB+"."+opNameV4+"/request")
assert.Contains(t, sub.Annotations, reqNsNew+"."+reqNameB+"."+opNameV4+"/operatorNamespace")

// Test case 8: uninstallOperator is false, uninstallOperand is true for operator with general installMode
// The operator should be NOT uninstalled because operator is not been managed by ODLM.
// The operand should be uninstalled because no other OperandRequest is requesting the same operand.
sub = &olmv1alpha1.Subscription{
ObjectMeta: metav1.ObjectMeta{
Namespace: reqNsOld,
Annotations: map[string]string{
reqNsOld + "." + reqNameA + "." + opNameV4 + "/request": opChannelV4,
reqNsOld + "." + reqNameA + "." + opNameV4 + "/operatorNamespace": reqNsOld,
},
Labels: map[string]string{
constant.OpreqLabel: "false",
},
},
}

uninstallOperator, uninstallOperand = checkSubAnnotationsForUninstall(reqNameA, reqNsOld, opNameV4, operatorv1alpha1.InstallModeNamespace, sub)

assert.False(t, uninstallOperator)
assert.True(t, uninstallOperand)

assert.NotContains(t, sub.Annotations, reqNsOld+"."+reqNameA+"."+opNameV4+"/request")
assert.NotContains(t, sub.Annotations, reqNsOld+"."+reqNameA+"."+opNameV4+"/operatorNamespace")
}
2 changes: 1 addition & 1 deletion controllers/operator/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (m *ODLMOperator) GetCatalogSourceAndChannelFromPackage(ctx context.Context
switch number {
case 0:
klog.V(2).Infof("Not found PackageManifest %s in the namespace %s has channel %s", packageName, namespace, channel)
return "", "", "", nil
return opregCatalog, opregCatalogNs, channel, nil
default:
// Check if the CatalogSource and CatalogSource namespace are specified in OperandRegistry
if opregCatalog != "" && opregCatalogNs != "" {
Expand Down