Skip to content

Commit 288734f

Browse files
committed
disown copied csvs
remove the label from any copied csv if it has been previously adopted Signed-off-by: Evan Cordell <[email protected]>
1 parent 98e3110 commit 288734f

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

pkg/controller/operators/adoption_controller.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,12 @@ func (r *AdoptionReconciler) ReconcileClusterServiceVersion(ctx context.Context,
187187
return reconcile.Result{}, err
188188
}
189189

190+
// disown copied csvs - a previous release inadvertently adopted them, this cleans any up if they are adopted
191+
if in.IsCopied() {
192+
err := r.disownFromAll(ctx, in)
193+
return reconcile.Result{}, err
194+
}
195+
190196
// Adopt all resources owned by the CSV if necessary
191197
return reconcile.Result{}, r.adoptComponents(ctx, in)
192198
}
@@ -315,6 +321,31 @@ func (r *AdoptionReconciler) disown(ctx context.Context, operator *decorators.Op
315321
return r.Patch(ctx, uCObj, client.MergeFrom(cObj))
316322
}
317323

324+
func (r *AdoptionReconciler) disownFromAll(ctx context.Context, component runtime.Object) error {
325+
cObj, ok := component.(client.Object)
326+
if !ok {
327+
return fmt.Errorf("Unable to typecast runtime.Object to client.Object")
328+
}
329+
var operators []decorators.Operator
330+
for _, name := range decorators.OperatorNames(cObj.GetLabels()) {
331+
o := &operatorsv1.Operator{}
332+
o.SetName(name.Name)
333+
operator, err := r.factory.NewOperator(o)
334+
if err != nil {
335+
return err
336+
}
337+
operators = append(operators, *operator)
338+
}
339+
errs := make([]error,0)
340+
for _, operator := range operators {
341+
if err := r.disown(ctx, &operator, component); err != nil {
342+
errs = append(errs, err)
343+
}
344+
}
345+
346+
return utilerrors.NewAggregate(errs)
347+
}
348+
318349
func (r *AdoptionReconciler) adoptees(ctx context.Context, operator decorators.Operator, csv *operatorsv1alpha1.ClusterServiceVersion) ([]runtime.Object, error) {
319350
// Note: We need to figure out how to dynamically add new list types here (or some equivalent) in
320351
// order to support operators composed of custom resources.

0 commit comments

Comments
 (0)