Skip to content

Commit

Permalink
fix(installplan): crs are ownerreferenced to their resolving csv
Browse files Browse the repository at this point in the history
  • Loading branch information
njhale committed Mar 3, 2020
1 parent 7697393 commit 0bf2fc4
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions pkg/controller/operators/catalog/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1726,22 +1726,34 @@ func (o *Operator) ExecutePlan(plan *v1alpha1.InstallPlan) error {
Resource: r.Name,
}

// Set up the dynamic client ResourceInterface
owner := &v1alpha1.ClusterServiceVersion{}
owner.SetNamespace(plan.GetNamespace())
owner.SetName(step.Resolving)

// Set up the dynamic client ResourceInterface and set ownerrefs
var resourceInterface dynamic.ResourceInterface
if r.Namespaced {
ownerutil.AddOwner(unstructuredObject, plan, false, false)
unstructuredObject.SetNamespace(namespace)
resourceInterface = o.dynamicClient.Resource(gvr).Namespace(namespace)

// Set OwnerReferences for namespace-scoped resource
ownerutil.AddNonBlockingOwner(unstructuredObject, owner)

// Update UIDs on all CSV OwnerReferences
updated, err := o.getUpdatedOwnerReferences(unstructuredObject.GetOwnerReferences(), plan.Namespace)
if err != nil {
return errorwrap.Wrapf(err, "error generating ownerrefs for unstructured object: %s", unstructuredObject.GetName())
}

unstructuredObject.SetOwnerReferences(updated)
} else {
resourceInterface = o.dynamicClient.Resource(gvr)
}

// Update UIDs on all CSV OwnerReferences
updated, err := o.getUpdatedOwnerReferences(unstructuredObject.GetOwnerReferences(), plan.Namespace)
if err != nil {
return errorwrap.Wrapf(err, "error generating ownerrefs for unstructured object: %s", unstructuredObject.GetName())
// Add owner labels to cluster-scoped resource
if err := ownerutil.AddOwnerLabels(unstructuredObject, owner); err != nil {
return err
}
}
unstructuredObject.SetOwnerReferences(updated)

// Ensure Unstructured Object
status, err := ensurer.EnsureUnstructuredObject(resourceInterface, unstructuredObject)
Expand Down

0 comments on commit 0bf2fc4

Please sign in to comment.