Skip to content

Commit

Permalink
[opsrc] Fix OperatorSource reconciliation error
Browse files Browse the repository at this point in the history
OperatorSource reconciler fails in 'Configuring' phase if the
following conditions are true:
 - The CatalogSourceConfig object already exists.
 - It is already owned by the OperatorSource object.

The reconciler appends the OperatorSource object to the
OwnerReference list of the CatalogSourceConfig without checking
whether it is already owned by the same OperatorSource. This causes
the Update API to throw an error.

Solution: Remove the given OperatorSource object from the
OwnerReference list to ensure it is not specified more than once

https://bugzilla.redhat.com/show_bug.cgi?id=1672701
  • Loading branch information
tkashem committed Feb 6, 2019
1 parent 486b674 commit 99d1db4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
17 changes: 17 additions & 0 deletions pkg/apis/marketplace/v1alpha1/catalogsourceconfig_types.go
Expand Up @@ -5,6 +5,7 @@ import (

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
)

const (
Expand Down Expand Up @@ -98,3 +99,19 @@ func (csc *CatalogSourceConfig) EnsurePublisher() {
func (csc *CatalogSourceConfig) GetPackageIDs() []string {
return strings.Split(csc.Spec.Packages, ",")
}

// RemoveOwner removes the owner specified in ownerUID from OwnerReference of
// the CatalogSourceConfig object.
func (csc *CatalogSourceConfig) RemoveOwner(ownerUID types.UID) {
owners := make([]metav1.OwnerReference, 0)

for _, owner := range csc.GetOwnerReferences() {
if owner.UID == ownerUID {
continue
}

owners = append(owners, owner)
}

csc.SetOwnerReferences(owners)
}
6 changes: 6 additions & 0 deletions pkg/operatorsource/configuring.go
Expand Up @@ -95,6 +95,12 @@ func (r *configuringReconciler) Reconcile(ctx context.Context, in *v1alpha1.Oper
}

cscExisting.EnsureGVK()

// The existing CatalogSourceConfig might already be owned by this
// OperatorSource object. Let's remove the owner reference, otherwise we
// will be adding it twice.
cscExisting.RemoveOwner(in.GetUID())

builder := CatalogSourceConfigBuilder{object: cscExisting}
cscUpdate := builder.WithSpec(in.Namespace, manifests, in.Spec.DisplayName, in.Spec.Publisher).
WithLabels(in.GetLabels()).
Expand Down

0 comments on commit 99d1db4

Please sign in to comment.