Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions controllers/operandrequest/reconcile_operand.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ func (r *Reconciler) reconcileOperand(ctx context.Context, requestInstance *oper
continue
}

if err := r.DeleteRedundantCSV(ctx, csv.Name, csv.Namespace, registryKey.Namespace, opdRegistry.PackageName); err != nil {
merr.Add(errors.Wrapf(err, "failed to delete the redundant ClusterServiceVersion %s in the namespace %s", csv.Name, csv.Namespace))
requestInstance.SetMemberStatus(operand.Name, operatorv1alpha1.OperatorFailed, "", &r.Mutex)
continue
}

// find the OperandRequest which has the same operator's channel version as existing subscription.
// ODLM will only reconcile Operand based on OperandConfig for this OperandRequest
var requestList []string
Expand Down
31 changes: 31 additions & 0 deletions controllers/operator/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,37 @@ func (m *ODLMOperator) GetClusterServiceVersionList(ctx context.Context, sub *ol
return csvs, nil
}

func (m *ODLMOperator) DeleteRedundantCSV(ctx context.Context, csvName, operatorNs, serviceNs, packageName string) error {
// Get the csv by its name and namespace
csv := &olmv1alpha1.ClusterServiceVersion{}
csvKey := types.NamespacedName{
Name: csvName,
Namespace: serviceNs,
}
if err := m.Reader.Get(ctx, csvKey, csv); err != nil {
if apierrors.IsNotFound(err) {
klog.V(2).Infof("ClusterServiceVersion %s is not found", csvName)
return nil
}
return errors.Wrapf(err, "failed to get ClusterServiceVersion %s/%s", serviceNs, csvName)
}

if csv.GetLabels() == nil {
klog.V(2).Infof("ClusterServiceVersion %s in the namespace %s has no label", csvName, serviceNs)
return nil
}
// Delete the CSV if the csv does not contain label operators.coreos.com/packageName.operatorNs='' AND does not contains label olm.copiedFrom: operatorNs
if _, ok := csv.GetLabels()[fmt.Sprintf("operators.coreos.com/%s.%s", packageName, operatorNs)]; !ok {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code does not account for the label lenght limit of 64 characters, where for the long namespace names, the label name is truncated, see https://github.ibm.com/IBMPrivateCloud/roadmap/issues/61714

if csv.GetLabels()["olm.copiedFrom"] != operatorNs {
klog.Infof("Delete the redundant ClusterServiceVersion %s in the namespace %s", csvName, serviceNs)
if err := m.Client.Delete(ctx, csv); err != nil {
return errors.Wrapf(err, "failed to delete ClusterServiceVersion %s/%s", serviceNs, csvName)
}
}
}
return nil
}

// GetOperatorNamespace returns the operator namespace based on the install mode
func (m *ODLMOperator) GetOperatorNamespace(installMode, namespace string) string {
if installMode == apiv1alpha1.InstallModeCluster {
Expand Down