Skip to content
This repository has been archived by the owner on Jul 22, 2022. It is now read-only.

Fix deletion of namespaced children #124

Closed
wants to merge 1 commit into from

Conversation

mgruener
Copy link

@mgruener mgruener commented Dec 17, 2018

Bugfix for the deletion of namespaced child resources.

When a cluster scoped parent resource manages namespace scoped child resources, the Delete() method gets passed the namespaced resource name in the format {.metadata.namespace}/{.metadata.name} instead of just the resource name.

This results in errors of the form

[[ can't delete <resource> <namespace>/<resource name>: the server could not find the requested resource] the server could not find the requested resource]

This PR ensures that the Delete() functions gets passed the resource name without the namespace part.

Fixes #127

@@ -166,11 +166,15 @@ func deleteChildren(client *dynamicclientset.ResourceClient, parent *unstructure
// Skip objects that are already pending deletion.
continue
}
ns := obj.GetNamespace()
Copy link

Choose a reason for hiding this comment

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

I think @silverlyra had it right on #128 that we should trust the existing value of obj.GetNamespace() here.

Below in updateChildren, we are looping over desired objects, which contain only whatever fields the hook decided to fill in. In that case, we allow the hook to leave the namespace empty and we will default it to the parent namespace.

By contrast, here we are looping over observed objects, which are fetched from the API server, and as such have all required fields and defaults materialized. If an observed object has an empty namespace, we should trust that it's supposed to be empty, meaning it's cluster-scoped.

@enisoc
Copy link

enisoc commented Jan 15, 2019

I went ahead and merged #128 since it was already what you'd get after addressing review comments on this PR. Thanks for the fix though and sorry for the slow response. I was out on leave but back now and trying to catch up on the backlog.

@enisoc enisoc closed this Jan 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

A cluster-scoped controller cannot update or delete namespaced resources
2 participants