Commit Graph

261 Commits

Author SHA1 Message Date
Jordan Liggitt
1e71a28490 Clean up namespaced children of missing virtual parents with incorrectly cluster-scoped nodes 2021-01-14 11:29:31 -05:00
Jordan Liggitt
65d43faf3a Add unit test for child scope mismatch with missing parent 2021-01-14 10:45:56 -05:00
drfish
4a839fa6d3 Fix typos in garbagecollector_test.go 2020-12-29 23:20:18 +08:00
Jordan Liggitt
e491c3bc70 Add GC unit tests
Adds unit tests covering the problematic scenarios identified
around conflicting data in child owner references

                      Before   After
package level         51%      68%
garbagecollector.go   60%      75%
graph_builder.go      50%      81%
graph.go              50%      68%

Added/improved coverage of key functions that had lacking unit test coverage:

* attemptToDeleteWorker
* attemptToDeleteItem
* processGraphChanges (added coverage of all added code)
2020-11-17 10:49:32 -05:00
Jordan Liggitt
603a0b016e Log cluster-scoped owners referencing namespaced owners, avoid retrying lookups forever
If a cluster-scoped dependent references a namespace-scoped owner,
this is an invalid relationship, and the lookup will never succeed in attemptToDelete.

Short-circuit requeueing in attemptToDelete and log.
2020-11-17 10:49:30 -05:00
Jordan Liggitt
221e4aa2c2 Queue non-matching children for deletion when a virtual node is marked as observed
When we observe valid coordinates for a previously virtual node,
if there are dependents that do not agree with those coordinates,
add them to the attemptToDelete queue.

This queue will check the dependent's ownerReferences using the coordinates specified by the dependent.
If all of the owners can be verified absent, the dependent will be deleted.
If some are still present, or if there are errors looking them up, the dependent will not be deleted.

If the verified owner is namespaced, and the dependent is not in the same namespace,
an event will be recorded for user visibility, since cross-namespace ownerReferences are not supported.
2020-11-17 10:49:27 -05:00
Jordan Liggitt
b655f22509 Handle virtual delete events when children don't agree on owner coordinates
If a virtual delete event is received for a node whose dependents disagree on the parent's coordinates:
1. propagate the delete to children that matched the verified absent coordinates
2. if the existing node is virtual, select a new set of coordinates from the remaining dependents
3. do not delete the parent node from the graph if the parent node is non-virtual,
   or if there are dependents that do not agree with the virtual delete event coordinates
2020-11-17 10:49:07 -05:00
Jordan Liggitt
b8d7ecf73b Make node removal conditional in processGraphChanges 2020-11-17 10:49:04 -05:00
Jordan Liggitt
ac8d419b4c Enqueue dependents for deletion when their ownerReference does not match observed parent coordinates
When adding a dependent to the graph, we ensure there is a node representing each owner reference,
and add the dependent to each parent node.

If the parent node already exists, and the dependent's ownerReference
coordinates disagree with the verified coordinates, add the dependent to the attemptToDelete queue.

This queue will check the dependent's ownerReferences using the coordinates specified by the dependent.
If all of the owners can be verified absent, the dependent will be deleted.
If some are still present, or if there are errors looking them up, the dependent will not be deleted.

If the parent node has been observed via informer event (so we know the coordinates are accurate),
and the verified owner is namespaced, and the dependent is not in the same namespace,
an event will be recorded for user visibility, since cross-namespace ownerReferences are not supported.
2020-11-17 10:47:39 -05:00
Jordan Liggitt
78317edb8b Short-circuit attemptToDelete loop for virtual nodes that are removed or observed
Virtual nodes are added to the attemptToDelete queue, and continue getting requeued
until they are successfully verified absent or are observed via informer.

