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

Don't force requeuing after adding finalizer in GitRepo controller #3284

Closed

Conversation

0xavi0
Copy link
Contributor

@0xavi0 0xavi0 commented Jan 30, 2025

This change is meant to avoid an extra Reconcile call when adding the finalizer to GitRepo. The reconciler will get called anyway because generation changes and, also because generation changes, we'll avoid an extra call to the polling function.

See below the difference of with and without the change. I've added a new extra log lines to show the difference (that are not part of this pull request)

without change

2025-01-30T13:45:49Z	INFO	gitjob	TESTFINALIZER Reconciling GitRepo	{"controller": "gitrepo", "controllerGroup": "fleet.cattle.io", "controllerKind": "GitRepo", "GitRepo": {"name":"simple","namespace":"fleet-local"}, "namespace": "fleet-local", "name": "simple", "reconcileID": "5517b2f5-2d4e-415b-b0e5-859cc070d9af"}
2025-01-30T13:45:49Z	INFO	gitjob	TESTFINALIZER -- finalizer added	{"controller": "gitrepo", "controllerGroup": "fleet.cattle.io", "controllerKind": "GitRepo", "GitRepo": {"name":"simple","namespace":"fleet-local"}, "namespace": "fleet-local", "name": "simple", "reconcileID": "5517b2f5-2d4e-415b-b0e5-859cc070d9af"}
2025-01-30T13:45:49Z	INFO	gitjob	TESTFINALIZER Reconciling GitRepo	{"controller": "gitrepo", "controllerGroup": "fleet.cattle.io", "controllerKind": "GitRepo", "GitRepo": {"name":"simple","namespace":"fleet-local"}, "namespace": "fleet-local", "name": "simple", "reconcileID": "94d228b5-c018-46af-9b69-b04b17ed976a"}
2025-01-30T13:45:49Z	INFO	gitjob	TESTFINALIZER --- GitRepo polled	{"controller": "gitrepo", "controllerGroup": "fleet.cattle.io", "controllerKind": "GitRepo", "GitRepo": {"name":"simple","namespace":"fleet-local"}, "namespace": "fleet-local", "name": "simple", "reconcileID": "94d228b5-c018-46af-9b69-b04b17ed976a", "generation": 2, "commit": "", "conditions": null}
2025-01-30T13:45:49Z	INFO	gitjob	TESTFINALIZER Reconciling GitRepo	{"controller": "gitrepo", "controllerGroup": "fleet.cattle.io", "controllerKind": "GitRepo", "GitRepo": {"name":"simple","namespace":"fleet-local"}, "namespace": "fleet-local", "name": "simple", "reconcileID": "1c71ae46-ea6b-452c-8896-704293f24584"}
2025-01-30T13:45:49Z	INFO	gitjob	TESTFINALIZER --- GitRepo polled	{"controller": "gitrepo", "controllerGroup": "fleet.cattle.io", "controllerKind": "GitRepo", "GitRepo": {"name":"simple","namespace":"fleet-local"}, "namespace": "fleet-local", "name": "simple", "reconcileID": "1c71ae46-ea6b-452c-8896-704293f24584", "generation": 2, "commit": "", "conditions": [{"type":"Ready","status":"True","lastUpdateTime":"2025-01-30T13:45:49Z"}]}

GitRepo is polled twice.

with change

2025-01-30T13:54:19Z	INFO	gitjob	TESTFINALIZER Reconciling GitRepo	{"controller": "gitrepo", "controllerGroup": "fleet.cattle.io", "controllerKind": "GitRepo", "GitRepo": {"name":"simple","namespace":"fleet-local"}, "namespace": "fleet-local", "name": "simple", "reconcileID": "4cb52a70-d552-4cda-85f7-058a9d129e1f"}
2025-01-30T13:54:19Z	INFO	gitjob	TESTFINALIZER -- finalizer added	{"controller": "gitrepo", "controllerGroup": "fleet.cattle.io", "controllerKind": "GitRepo", "GitRepo": {"name":"simple","namespace":"fleet-local"}, "namespace": "fleet-local", "name": "simple", "reconcileID": "4cb52a70-d552-4cda-85f7-058a9d129e1f"}
2025-01-30T13:54:19Z	INFO	gitjob	TESTFINALIZER Reconciling GitRepo	{"controller": "gitrepo", "controllerGroup": "fleet.cattle.io", "controllerKind": "GitRepo", "GitRepo": {"name":"simple","namespace":"fleet-local"}, "namespace": "fleet-local", "name": "simple", "reconcileID": "52cce150-c17c-4242-acb8-6b05ba3ecd58"}
2025-01-30T13:54:19Z	INFO	gitjob	TESTFINALIZER --- GitRepo polled	{"controller": "gitrepo", "controllerGroup": "fleet.cattle.io", "controllerKind": "GitRepo", "GitRepo": {"name":"simple","namespace":"fleet-local"}, "namespace": "fleet-local", "name": "simple", "reconcileID": "52cce150-c17c-4242-acb8-6b05ba3ecd58", "generation": 2, "commit": "", "conditions": null}

GitRepo is only polled 1 time

This change is meant to avoid an extra `Reconcile` call when adding the finalizer to `GitRepo`.
The reconciler will get called anyway because generation changes and, also because generation changes, we'll avoid an extra call to the polling function.

See below the difference of with and without the change.
I've added a new extra log lines to show the difference (that are not part of this pull request)

