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

✨ Improve builder UX #264

Merged
merged 2 commits into from
Jan 4, 2019
Merged

Conversation

pwittrock
Copy link
Contributor

No description provided.

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 20, 2018
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Dec 20, 2018
Copy link
Contributor

@DirectXMan12 DirectXMan12 left a 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
Copy link
Contributor

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

Copy link
Contributor Author

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()})
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

ack


// 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 {
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

// 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.
Copy link
Contributor

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/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -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}
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Describe("Start with Controller", func() {
depName := "deploy-name-2"
It("should Reconcile objects", func(done Done) {
By("Creating the application")
Copy link
Contributor

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

Copy link
Contributor

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()
       // ...
   })
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -19,39 +19,41 @@ package builder_test
import (
"context"
"fmt"
"os"
"log"
Copy link
Contributor

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?

Copy link
Contributor

@droot droot left a 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

Copy link
Contributor

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.

Copy link
Contributor Author

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)
}
Copy link
Contributor

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.

Copy link
Contributor Author

@pwittrock pwittrock Dec 20, 2018

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
Copy link
Contributor

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 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Dec 20, 2018
@pwittrock
Copy link
Contributor Author

PTAL

Copy link
Contributor

@DirectXMan12 DirectXMan12 left a 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"
Copy link
Contributor

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?

Copy link
Contributor Author

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,
Copy link
Contributor

Choose a reason for hiding this comment

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

did these get unformatted?

Copy link
Contributor Author

@pwittrock pwittrock Dec 21, 2018

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.

@@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

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

??

Copy link
Contributor Author

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.
Copy link
Contributor

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 ;-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

@pwittrock
Copy link
Contributor Author

pwittrock commented Dec 21, 2018

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
@pwittrock
Copy link
Contributor Author

ping

Copy link
Contributor

@droot droot left a 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 \
Copy link
Contributor

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})
Copy link
Contributor

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 ?

Copy link
Contributor

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{})
Copy link
Contributor

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 :)

Copy link
Contributor

@DirectXMan12 DirectXMan12 left a 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

// 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.
Copy link
Contributor

Choose a reason for hiding this comment

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

find-replace issue

Copy link
Contributor Author

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})
Copy link
Contributor

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

@pwittrock
Copy link
Contributor Author

PTAL

@DirectXMan12
Copy link
Contributor

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 4, 2019
@k8s-ci-robot
Copy link
Contributor

[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:
  • OWNERS [DirectXMan12,pwittrock]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot merged commit 5aed6d6 into kubernetes-sigs:master Jan 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants