-
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
✨ Improve builder UX #264
✨ Improve builder UX #264
Conversation
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.
few nits inline, generally looks good
needs a better PR description ;-)
example_test.go
Outdated
} | ||
|
||
_, err = controllers. | ||
NewControllerBuilder(manager). // Create the Controller |
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.
🚲 🏠 : maybe just NewControllerIn
? Reads a bit more fluently
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.
Done
example_test.go
Outdated
NewControllerBuilder(manager). // Create the Controller | ||
ForType(&appsv1.ReplicaSet{}). // ReplicaSet is the Application API | ||
Owns(&corev1.Pod{}). // ReplicaSet owns Pods created by it | ||
Build(&ReplicaSetReconciler{Client: manager.GetClient()}) |
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.
what's up with the return of explicit wiring?
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.
I think this works for this case. It is pretty simple.
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.
ack
pkg/builder/build.go
Outdated
|
||
// Watch exposes the lower-level Controller Watch functions through the builder. Consider using | ||
// Owns or ForType instead of Watch directly. | ||
func (b *Builder) Watch(src source.Source, eventhandler handler.EventHandler) *Builder { |
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.
nit: follow the same phrasing as ForType
or Owns
here -- Watches
or something similar
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.
Done
pkg/builder/build.go
Outdated
// WithConfig sets the Config to use for configuring clients. Defaults to the in-cluster config or to ~/.kube/config. | ||
// Deprecated - set through the Manager instead. |
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.
nit: we should prob follow the standard library convention: https://rakyll.org/deprecated/
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.
Done
pkg/builder/build.go
Outdated
@@ -114,12 +131,10 @@ func (b *Builder) Build(r reconcile.Reconciler) (manager.Manager, error) { | |||
return nil, err | |||
} | |||
|
|||
a := &application{mgr: b.mgr, ctrl: b.ctrl} | |||
|
|||
// Reconcile type | |||
s := &source.Kind{Type: b.apiType} |
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.
blech, we should fix these single-letter variables in a follow-up
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.
done
pkg/builder/build_test.go
Outdated
Describe("Start with Controller", func() { | ||
depName := "deploy-name-2" | ||
It("should Reconcile objects", func(done Done) { | ||
By("Creating the application") |
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 tests effectively do the same thing after setting up the controller. We should prob refactor out into a help above for easier maintenance
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.
or invert and do something like
func DescribeAController(setupTheController func() manager.Manager) {
It("should reconcile objects", func(done Done) {
mgr := setupTheController()
// ...
})
}
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.
Done
pkg/builder/example_test.go
Outdated
@@ -19,39 +19,41 @@ package builder_test | |||
import ( | |||
"context" | |||
"fmt" | |||
"os" | |||
"log" |
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.
why're we reverting back to std log?
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.
few minor nits.
*/ | ||
|
||
package controller_runtime | ||
|
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.
We should add a comment explaining motivation for this file alias.go
.
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.
Done
alias.go
Outdated
|
||
func NewManager(config *rest.Config, options Options) (manager.Manager, error) { | ||
return manager.New(config, options) | ||
} |
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.
nit: some fns/vars have comments and some don't, so reading the file feels inconsistent.
Also this will impact the godocs as well.
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.
Done. Copied all comments
example_test.go
Outdated
|
||
_, err = controllers. | ||
NewControllerBuilder(manager). // Create the Controller | ||
ForType(&appsv1.ReplicaSet{}). // ReplicaSet is the Application API |
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.
wondering if we should drop Type
?
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.
Done
ad518da
to
8f7b8af
Compare
PTAL |
41d6293
to
42c1184
Compare
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.
couple of nits inline. Otherwise lgtm
example_test.go
Outdated
corev1 "k8s.io/api/core/v1" | ||
controllers "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log" |
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.
can just use controllers.Log
, right?
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.
Done
MaxConcurrentReconciles: options.MaxConcurrentReconciles, | ||
Name: name, | ||
Name: name, |
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.
did these get unformatted?
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 are formatted with go fmt ./pkg/...
and should be fine.
pkg/source/source.go
Outdated
@@ -241,7 +241,7 @@ func (cs *Channel) syncLoop() { | |||
} | |||
} | |||
|
|||
// Informer is used to provide a source of events originating inside the cluster from Watches (e.g. Pod Create) | |||
// Informer is used to provide a source of events originating inside the cluster from Watch (e.g. Pod Create) |
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.
??
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.
Done by the IDE when refactoring the naming change requested in your previous comment.
|
||
// Log is the base logger used by kubebuilder. It delegates | ||
// to another logr.Logger. You *must* call SetLogger to | ||
// get any actual logging. |
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.
might want to note that SetLogger
isn't here ;-)
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.
Added
1a65375
to
609e516
Compare
PTAL. I am going on break. Can we merge this as is and follow up on any minor / formatting issues? |
- Rename Builder functions - Encourage providing the manager to the Builder factory - Deprecate discouraged functions - Add alias.go with short cuts for common functions to reduce import line bloat - Fix issue with GetConfigOrDie not exiting - Update examples - Add example at package root
ping |
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.
Looks good to me. would wait for @DirectXMan12 to take a final look.
@@ -52,6 +51,7 @@ gometalinter.v2 --disable-all \ | |||
--skip=atomic \ | |||
./pkg/... | |||
# TODO: Enable these as we fix them to make them pass | |||
# --enable=goimports \ |
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.
It gave me trouble in the past and reinstalling (updating) goimports fixed the problem. I am assuming this will be enabled before the merge ?
For(&appsv1.Deployment{}). | ||
Watches( // Equivalent of Owns | ||
&source.Kind{Type: &appsv1.ReplicaSet{}}, | ||
&handler.EnqueueRequestForOwner{OwnerType: &appsv1.Deployment{}, IsController: true}) |
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.
Looking at this example, builder for controller appears to be a very thin improvement over current controller
abstraction because users have to understand manager
, watches
and handlers
to use these. Am I missing something ?
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.
this is just an example of using watches directly. We need to test the "I want .Owns and one more complicated thing" -- the test just happens to use the Owner enqueuer for convienience
ControllerManagedBy(mgr). // Create the ControllerManagedBy | ||
For(&appsv1.ReplicaSet{}). // ReplicaSet is the Application API | ||
Owns(&corev1.Pod{}). // ReplicaSet owns Pods created by it | ||
Build(&ReplicaSetReconciler{}) |
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.
I see it now (ignore my previous comment). Simple use-case is looking simple now :)
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.
minor nits. Otherwise looks good
pkg/builder/build.go
Outdated
// Supporting mocking out functions for testing | ||
var getConfig = config.GetConfig | ||
var newController = controller.New | ||
var newManager = manager.New | ||
var getGvk = apiutil.GVKForObject | ||
|
||
// Builder builds an Application Controller (e.g. Operator) and returns a manager.Manager to start it. | ||
// Builder builds an Application ControllerManagedBy (e.g. Operator) and returns a manager.Manager to start it. |
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.
find-replace issue
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.
Done
For(&appsv1.Deployment{}). | ||
Watches( // Equivalent of Owns | ||
&source.Kind{Type: &appsv1.ReplicaSet{}}, | ||
&handler.EnqueueRequestForOwner{OwnerType: &appsv1.Deployment{}, IsController: true}) |
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.
this is just an example of using watches directly. We need to test the "I want .Owns and one more complicated thing" -- the test just happens to use the Owner enqueuer for convienience
…hat haven't changed their imports)
PTAL |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: DirectXMan12, pwittrock The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
No description provided.