**without change**
```bash
2025-01-30T13:45:49Z	INFO	gitjob	TESTFINALIZER Reconciling GitRepo	{"controller": "gitrepo", "controllerGroup": "fleet.cattle.io", "controllerKind": "GitRepo", "GitRepo": {"name":"simple","namespace":"fleet-local"}, "namespace": "fleet-local", "name": "simple", "reconcileID": "5517b2f5-2d4e-415b-b0e5-859cc070d9af"}
2025-01-30T13:45:49Z	INFO	gitjob	TESTFINALIZER -- finalizer added	{"controller": "gitrepo", "controllerGroup": "fleet.cattle.io", "controllerKind": "GitRepo", "GitRepo": {"name":"simple","namespace":"fleet-local"}, "namespace": "fleet-local", "name": "simple", "reconcileID": "5517b2f5-2d4e-415b-b0e5-859cc070d9af"}
2025-01-30T13:45:49Z	INFO	gitjob	TESTFINALIZER Reconciling GitRepo	{"controller": "gitrepo", "controllerGroup": "fleet.cattle.io", "controllerKind": "GitRepo", "GitRepo": {"name":"simple","namespace":"fleet-local"}, "namespace": "fleet-local", "name": "simple", "reconcileID": "94d228b5-c018-46af-9b69-b04b17ed976a"}
2025-01-30T13:45:49Z	INFO	gitjob	TESTFINALIZER --- GitRepo polled	{"controller": "gitrepo", "controllerGroup": "fleet.cattle.io", "controllerKind": "GitRepo", "GitRepo": {"name":"simple","namespace":"fleet-local"}, "namespace": "fleet-local", "name": "simple", "reconcileID": "94d228b5-c018-46af-9b69-b04b17ed976a", "generation": 2, "commit": "", "conditions": null}
2025-01-30T13:45:49Z	INFO	gitjob	TESTFINALIZER Reconciling GitRepo	{"controller": "gitrepo", "controllerGroup": "fleet.cattle.io", "controllerKind": "GitRepo", "GitRepo": {"name":"simple","namespace":"fleet-local"}, "namespace": "fleet-local", "name": "simple", "reconcileID": "1c71ae46-ea6b-452c-8896-704293f24584"}
2025-01-30T13:45:49Z	INFO	gitjob	TESTFINALIZER --- GitRepo polled	{"controller": "gitrepo", "controllerGroup": "fleet.cattle.io", "controllerKind": "GitRepo", "GitRepo": {"name":"simple","namespace":"fleet-local"}, "namespace": "fleet-local", "name": "simple", "reconcileID": "1c71ae46-ea6b-452c-8896-704293f24584", "generation": 2, "commit": "", "conditions": [{"type":"Ready","status":"True","lastUpdateTime":"2025-01-30T13:45:49Z"}]}
```

`GitRepo` is polled twice. 1 time with generation=1 and the second with generation=2

**with change**
```bash
2025-01-30T13:54:19Z	INFO	gitjob	TESTFINALIZER Reconciling GitRepo	{"controller": "gitrepo", "controllerGroup": "fleet.cattle.io", "controllerKind": "GitRepo", "GitRepo": {"name":"simple","namespace":"fleet-local"}, "namespace": "fleet-local", "name": "simple", "reconcileID": "4cb52a70-d552-4cda-85f7-058a9d129e1f"}
2025-01-30T13:54:19Z	INFO	gitjob	TESTFINALIZER -- finalizer added	{"controller": "gitrepo", "controllerGroup": "fleet.cattle.io", "controllerKind": "GitRepo", "GitRepo": {"name":"simple","namespace":"fleet-local"}, "namespace": "fleet-local", "name": "simple", "reconcileID": "4cb52a70-d552-4cda-85f7-058a9d129e1f"}
2025-01-30T13:54:19Z	INFO	gitjob	TESTFINALIZER Reconciling GitRepo	{"controller": "gitrepo", "controllerGroup": "fleet.cattle.io", "controllerKind": "GitRepo", "GitRepo": {"name":"simple","namespace":"fleet-local"}, "namespace": "fleet-local", "name": "simple", "reconcileID": "52cce150-c17c-4242-acb8-6b05ba3ecd58"}
2025-01-30T13:54:19Z	INFO	gitjob	TESTFINALIZER --- GitRepo polled	{"controller": "gitrepo", "controllerGroup": "fleet.cattle.io", "controllerKind": "GitRepo", "GitRepo": {"name":"simple","namespace":"fleet-local"}, "namespace": "fleet-local", "name": "simple", "reconcileID": "52cce150-c17c-4242-acb8-6b05ba3ecd58", "generation": 2, "commit": "", "conditions": null}
```

`GitRepo` is only polled 1 time when generation=2

Signed-off-by: Xavi Garcia <[email protected]>
Signed-off-by: Xavi Garcia <[email protected]>
Signed-off-by: Xavi Garcia <[email protected]>
@0xavi0 0xavi0 force-pushed the dont-requeue-after-adding-finalizer branch from 51d989d to 8e84d54 Compare January 31, 2025 12:51
Changes ImageScanCommit to a pointer because otherwise default values are stored on the first time a `GitRepo` is updated and generation is changed, which means another call to the reconciler.

This creates a double call to fetch for new commits (poll the `GitRepo`) when a `GitRepo` is added.

On the first time it will poll because `LastPollingTime` in Status is not set yet.
And the second time it will fetch for new commits is when generations changes from 1 to 2 (which is almost immediate after the `GitRepo` is updated to add the finalizer.

Signed-off-by: Xavi Garcia <[email protected]>
@0xavi0
Copy link
Contributor Author

0xavi0 commented Feb 5, 2025

Closing for clarity and following in: #3302

@0xavi0 0xavi0 closed this Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant