Skip to content

Commit

Permalink
controllers: fix secret ownership reference comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
abursavich committed Aug 13, 2019
1 parent 00200de commit 92b2408
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pkg/controllers/configmapsecret_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,21 +204,23 @@ func (r *ConfigMapSecret) setOwner(log logr.Logger, cms *v1alpha1.ConfigMapSecre
return false, err
}
owner := metav1.NewControllerRef(cms, gvk)
for i, ref := range cms.OwnerReferences {
for i, ref := range secret.OwnerReferences {
if ref.Controller == nil || !*ref.Controller {
continue
}
if ref.UID != cms.UID {
log.Error(err, "Secret has a different owner", "owner", ref)
return false, &controllerutil.AlreadyOwnedError{Object: cms, Owner: ref}
}
if ref != *owner { // e.g. apiVersion upgraded
cms.OwnerReferences[i] = *owner
if !reflect.DeepEqual(&ref, owner) { // e.g. apiVersion changed
log.Info("Updating ownership of Secret")
secret.OwnerReferences[i] = *owner
return true, nil
}
return false, nil
}
cms.OwnerReferences = append(cms.OwnerReferences, *owner)
log.Info("Taking ownership of Secret", "owner", *owner)
cms.OwnerReferences = append(secret.OwnerReferences, *owner)
return true, nil
}

Expand Down

0 comments on commit 92b2408

Please sign in to comment.