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

⚠ Support shutdown watches dynamically (v2) #2159

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

inteon
Copy link
Member

@inteon inteon commented Jan 31, 2023

⚠️ depends on #2315

PTAL at the original PR: #2099

I started making some small changes to the original PR, thinking there would be an easy fix. However, it turned out that there were still a lot of fundamental questions requiring more time and effort to get fixed.

The current state of the PR is best described by #2159 (comment).

(4/4) PR chain:

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jan 31, 2023
@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jan 31, 2023
@k8s-ci-robot
Copy link
Contributor

Hi @inteon. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Jan 31, 2023
@inteon inteon changed the title Support shutdown controllers and watches dynamically (v2) ⚠ Support shutdown controllers and watches dynamically (v2) Jan 31, 2023
Copy link
Contributor

@FillZpp FillZpp left a comment

Choose a reason for hiding this comment

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

Thanks @inteon , nice work!

It seems you have removed the Stop() from Controller, so how should users stop one or more specific controller?

pkg/internal/source/kind.go Outdated Show resolved Hide resolved
pkg/internal/source/kind.go Outdated Show resolved Hide resolved
@FillZpp
Copy link
Contributor

FillZpp commented Feb 1, 2023

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Feb 1, 2023
@inteon
Copy link
Member Author

inteon commented Feb 1, 2023

Thanks @inteon , nice work!

It seems you have removed the Stop() from Controller, so how should users stop one or more specific controller?

@FillZpp what do you think about a more generic solution for canceling runnables:

// NewCancelRunnable returns a new Runnable and a function to cancel that runnable.
func NewCancelRunnable(r Runnable) (Runnable, context.CancelFunc) {
	mu := sync.Mutex{}
	cancel := (func())(nil)
	canceled := false

	return RunnableFunc(func(ctx context.Context) error {
			mu.Lock()
			ctx, cancel = context.WithCancel(ctx)
			if canceled {
				cancel()
			}
			mu.Unlock()

			return r.Start(ctx)
		}), func() {
			mu.Lock()
			defer mu.Unlock()
			canceled = true
			if cancel != nil {
				cancel()
			}
		}
}

@FillZpp
Copy link
Contributor

FillZpp commented Feb 1, 2023

Thanks @inteon , nice work!
It seems you have removed the Stop() from Controller, so how should users stop one or more specific controller?

@FillZpp what do you think about a more generic solution for canceling runnables:

// NewCancelRunnable returns a new Runnable and a function to cancel that runnable.
func NewCancelRunnable(r Runnable) (Runnable, context.CancelFunc) {
	mu := sync.Mutex{}
	cancel := (func())(nil)
	canceled := false

	return RunnableFunc(func(ctx context.Context) error {
			mu.Lock()
			ctx, cancel = context.WithCancel(ctx)
			if canceled {
				cancel()
			}
			mu.Unlock()

			return r.Start(ctx)
		}), func() {
			mu.Lock()
			defer mu.Unlock()
			canceled = true
			if cancel != nil {
				cancel()
			}
		}
}

Emm, I think it's alright. It may not be intuitive as the Stop method, but more generic as you said.

@FillZpp
Copy link
Contributor

FillZpp commented Feb 1, 2023

/label tide/merge-method-squash

@k8s-ci-robot k8s-ci-robot added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Feb 1, 2023
@FillZpp
Copy link
Contributor

FillZpp commented Feb 2, 2023

fixes #1884

pkg/manager/manager.go Outdated Show resolved Hide resolved
pkg/manager/manager.go Outdated Show resolved Hide resolved
pkg/source/source.go Outdated Show resolved Hide resolved
@inteon inteon force-pushed the dynamic_source branch 2 times, most recently from f57dd5d to a169245 Compare February 14, 2023 11:47
pkg/internal/controller/controller.go Outdated Show resolved Hide resolved
pkg/internal/controller/controller.go Outdated Show resolved Hide resolved
pkg/internal/controller/controller.go Outdated Show resolved Hide resolved
pkg/manager/manager.go Outdated Show resolved Hide resolved
pkg/manager/manager.go Outdated Show resolved Hide resolved
pkg/source/source.go Outdated Show resolved Hide resolved
pkg/source/source.go Outdated Show resolved Hide resolved
pkg/internal/controller/controller.go Outdated Show resolved Hide resolved
pkg/internal/controller/controller_test.go Outdated Show resolved Hide resolved
@lou-lan
Copy link

lou-lan commented Nov 8, 2023

@inteon Thank you for your contribution with this PR. I've noticed that this PR seems to have not been updated for a while. I believe this PR is very important for the enhancement of this project, and I also have use cases for this feature. If there is any way I can help, such as conducting code reviews or assisting with testing, I would be more than happy to contribute.

@inteon inteon requested a review from FillZpp November 16, 2023 16:48
@inteon
Copy link
Member Author

inteon commented Nov 16, 2023

@lou-lan I'm not sure what is blocking this PR.
I resolved the remaining issues and challenges.
Looking for a final review from @vincepri @sbueringer or @FillZpp

@alvaroaleman
Copy link
Member

Sorry, I don't understand this change. Contrary to what the title claims, it never stops any watch, it stops the source. How does that help? Please provide a real-world use-case.

If this is supposed to work towards allowing to stop watches by refcounting if they have eventhandlers or are otherwise used, I'd like to see a description somewhere as to how exactly this will work once all pieces are done.

@inteon
Copy link
Member Author

inteon commented Dec 27, 2023

Sorry, I don't understand this change. Contrary to what the title claims, it never stops any watch, it stops the source. How does that help? Please provide a real-world use-case.

If this is supposed to work towards allowing to stop watches by refcounting if they have eventhandlers or are otherwise used, I'd like to see a description somewhere as to how exactly this will work once all pieces are done.

@alvaroaleman I just added a StopWatch function to expose this functionality via the Controller API (see 6c16925).
This integration test should be a good example on how this PR can be used:
6c16925#diff-c1c23edcf40f177710028c953468fd5bf7aa0f32d67780354c609e127603bb04

@inteon
Copy link
Member Author

inteon commented Dec 27, 2023

/test pull-controller-runtime-test

Signed-off-by: Tim Ramlot <42113979+inteon@users.noreply.github.com>
@inteon inteon force-pushed the dynamic_source branch 5 times, most recently from 093d2ce to cc38429 Compare February 13, 2024 21:41
inteon and others added 3 commits February 13, 2024 22:57
Signed-off-by: Tim Ramlot <42113979+inteon@users.noreply.github.com>
Signed-off-by: Tim Ramlot <42113979+inteon@users.noreply.github.com>
Co-authored-by: FillZpp <FillZpp.pub@gmail.com>
Signed-off-by: Tim Ramlot <42113979+inteon@users.noreply.github.com>
@inteon
Copy link
Member Author

inteon commented Feb 13, 2024

/retest

@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented Feb 13, 2024

@inteon: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-controller-runtime-apidiff-master a169245 link false /test pull-controller-runtime-apidiff-master
pull-controller-runtime-apidiff b50828a link false /test pull-controller-runtime-apidiff

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet