Commit Graph

277 Commits

Author SHA1 Message Date
atiratree
2fc401d0a2 add gc metrics and collect sync errors 2022-02-04 20:21:30 +01:00
jlsong01
d66b3edd65 allocate a unique scheme for each test to fix concurrent usage issue 2022-02-02 15:22:59 +08:00
Kubernetes Prow Robot
3bd422dc76
Merge pull request #107293 from dims/jan-1-owners-cleanup
Cleanup OWNERS files - Jan 2021 Week 1
2022-01-13 10:30:30 -08:00
Davanum Srinivas
9682b7248f
OWNERS cleanup - Jan 2021 Week 1
Signed-off-by: Davanum Srinivas <davanum@gmail.com>
2022-01-10 08:14:29 -05:00
astraw99
a5a54754d5 refactor garbagecollection controllers to make forget impossible to forget 2022-01-09 15:19:10 +08:00
Kubernetes Prow Robot
8324868f89
Merge pull request #106950 from sunzhaochang/fix-unexpected-end-test
Fix unexpected end of TestDependentsRace
2021-12-14 15:16:49 -08:00
sunzhaochang
f0e74bfb7f Fix unexpected end of TestDependentsRace 2021-12-10 20:07:37 +08:00
Davanum Srinivas
9405e9b55e
Check in OWNERS modified by update-yamlfmt.sh
Signed-off-by: Davanum Srinivas <davanum@gmail.com>
2021-12-09 21:31:26 -05:00
Mikhail Mazurskiy
de4598d0db
ResettableRESTMapper to make it possible to reset wrapped mappers 2021-11-06 10:44:02 +11:00
Manu Gupta
79a51090f9
fix: 81134: fix unsafe json for ReleaseControllerRevision (#104049)
* fix: 81134: fix unsafe json for ReleaseControllerRevision

1. Ensures that ReleaseControllerRevision returns a proper json by
marshalling an object into bytes. Otherwise, it returns an error.

2. Also, refactors the code to commonize the merge type
   GenerateDeleteOwnerRefStrategicMergeBytes that returns a byte and is
   used across ReleasePod, ReleaseControllerRevison
   ReleaseReplicaSet.

* Move GeneratePatchBytesForDelete to controller_ref_manager
2021-11-05 06:33:52 -07:00
Mike Dame
4960d0976a Wire contexts to Core controllers 2021-11-01 10:29:00 -04:00
Kubernetes Prow Robot
8ac9526475
Merge pull request #101928 from alexanderConstantinescu/drain-workqueue
client-go/workqueue: Drain work queue on shutdown
2021-09-10 18:02:06 -07:00
Jiahui Feng
8f5771d243 use common controller interface in KCM. 2021-08-25 13:29:03 -07:00
Stephen Augustus
481cf6fbe7
generated: Run hack/update-gofmt.sh
Signed-off-by: Stephen Augustus <foo@auggie.dev>
2021-08-24 15:47:49 -04:00
Alexander Constantinescu
5b740f430e [queue] Implement ShutDownWithDrain allowing the queue to drain when shutting down
Signed-off-by: Alexander Constantinescu <aconstan@redhat.com>
2021-08-20 13:59:12 +02:00
Benjamin Elder
56e092e382 hack/update-bazel.sh 2021-02-28 15:17:29 -08:00
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