Skip to content

ConfigMapPropagation should keep other owner references when abandoning a copy configmap#2492

Merged
knative-prow-robot merged 5 commits into
knative:masterfrom
grac3gao-zz:ownerreference
Feb 10, 2020
Merged

ConfigMapPropagation should keep other owner references when abandoning a copy configmap#2492
knative-prow-robot merged 5 commits into
knative:masterfrom
grac3gao-zz:ownerreference

Conversation

@grac3gao-zz
Copy link
Copy Markdown
Contributor

Fixes #2437

Proposed Changes

  • ConfigMapPropagation controller only deletes the CMP owner reference from the ConfigMap, and keeps other owner references (if any)
  • A unit test

Release Note

@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Feb 4, 2020
@knative-prow-robot knative-prow-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Feb 4, 2020
if owner.UID == cmp.UID {
index = i
break
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only find this way to delete an owner reference (by iterating the owner reference array). Not sure if there is other better way to do this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move this to a method in the controller removeOwnerReference so it's easier to read.

Rather than modifying the array in place, it might be simpler to copy each element to a new array, skipping the ref to remove. Code readability is more important than perf here IMO.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That make sense, I just changed it. Thank you.

}

// removeOwnerReference removes the target ownerReference and returns a new slice of ownerReferences.
func (r *Reconciler) removeOwnerReference(ownerReferences []metav1.OwnerReference, uid types.UID) []metav1.OwnerReference {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for this to be a method. Since it doesn't use r it can just be a package-level function.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

var expected []metav1.OwnerReference
for _, owner := range ownerReferences {
if owner.UID != uid {
expected = append(expected, *owner.DeepCopy())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the object itself isn't being modified, just the slice, I'd expect append(expected, owner) to work fine here. Why use DeepCopy?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@knative-metrics-robot
Copy link
Copy Markdown

The following is the coverage report on the affected files.
Say /test pull-knative-eventing-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/reconciler/configmappropagation/configmappropagation.go 89.2% 89.6% 0.4

Copy link
Copy Markdown
Contributor

@grantr grantr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @grac3gao!

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Feb 10, 2020
@knative-prow-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: grac3gao, grantr

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 10, 2020
@knative-prow-robot knative-prow-robot merged commit 1f0e962 into knative:master Feb 10, 2020
@grac3gao-zz grac3gao-zz deleted the ownerreference branch February 18, 2020 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ConfigMapPropagation deletes all OwnerReferences when abandoning a copy

6 participants