Skip to content

Commit

Permalink
Merge pull request #681 from alecmerdler/ALM-878
Browse files Browse the repository at this point in the history
Ensure Owner References on ConfigMaps for CatalogSources
  • Loading branch information
openshift-merge-robot authored Jan 25, 2019
2 parents 3af3a51 + 81a852c commit 756be5c
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 8 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ require (
k8s.io/klog v0.1.0 // indirect
k8s.io/kube-aggregator v0.0.0-20181204002017-122bac39d429
k8s.io/kube-openapi v0.0.0-20181031203759-72693cb1fadd
k8s.io/kubernetes v1.11.7-beta.0.0.20190118094746-65ecaf067134
k8s.io/kubernetes v1.11.8-beta.0.0.20190124204751-3a10094374f2
)
55 changes: 51 additions & 4 deletions go.sum

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions pkg/controller/operators/catalog/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,10 @@ func (o *Operator) syncCatalogSources(obj interface{}) (syncError error) {
return fmt.Errorf("failed to get catalog config map %s: %s", catsrc.Spec.ConfigMap, err)
}

if wasOwned := ownerutil.EnsureOwner(configMap, catsrc); !wasOwned {
o.OpClient.KubernetesInterface().CoreV1().ConfigMaps(configMap.GetNamespace()).Update(configMap)
}

if catsrc.Status.ConfigMapResource == nil || catsrc.Status.ConfigMapResource.UID != configMap.GetUID() || catsrc.Status.ConfigMapResource.ResourceVersion != configMap.GetResourceVersion() {
logger.Debug("updating catsrc configmap state")
// configmap ref nonexistent or updated, write out the new configmap ref to status and exit
Expand All @@ -364,8 +368,6 @@ func (o *Operator) syncCatalogSources(obj interface{}) (syncError error) {
ResourceVersion: configMap.GetResourceVersion(),
}
out.Status.LastSync = timeNow()

// update status
if _, err = o.client.OperatorsV1alpha1().CatalogSources(out.GetNamespace()).UpdateStatus(out); err != nil {
return err
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/controller/operators/catalog/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorlister"
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/queueinformer"
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/ownerutil"
)

type mockTransitioner struct {
Expand Down Expand Up @@ -368,6 +369,10 @@ func TestSyncCatalogSources(t *testing.T) {
if tt.expectedStatus != nil {
require.NotEmpty(t, updated.Status)
require.Equal(t, *tt.expectedStatus.ConfigMapResource, *updated.Status.ConfigMapResource)

configMap, err := op.OpClient.KubernetesInterface().CoreV1().ConfigMaps(tt.catalogSource.GetNamespace()).Get(tt.catalogSource.Spec.ConfigMap, metav1.GetOptions{})
require.NoError(t, err)
require.True(t, ownerutil.EnsureOwner(configMap, updated))
}
})
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/lib/ownerutil/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,16 @@ func AddOwner(object metav1.Object, owner Owner, blockOwnerDeletion, isControlle
object.SetOwnerReferences(ownerRefs)
}

// EnsureOwner adds a new owner if needed and returns whether the object already had the owner.
func EnsureOwner(object metav1.Object, owner Owner) bool {
if IsOwnedBy(object, owner) {
return true
} else {
AddNonBlockingOwner(object, owner)
return false
}
}

// InferGroupVersionKind adds TypeMeta to an owner so that it can be written to an ownerref.
// TypeMeta is generally only known at serialization time, so we often won't know what GVK an owner has.
// For the types we know about, we can add the GVK of the apis that we're using the interact with the object.
Expand Down
2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ k8s.io/kube-openapi/pkg/generators/rules
k8s.io/kube-openapi/pkg/builder
k8s.io/kube-openapi/pkg/handler
k8s.io/kube-openapi/pkg/util/sets
# k8s.io/kubernetes v1.11.7-beta.0.0.20190118094746-65ecaf067134
# k8s.io/kubernetes v1.11.8-beta.0.0.20190124204751-3a10094374f2
k8s.io/kubernetes/plugin/pkg/auth/authorizer/rbac
k8s.io/kubernetes/pkg/apis/rbac/v1
k8s.io/kubernetes/pkg/registry/rbac/validation
Expand Down

0 comments on commit 756be5c

Please sign in to comment.