Skip to content

Commit

Permalink
template-processors/base/bin: don't try deleting ComponentStatus objects
Browse files Browse the repository at this point in the history
This commit works around a problem mentioned in
kubernetes/kubectl#151 (comment):

    > > For some reason when I add a label selector that should not match
    > > anything to the command [...], it returns 3 ComponentStatus items:
    > >
    > >     $ kubectl get $(kubectl api-resources --verbs=list -o name | paste -sd, -) --ignore-not-found --all-namespaces -l random=label
    > >     NAME                                 AGE
    > >     componentstatus/controller-manager   <unknown>
    > >     componentstatus/scheduler            <unknown>
    > >     componentstatus/etcd-0               <unknown>
    >
    > ComponentStatus is an unusual API with a custom list
    > implementation, and did not pay any attention to label selectors
    > until kubernetes/kubernetes#78438 fixed that in 1.17

As a result of the above issue, ComponentStatus items leak into
`ownedKinds` and further into the attempted `kubectl delete` operation,
where they tend to trigger an unnecessary error (because deleting them
is forbidden). The ComponentStatus is a readonly "feature" of
Kubernetes, so we won't ever expect to try and delete it purposefully
anyway, see e.g.:
https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.10/#componentstatus-v1-core

Therefore, this commit filters out the ComponentStatus kind explicitly
from the list of `ownedKinds` to consider for deletion.
  • Loading branch information
Mateusz Czapliński committed Dec 12, 2019
1 parent 4038f1d commit f91a111
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion template-processors/base/bin/resourceManager.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ function addLabels {
function deleteByOldLabels {
local owner="$1"
local timestamp="$2"
local allKinds="$(kube api-resources --verbs=list -o name | paste -sd, -)"
# NOTE: removing componentstatus because it shows up unintended in ownedKinds: https://github.com/kubernetes/kubectl/issues/151#issuecomment-562578617
local allKinds="$(kube api-resources --verbs=list -o name | grep -ivw componentstatus | paste -sd, -)"
local ownedKinds="$(kube get "$allKinds" --ignore-not-found \
-l "$TAG_OWNER==$owner" \
-o custom-columns=kind:.kind \
Expand Down

0 comments on commit f91a111

Please sign in to comment.