Skip to content

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

Merged
merged 1 commit into from
Jun 27, 2018

Conversation

pwittrock
Copy link
Contributor

@pwittrock pwittrock commented Jun 12, 2018

Looking to get feedback on simplifying this pattern.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jun 12, 2018
@pwittrock pwittrock changed the title Add simple operator package Proposal: Add simple operator package Jun 12, 2018
@pwittrock pwittrock closed this Jun 12, 2018
@pwittrock pwittrock reopened this Jun 12, 2018
@pwittrock pwittrock force-pushed the operator branch 2 times, most recently from 6d37af6 to 6df4f01 Compare June 13, 2018 17:52
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jun 13, 2018
@pwittrock pwittrock force-pushed the operator branch 4 times, most recently from 225aba7 to 66c7717 Compare June 18, 2018 02:14
@pwittrock pwittrock changed the title Proposal: Add simple operator package Proposal: Add simple application package Jun 18, 2018
@pwittrock pwittrock changed the title Proposal: Add simple application package Add simple application pattern package Jun 18, 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.

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

Choose a reason for hiding this comment

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

mgr?

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

ctrl *internalcontroller.Controller
}

var noop = reconcile.Func(func(reconcile.Request) (reconcile.Result, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

docs

Copy link
Contributor Author

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

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.

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

return reconcile.Result{}, nil
})

var getConfig = config.GetConfig
Copy link
Contributor

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.

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

return b
}

// WithEventFilter sets the event filters. Defaults to the empty list.
Copy link
Contributor

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

Copy link
Contributor

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

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

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

if err != nil {
return nil, err
}
a.ctrl = ctrl.(*internalcontroller.Controller)
Copy link
Contributor

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?

Copy link
Contributor Author

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

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?

Copy link
Contributor Author

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

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?

Copy link
Contributor Author

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

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.

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 Jun 26, 2018
@pwittrock
Copy link
Contributor Author

@DirectXMan12 LMK if there is anything else.

@pwittrock pwittrock added approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm "Looks good to me", indicates that a PR is ready to be merged. labels Jun 27, 2018
@pwittrock
Copy link
Contributor Author

@DirectXMan12 Merging for now since @mengqiy needs to create something similar. Let me know if anything was unaddressed.

@k8s-ci-robot k8s-ci-robot merged commit 2826ee9 into kubernetes-sigs:master Jun 27, 2018
justinsb pushed a commit to justinsb/controller-runtime that referenced this pull request Dec 7, 2018
Add simple application pattern package
DirectXMan12 pushed a commit that referenced this pull request Jan 31, 2020
Add string method for ReconcileKey
stevekuznetsov pushed a commit to stevekuznetsov/controller-runtime that referenced this pull request Oct 10, 2022
✨ Add ClusterAwareBuilderWithOptions to the wrapper
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.

3 participants