In the meantime, if the real object associated with that UID is observed via informer,
or is observed to be deleted via informer, the graph node for that UID can be removed
or marked as observed. In that case, we should stop retrying to get the virtual node coordinates.
2020-11-17 10:46:00 -05:00
Jordan Liggitt
cae56bea0a Replace virtual node with observed node if identity differs
If the graph contains a virtual node (because some child object referenced it in an OwnerRef),
and a real informer event is observed for that uid at different coordinates,
we want to fix the coordinates of the node in the graph to match the actual coordinates.

The safe way to do this is to clone the node, replace the identity in the clone,
then replace the node with the clone.

Modifying the identity directly is not safe because it is accessed lock-free from many code paths.

Replacing the node in the graph from processGraphChanges is safe because it is the only graph writer.
2020-11-17 10:42:48 -05:00
Jordan Liggitt
cb7b9ed532 Refactor identityFromEvent 2020-11-17 10:42:48 -05:00
Jordan Liggitt
30eb6683e6 Avoid marking virtual nodes as observed when they haven't been
Virtual nodes can be added to the GC graph in order to represent objects
which have not been observed via an informer, but are referenced via ownerReferences.

These virtual nodes are requeued into attemptToDelete until they are observed via an informer,
or successfully verified absent via a live lookup. Previously, both of those code paths
called markObserved() to stop requeuing into attemptToDelete.

Because it is useful to know whether a particular node has been observed via
a real informer event, this commit does the following:

* adds a `virtual bool` attribute to graph events so we know which ones came from a real informer
* limits the markObserved() call to the code path where a real informer event is observed
* uses an alternative mechanism to stop requeueing into attemptToDelete when a virtual node is verified absent via a live lookup
2020-11-17 10:42:48 -05:00
Jordan Liggitt
445f20dbdb Switch GC absentOwnerCache to full reference
Before deleting an object based on absent owners, GC verifies absence of those owners with a live lookup.

The coordinates used to perform that live lookup are the ones specified in the ownerReference of the child.

In order to performantly delete multiple children from the same parent (e.g. 1000 pods from a replicaset),
a 404 response to a lookup is cached in absentOwnerCache.

