-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add simple application pattern package #26
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
Conversation
6d37af6
to
6df4f01
Compare
225aba7
to
66c7717
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.
Overall verdict: awesome.
bunch of nits inline, needs doc improvements.
|
||
// application is a very simple Controller that embeds a Manager. | ||
type application struct { | ||
mrg manager.Manager |
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.
mgr
?
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
ctrl *internalcontroller.Controller | ||
} | ||
|
||
var noop = reconcile.Func(func(reconcile.Request) (reconcile.Result, 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.
docs
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.
Deleted
"sigs.k8s.io/controller-runtime/pkg/source" | ||
) | ||
|
||
// application is a very simple Controller that embeds a Manager. |
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.
write why in the docs.
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
return reconcile.Result{}, nil | ||
}) | ||
|
||
var getConfig = config.GetConfig |
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 for testing purposes? Write that in a comment.
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
return b | ||
} | ||
|
||
// WithEventFilter sets the event filters. Defaults to the empty list. |
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 event filters, to filter which create/update/delete/generic events eventually trigger reconciliations
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.
for example, filtering by a particular label selector or annotation
// WithHandler sets th Reconcile called in response to create / update / delete events for the | ||
// BuilderFor type or Created object types. | ||
func (b *Builder) WithHandler(r reconcile.Reconciler) *Builder { | ||
b.r = r |
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.
give this a proper name please. You have autocomplete, so you have no excuse :-P
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
if err != nil { | ||
return nil, err | ||
} | ||
a.ctrl = ctrl.(*internalcontroller.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.
eeewww. why is this cast necessary?
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.
Its not
|
||
// Watch the managed types | ||
for _, t := range b.manages { | ||
err = a.ctrl.Watch(&source.Kind{Type: t}, &handler.EnqueueRequestForOwner{ |
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.
is there/should there be a way to add non-owns relationships with this 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.
Not right now. The point of this package is to offer a simplified view for the most common way to build application controllers. If arbitrary mappings become common for operators, then we can add them. Otherwise users can break out and use the underlying libraries directly.
// | ||
// An application is a Controller that implements the operational logic for an application. It is often used | ||
// to take off-the-shelf OSS applications, and make them Kubernetes native. | ||
package 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.
if it's for operators, maybe just call it operator
?
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.
Calling this Application because that is the common response when folks as "what is an operator". I created an operator package to explain this.
// List the Pods matching the PodTemplate Labels | ||
pods := &corev1.PodList{} | ||
err = a.List(context.TODO(), | ||
&client.ListOptions{ |
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 believe we have a builder for this (if we don't have one for the namespace, we should), so you should be able to write something like
client.InNamespace(req.Namespace).WithLabels(rs.Spec.Template.Labels)
, which is a bit easier to read and doesn't require pulling out labels.SelectorFromSet
.
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
@DirectXMan12 LMK if there is anything else. |
@DirectXMan12 Merging for now since @mengqiy needs to create something similar. Let me know if anything was unaddressed. |
Add simple application pattern package
Add string method for ReconcileKey
✨ Add ClusterAwareBuilderWithOptions to the wrapper
Looking to get feedback on simplifying this pattern.