Skip to content

Commit

Permalink
disown copied csvs
Browse files Browse the repository at this point in the history
remove the label from any copied csv if it has been previously adopted

Signed-off-by: Evan Cordell <cordell.evan@gmail.com>
  • Loading branch information
ecordell committed Apr 9, 2021
1 parent e0bc6f6 commit 2d4b5e9
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions pkg/controller/operators/adoption_controller.go
Expand Up @@ -193,6 +193,12 @@ func (r *AdoptionReconciler) ReconcileClusterServiceVersion(req ctrl.Request) (r
return reconcile.Result{}, err
}

// disown copied csvs - a previous release inadvertently adopted them, this cleans any up if they are adopted
if in.IsCopied() {
err := r.disownFromAll(ctx, in)
return reconcile.Result{}, err
}

// Adopt all resources owned by the CSV if necessary
return reconcile.Result{}, r.adoptComponents(ctx, in)
}
Expand Down Expand Up @@ -305,6 +311,31 @@ func (r *AdoptionReconciler) disown(ctx context.Context, operator *decorators.Op
return r.Patch(ctx, candidate, client.MergeFrom(component))
}

func (r *AdoptionReconciler) disownFromAll(ctx context.Context, component runtime.Object) error {
cObj, ok := component.(client.Object)
if !ok {
return fmt.Errorf("Unable to typecast runtime.Object to client.Object")
}
var operators []decorators.Operator
for _, name := range decorators.OperatorNames(cObj.GetLabels()) {
o := &operatorsv1.Operator{}
o.SetName(name.Name)
operator, err := r.factory.NewOperator(o)
if err != nil {
return err
}
operators = append(operators, *operator)
}
errs := make([]error,0)
for _, operator := range operators {
if err := r.disown(ctx, &operator, component); err != nil {
errs = append(errs, err)
}
}

return utilerrors.NewAggregate(errs)
}

func (r *AdoptionReconciler) adoptees(ctx context.Context, operator decorators.Operator, csv *operatorsv1alpha1.ClusterServiceVersion) ([]runtime.Object, error) {
// Note: We need to figure out how to dynamically add new list types here (or some equivalent) in
// order to support operators composed of custom resources.
Expand Down

0 comments on commit 2d4b5e9

Please sign in to comment.