Previously, the cache was a simple uid set. However, since children can disagree on the coordinates
that should be used to look up a given uid, the cache should record the exact coordinates verified absent.
This is a [apiVersion, kind, namespace, name, uid] tuple.
2020-11-17 10:42:48 -05:00
Jordan Liggitt
09bdf76b8a Plumb event recorder to garbage collector controller 2020-11-17 10:42:45 -05:00
cici37
a91a2cdad6 Move informer_factory to staging 2020-10-29 12:20:33 -07:00
wangkai1994
b3b95f5ab5 add defer 2020-07-07 10:20:19 +08:00
Lukasz Szaszkiewicz
50db32cf8c GC doesn't have to create monitors in the constructor 2020-06-10 14:59:45 +02:00
tahsinrahman
78318c7a26 Migrate to log calls to klog.InfoS and klog.ErroS for pkg/controller 2020-06-05 13:23:01 +08:00
Davanum Srinivas
07d88617e5
Run hack/update-vendor.sh
Signed-off-by: Davanum Srinivas <davanum@gmail.com>
2020-05-16 07:54:33 -04:00
Davanum Srinivas
442a69c3bd
switch over k/k to use klog v2
Signed-off-by: Davanum Srinivas <davanum@gmail.com>
2020-05-16 07:54:27 -04:00
Jordan Liggitt
04a72d5ef9 client-go metadata: update callers 2020-03-06 11:07:54 -05:00
s-ito-ts
e6b9a7a309 Fix golint errors in pkg/controller/garbagecollector 2020-02-20 04:46:02 +00:00
hwdef
38256df718 pkg/controller: fix staticcheck warning 2019-11-07 16:46:47 +08:00
Kubernetes Prow Robot
6e0c915f43
Merge pull request #84060 from yutedz/gc-ref-diff
Traverse OwnerReference maps more efficiently
2019-11-01 18:07:41 -07:00
wojtekt
7b6bcdf780 Autogenerated code 2019-10-24 20:21:00 +02:00
Ted Yu
0d704f1ce2 Traverse OwnerReference maps more efficiently 2019-10-19 17:56:11 -07:00
zouyee
a864fd2100 fix unsafe JSON construction
Signed-off-by: Zou Nengren <zouyee1989@gmail.com>
2019-10-10 09:44:54 +08:00
Tim Allclair
ef6cba0b36 Always set content-type & nosniff 2019-09-11 15:01:43 -07:00
Yassine TIJANI
7e4c3096fe move WaitForCacheSync to the sharedInformer package
Signed-off-by: Yassine TIJANI <ytijani@vmware.com>
2019-08-22 16:13:41 +01:00
Lukasz Szaszkiewicz
2d81cee900 changes the way gc detect that an object needs to be deleted
before this change, an object would be added to `attemptToDelete` queue only if `gc` detected the transition, simply by check if `deletionTimestamp` was set. After the change, it will check if `foregroundDeletion` finalizer has been set before adding the item to the queue.
2019-08-12 10:52:43 +02:00
David Xia
fabfd950b1
cleanup: fix some log and error capitalizations
Part of https://github.com/kubernetes/kubernetes/issues/15863
2019-07-20 18:26:16 -04:00
Clayton Coleman
637cc83341
Switch the garbage collector to use metadata client and protobuf 2019-07-11 12:18:51 -04:00
Kubernetes Prow Robot
95e3a2576b
Merge pull request #78650 from cwdsuzhou/gc_graph_common
Merge similar funcs
2019-06-14 11:53:02 -07:00
Jordan Liggitt
6a7e7fc156 Fix TestStressingCascadingDeletion flake 2019-06-04 17:26:36 -04:00
caiweidong
0989bfee95 merge common funcs 2019-06-04 16:37:42 +08:00
Chao Xu
369314959c generated 2019-05-24 18:14:53 -07:00
Yu Liao
05ebe91277 Switched to use dynamic shared informer for Garbage Collector. 2019-05-17 15:41:36 -07:00
Humble Chirammal
4d56ab19e4 Remove unwanted conditions from controllers.
Signed-off-by: Humble Chirammal <hchiramm@redhat.com>
2019-05-01 14:13:19 +05:30
Jordan Liggitt
bba9f5e673 Fixup gonum.org/v1/gonum/graph API calls 2019-04-08 15:20:46 -04:00
Kubernetes Prow Robot
f83fcbefb6
Merge pull request #76004 from yue9944882/chore/trival-reserving-error-msg
Fixes reversed owner relation in error msg from garbage collector
2019-04-02 03:04:58 -07:00
yue9944882
0a60d19ebd fixes reversed owner relation in error msg 2019-04-02 12:08:53 +08:00
Clayton Coleman
a63fef26ca
Garbage collector should use a merge patch instead of Update
Fix a TODO in GC controller that blocks using the new
PartialObjectMetadata flow (because we don't support PUT of
PartialObjectMetadata). This patch is equivalent to the previous
mutation.
2019-04-01 11:02:03 -04:00
Jordan Liggitt
8146fe47d8 Clean up test output 2019-03-26 23:15:39 -04:00
stewart-yu
ecbd5427e7 auto-generated file 2019-03-02 12:55:26 +08:00
stewart-yu
e01ff1641c move config local to every controllers in kube-controller-manager 2019-03-02 12:54:33 +08:00
Kubernetes Prow Robot
808f2cf0ef
Merge pull request #72525 from justinsb/owners_should_not_be_executable
Remove executable file permission from OWNERS files
2019-02-14 23:55:45 -08:00
Dr. Stefan Schimanski
618050e35d client-go: extend discovery intf with ServerGroupsAndResources 2019-02-12 14:28:19 +01:00
Kubernetes Prow Robot
b50c643be0
Merge pull request #73540 from rlenferink/patch-5
Updated OWNERS files to include link to docs
2019-02-08 09:05:56 -08:00
Antoine Pelisse
0e1d50e70f API Machinery, Kubectl and tests 2019-02-04 13:51:48 -08:00