-
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
Invert the relationship between controller.Base and derivatives. #1770
Conversation
Woooo
…On Tue, Jul 31, 2018 at 17:04 Google Prow Robot ***@***.***> wrote:
@mattmoor <https://github.com/mattmoor>: The following tests *failed*,
say /retest to rerun them all:
Test name Commit Details Rerun command
pull-knative-serving-unit-tests 203ad04
<203ad04>
link
<https://gubernator-internal.googleplex.com/build/knative-prow/pr-logs/pull/knative_serving/1770/pull-knative-serving-unit-tests/317/> /test
pull-knative-serving-unit-tests
pull-knative-serving-build-tests 203ad04
<203ad04>
link
<https://gubernator-internal.googleplex.com/build/knative-prow/pr-logs/pull/knative_serving/1770/pull-knative-serving-build-tests/298/> /test
pull-knative-serving-build-tests
Full PR test history
<https://gubernator-internal.googleplex.com/pr/knative_serving/1770>. Your
PR dashboard <https://gubernator-internal.googleplex.com/pr/mattmoor>.
Instructions for interacting with me using PR comments are available here
<https://git.k8s.io/community/contributors/guide/pull-requests.md>. If
you have questions or suggestions related to my behavior, please file an
issue against the kubernetes/test-infra
<https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:>
repository. I understand the commands that are listed here
<https://go.k8s.io/bot-commands>.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1770 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AABIgvrY8-NpeYQlvbdTS_x8OKiSaprrks5uMMZDgaJpZM4VpZQB>
.
|
These test failures are quite weird, I wonder if I need to rebase or something... |
Oh yeah, Chen's change.... |
The way we use `controller.Base` today is very reminiscent of OOP; it is effectively trying to be a base class, and many things are painful trying to write this way in Go (e.g. we cannot simply make `Reconcile` an abstract method to be implemented by derivatives). With this change, we will instead move to a model where `Base` becomes `Impl` and takes an instance of the following interface: ```go package controller type Reconciler interface { Reconcile(key string) error } ``` In this model, `controller.Impl` is the single shared controller implementation, and the `NewController` methods become responsible for instantiating it with the appropriate implementation of `Reconciler` and wiring the appropriate events up via the informers. This cleans up the separation between `./pkg/controller` and `./pkg/controller/foo`, and will hopefully start to make the latter quite small. Ultimately the plan is to share the former via `knative/pkg`. Fixes: knative#1505
/test pull-knative-serving-integration-tests |
The `controller.go` is from: knative/serving#1770, however, this adds 100% coverage of `controller.go`, which we have been missing in `knative/serving`. Fixes: knative#8
FWIW, I also have knative/pkg#33 in flight, which adds 100% coverage of |
I think that (in the move to // loggerWithServiceInfo enriches the logs with service name and namespace.
func loggerWithServiceInfo(logger *zap.SugaredLogger, ns string, name string) *zap.SugaredLogger {
return logger.With(zap.String(commonlogkey.Namespace, ns), zap.String(logkey.Service, name))
} and this: // Wrap our logger with the additional context of the configuration that we are reconciling.
logger := loggerWithServiceInfo(c.Logger, namespace, name)
ctx := logging.WithLogger(context.TODO(), logger) I may then also make the |
The `controller.go` is from: knative/serving#1770, however, this adds 100% coverage of `controller.go`, which we have been missing in `knative/serving`. This also adds a `context.Context` to the `Reconcile` signature, to enable better sharing of logger setup across controllers. Fixes: knative#8
pkg/controller/controller.go
Outdated
syncHandler func(string) error, | ||
controllerName string) error { | ||
|
||
func (c *Impl) Run(threadiness int, stopCh <-chan struct{}) error { |
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 you update the comment for this method?
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/controller/controller.go
Outdated
// Launch workers to process Revision resources | ||
logger.Info("Starting workers") | ||
logger := c.logger |
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.
The comment above this mentions Revisions, which feels like a copy/paste oversight.
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/controller/controller.go
Outdated
// Launch workers to process Revision resources | ||
logger.Info("Starting workers") | ||
logger := c.logger | ||
logger.Info("Starting controller and workers") |
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's a bit of a shame that we're losing the controller kind in this log message, but I think we should be able to see that in the structured logging, 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.
We're actually not. This message appears in a JSON blob that has been decorated with this context (in some form) already.
The `controller.go` is from: knative/serving#1770, however, this adds 100% coverage of `controller.go`, which we have been missing in `knative/serving`. This also adds a `context.Context` to the `Reconcile` signature, to enable better sharing of logger setup across controllers. Fixes: knative#8
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: jonjohnsonjr, mattmoor 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 |
The following is the coverage report on pkg/.
|
/test pull-knative-serving-integration-tests |
The `controller.go` is from: knative/serving#1770, however, this adds 100% coverage of `controller.go`, which we have been missing in `knative/serving`. This also adds a `context.Context` to the `Reconcile` signature, to enable better sharing of logger setup across controllers. Fixes: #8
…tive#1770) * Invert the relationship between controller.Base and derivatives. The way we use `controller.Base` today is very reminiscent of OOP; it is effectively trying to be a base class, and many things are painful trying to write this way in Go (e.g. we cannot simply make `Reconcile` an abstract method to be implemented by derivatives). With this change, we will instead move to a model where `Base` becomes `Impl` and takes an instance of the following interface: ```go package controller type Reconciler interface { Reconcile(key string) error } ``` In this model, `controller.Impl` is the single shared controller implementation, and the `NewController` methods become responsible for instantiating it with the appropriate implementation of `Reconciler` and wiring the appropriate events up via the informers. This cleans up the separation between `./pkg/controller` and `./pkg/controller/foo`, and will hopefully start to make the latter quite small. Ultimately the plan is to share the former via `knative/pkg`. Fixes: knative#1505 * Address Jon code review feedback.
The way we use
controller.Base
today is very reminiscent of OOP; it is effectively trying to be a base class, and many things are painful trying to write this way in Go (e.g. we cannot simply makeReconcile
an abstract method to be implemented by derivatives).With this change, we will instead move to a model where
Base
becomesImpl
and takes an instance of the following interface:In this model,
controller.Impl
is the single shared controller implementation, and theNewController
methods become responsible for instantiating it with the appropriate implementation ofReconciler
and wiring the appropriate events up via the informers.This cleans up the separation between
./pkg/controller
and./pkg/controller/foo
, and will hopefully start to make the latter quite small. The plan is to share the former viaknative/pkg
in a subsequent change. I'm debating followup changes such as moving to a./pkg/reconciler/foo
structure, once onlyReconciler
s live in this repo.Fixes: #1505
cc @evankanderson @vaikas-google @n3wscott @grantr @imjasonh