Skip to content
Prev Previous commit
Next Next commit
preliminary changes for odlm delete operands
Signed-off-by: Ben Luzarraga <[email protected]>
  • Loading branch information
bluzarraga committed Jan 30, 2025
commit a69f49074322163bf672e7c95515d4e2a83513c5
5 changes: 2 additions & 3 deletions controllers/operandrequestnoolm/reconcile_operand.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"sync"
"time"

olmv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
"github.com/pkg/errors"
appsv1 "k8s.io/api/apps/v1"
authorizationv1 "k8s.io/api/authorization/v1"
Expand Down Expand Up @@ -589,7 +588,7 @@ func (r *Reconciler) reconcileK8sResource(ctx context.Context, res operatorv1alp
}

// deleteAllCustomResource remove custom resource base on OperandConfig and CSV alm-examples
func (r *Reconciler) deleteAllCustomResource(ctx context.Context, csv *olmv1alpha1.ClusterServiceVersion, requestInstance *operatorv1alpha1.OperandRequest, csc *operatorv1alpha1.OperandConfig, operandName, namespace string) error {
func (r *Reconciler) deleteAllCustomResource(ctx context.Context, deployment *appsv1.Deployment, requestInstance *operatorv1alpha1.OperandRequest, csc *operatorv1alpha1.OperandConfig, operandName, namespace string) error {

customeResourceMap := make(map[string]operatorv1alpha1.OperandCRMember)
for _, member := range requestInstance.Status.Members {
Expand Down Expand Up @@ -645,7 +644,7 @@ func (r *Reconciler) deleteAllCustomResource(ctx context.Context, csv *olmv1alph
if service == nil {
return nil
}
almExamples := csv.GetAnnotations()["alm-examples"]
almExamples := deployment.GetAnnotations()["alm-examples"]
klog.V(2).Info("Delete all the custom resource from Subscription ", service.Name)

// Create a slice for crTemplates
Expand Down
14 changes: 7 additions & 7 deletions controllers/operandrequestnoolm/reconcile_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,17 +526,17 @@ func (r *Reconciler) uninstallOperands(ctx context.Context, operandName string,
// ignore the name which triggered reconcile
// if list is empty then uninstallOperand = true

if csvList, err := r.GetClusterServiceVersionListFromPackage(ctx, op.PackageName, namespace); err != nil {
// If can't get CSV, requeue the request
if deploymentList, err := r.GetDeploymentListFromPackage(ctx, op.PackageName, op.Namespace); err != nil {
// If can't get deployment, requeue the request
return err
} else if csvList != nil {
klog.Infof("Found %d ClusterServiceVersions for package %s/%s", len(csvList), op.Name, namespace)
} else if deploymentList != nil {
klog.Infof("Found %d Deployment for package %s/%s", len(deploymentList), op.Name, namespace)
if uninstallOperand {
klog.V(2).Infof("Deleting all the Custom Resources for CSV, Namespace: %s, Name: %s", csvList[0].Namespace, csvList[0].Name)
if err := r.deleteAllCustomResource(ctx, csvList[0], requestInstance, configInstance, operandName, configInstance.Namespace); err != nil {
klog.V(2).Infof("Deleting all the Custom Resources for Deployment, Namespace: %s, Name: %s", deploymentList[0].Namespace, deploymentList[0].Name)
if err := r.deleteAllCustomResource(ctx, deploymentList[0], requestInstance, configInstance, operandName, configInstance.Namespace); err != nil {
return err
}
klog.V(2).Infof("Deleting all the k8s Resources for CSV, Namespace: %s, Name: %s", csvList[0].Namespace, csvList[0].Name)
klog.V(2).Infof("Deleting all the k8s Resources for Deployment, Namespace: %s, Name: %s", deploymentList[0].Namespace, deploymentList[0].Name)
if err := r.deleteAllK8sResource(ctx, configInstance, operandName, configInstance.Namespace); err != nil {
return err
}
Expand Down