-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
⚠️ Refactor source/handler/predicate packages to remove dep injection #2120
Changes from all commits
d6a053f
c6fbc02
ad96c14
1c3b223
36ef9e1
b324b0b
ea1fcf3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,7 +118,7 @@ var _ = Describe("application", func() { | |
Expect(err).NotTo(HaveOccurred()) | ||
|
||
instance, err := ControllerManagedBy(m). | ||
Watches(&source.Kind{Type: &appsv1.ReplicaSet{}}, &handler.EnqueueRequestForObject{}). | ||
Watches(source.Kind(m.GetCache(), &appsv1.ReplicaSet{}), &handler.EnqueueRequestForObject{}). | ||
Build(noop) | ||
Expect(err).To(MatchError(ContainSubstring("one of For() or Named() must be called"))) | ||
Expect(instance).To(BeNil()) | ||
|
@@ -157,7 +157,7 @@ var _ = Describe("application", func() { | |
|
||
instance, err := ControllerManagedBy(m). | ||
Named("my_controller"). | ||
Watches(&source.Kind{Type: &appsv1.ReplicaSet{}}, &handler.EnqueueRequestForObject{}). | ||
Watches(source.Kind(m.GetCache(), &appsv1.ReplicaSet{}), &handler.EnqueueRequestForObject{}). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is now the new experience on how to create a controller in a manager. Over time, the builder has increased the options we're passing in, which is ok, but we've also had to deal with all of the dependency injection stuff which isn't pretty at all. This UX might be a stopgap, but it's actually nicer to be explicit where a source is getting its cache or any other function. In a follow-up PR we might want to explore easier ways to plow through this information when we're clearly building a controller in a Manager, and make the source aware that it can access whatever it needs through the manager. For now, we can keep this as a first step breaking change and iterate on it as we see fit. The clarity might come handy in the future when we reason through the codebase. |
||
Build(noop) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(instance).NotTo(BeNil()) | ||
|
@@ -369,8 +369,9 @@ var _ = Describe("application", func() { | |
bldr := ControllerManagedBy(m). | ||
For(&appsv1.Deployment{}). | ||
Watches( // Equivalent of Owns | ||
&source.Kind{Type: &appsv1.ReplicaSet{}}, | ||
&handler.EnqueueRequestForOwner{OwnerType: &appsv1.Deployment{}, IsController: true}) | ||
source.Kind(m.GetCache(), &appsv1.ReplicaSet{}), | ||
handler.EnqueueRequestForOwner(m.GetScheme(), m.GetRESTMapper(), &appsv1.Deployment{}, handler.OnlyControllerOwner()), | ||
) | ||
|
||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
@@ -384,10 +385,11 @@ var _ = Describe("application", func() { | |
bldr := ControllerManagedBy(m). | ||
Named("Deployment"). | ||
Watches( // Equivalent of For | ||
&source.Kind{Type: &appsv1.Deployment{}}, &handler.EnqueueRequestForObject{}). | ||
source.Kind(m.GetCache(), &appsv1.Deployment{}), &handler.EnqueueRequestForObject{}). | ||
Watches( // Equivalent of Owns | ||
&source.Kind{Type: &appsv1.ReplicaSet{}}, | ||
&handler.EnqueueRequestForOwner{OwnerType: &appsv1.Deployment{}, IsController: true}) | ||
source.Kind(m.GetCache(), &appsv1.ReplicaSet{}), | ||
handler.EnqueueRequestForOwner(m.GetScheme(), m.GetRESTMapper(), &appsv1.Deployment{}, handler.OnlyControllerOwner()), | ||
) | ||
|
||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
@@ -481,7 +483,7 @@ var _ = Describe("application", func() { | |
bldr := ControllerManagedBy(mgr). | ||
For(&appsv1.Deployment{}, OnlyMetadata). | ||
Owns(&appsv1.ReplicaSet{}, OnlyMetadata). | ||
Watches(&source.Kind{Type: &appsv1.StatefulSet{}}, | ||
Watches(source.Kind(mgr.GetCache(), &appsv1.StatefulSet{}), | ||
handler.EnqueueRequestsFromMapFunc(func(o client.Object) []reconcile.Request { | ||
defer GinkgoRecover() | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -139,11 +139,6 @@ func NewUnmanaged(name string, mgr manager.Manager, options Options) (Controller | |
options.RateLimiter = workqueue.DefaultControllerRateLimiter() | ||
} | ||
|
||
// Inject dependencies into Reconciler | ||
if err := mgr.SetFields(options.Reconciler); err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pretty sure this will break people, as Kubebuilder at least used to scaffold in a way that this ended up being done, not sure if that is still the case today. You sure you want to just remove this instead of warn for one release if any of the things end up getting injected? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, these fields have been deprecated since 0.10; it's better to not linger the support for dependency injection longer. We can do a couple of things to avoid breaking, including giving a heads up to folks in the mailing list. |
||
return nil, err | ||
} | ||
|
||
if options.RecoverPanic == nil { | ||
options.RecoverPanic = mgr.GetControllerOptions().RecoverPanic | ||
} | ||
|
@@ -156,7 +151,6 @@ func NewUnmanaged(name string, mgr manager.Manager, options Options) (Controller | |
}, | ||
MaxConcurrentReconciles: options.MaxConcurrentReconciles, | ||
CacheSyncTimeout: options.CacheSyncTimeout, | ||
SetFields: mgr.SetFields, | ||
Name: name, | ||
LogConstructor: options.LogConstructor, | ||
RecoverPanic: options.RecoverPanic, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These were actually useful to catch errors right away, and have a bit more verbosity when tests are running, we should probably keep them