Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscription replace should annotate the objects like a normal subscription. #293

Merged
merged 2 commits into from
Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions pkg/synchronizer/kubernetes/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -784,11 +784,10 @@ var _ = Describe("test resource overwrite", func() {
// age field should be deleted because the reconcile option was replace
Expect(cm.Data["age"]).Should(Equal(""))

// The hosting annotations should not be added when existing resource, that is not owned by the subscription,
// gets overwritten
// If reconcile option is replace, the hosting annotations should added to existing resource, that is not owned by the subscription.
cmAnnotations = cm.GetAnnotations()
Expect(cmAnnotations["apps.open-cluster-management.io/hosting-deployable"]).To(Equal(""))
Expect(cmAnnotations["apps.open-cluster-management.io/hosting-subscription"]).To(Equal(""))
Expect(cmAnnotations["apps.open-cluster-management.io/hosting-deployable"]).To(Equal(configMapSharedkey.Namespace + "/" + configMapSharedkey.Name))
Expect(cmAnnotations["apps.open-cluster-management.io/hosting-subscription"]).To(Equal(configMapSharedkey.Namespace + "/" + configMapSharedkey.Name))
})

It("resource owned by others can be merged by subscription", func() {
Expand Down Expand Up @@ -865,7 +864,7 @@ var _ = Describe("test resource overwrite", func() {
// age field should be kept because the reconcile option was merge
Expect(cm.Data["age"]).Should(Equal("19"))

// The hosting annotations should not be added when existing resource, that is not owned by the subscription,
// With merge option, the hosting annotations should not be added when existing resource, that is not owned by the subscription,
// gets overwritten
cmAnnotations = cm.GetAnnotations()
Expect(cmAnnotations["apps.open-cluster-management.io/hosting-deployable"]).To(Equal(""))
Expand Down
6 changes: 5 additions & 1 deletion pkg/synchronizer/kubernetes/synchronizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,11 @@ func (sync *KubeSynchronizer) updateResourceByTemplateUnit(ri dynamic.ResourceIn
newobj := tplunit.Unstructured.DeepCopy()
newobj.SetResourceVersion(obj.GetResourceVersion())

if overwrite {
// If subscription-admin chooses merge option, remove the typical annotations we add. This will avoid the resources being
// deleted when the subscription is removed.
// If subscription-admin chooses replace option, keep the typical annotations we add. Subscription takes over the resources.
// When the subscription is removed, the resources will be removed too.
if overwrite && merge {
// If overwriting someone else's resource, remove annotations like hosting subscription, hostring deployables... etc
newobj = utils.RemoveSubAnnotations(newobj)
newobj = utils.RemoveSubOwnerRef(newobj)
Expand Down