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

Update sample to use kubebuilder controller library #5

Merged
merged 1 commit into from
Mar 19, 2018
Merged

Update sample to use kubebuilder controller library #5

merged 1 commit into from
Mar 19, 2018

Conversation

pwittrock
Copy link
Contributor

@pwittrock pwittrock commented Mar 16, 2018

This PR changes the for of sample-controller to use the kubebuilder controller libraries.

Note: Reduces the size of the controller by 50% (~200) lines

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 16, 2018
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.

Took a quick look without going through the main repo and have couple of questions.
I will go through the main repo to have better context.

deploymentsLister: iargs.KubernetesInformers.Apps().V1().Deployments().Lister(),
foosLister: iargs.Informers.Samplecontroller().V1alpha1().Foos().Lister(),
recorder: iargs.CreateRecorder(controllerAgentName),
}
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 Controller struct can have iargs in it ? because everything the controller needs is coming from iargs ?

Choose a reason for hiding this comment

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

That'd be somewhat similar to inject cobra deep down everywhere IMHO. Objects like Controller shouldn't be coupled with iargs, or with the source of their parameters.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I think that might be the way to go.

if shutdown {
return false
}
genericController.WatchAndMapToControllerIf(&appsv1.Deployment{}, handlefunctions.ResourceVersionChanged, MapToDeploymentToTypes...)
Copy link
Contributor

Choose a reason for hiding this comment

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

Still trying to understand the mapping stuff here. Looked the code handleObject(..) and if it is replacing that functionality then we can potentially improve the API name name here "WatchOwnersIf(...)"

also thinking if we can make the predicates more obvious like if it read "predicates.ResourceVersionChanged(...)" ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

+1 to both

Copy link

@apelisse apelisse left a comment

Choose a reason for hiding this comment

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

It does look much simpler.

deploymentsLister: iargs.KubernetesInformers.Apps().V1().Deployments().Lister(),
foosLister: iargs.Informers.Samplecontroller().V1alpha1().Foos().Lister(),
recorder: iargs.CreateRecorder(controllerAgentName),
}

Choose a reason for hiding this comment

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

That'd be somewhat similar to inject cobra deep down everywhere IMHO. Objects like Controller shouldn't be coupled with iargs, or with the source of their parameters.


// Get the Foo resource with this namespace/name
func (c *Controller) syncHandler(key types.ReconcileKey) error {
namespace, name := key.Namespace, key.Name

Choose a reason for hiding this comment

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

major nit: why?! =))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To try and keep it as close to the original as possible. If I change stuff like this then there are a bunch of lines changed that are orthogonal.

return false
}
genericController.WatchAndMapToControllerIf(&appsv1.Deployment{}, handlefunctions.ResourceVersionChanged,
metav1.GroupVersionKind{Group: "apps", Version: "v1", Kind: "Deployment"})
Copy link
Contributor

Choose a reason for hiding this comment

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

The WatchAndMapToControllerIf function compares the owner of the watched object to the given GroupVersionKind. So shouldn't the GroupVersionKind here refer to sample1alphva1.Foo instead of appsv1.Deployment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes good catch. Updated.

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.

/lgtm

@k8s-ci-robot
Copy link
Contributor

@droot: changing LGTM is restricted to assignees, and only kubernetes-sigs org members may be assigned issues.

In response to this:

/lgtm

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@pwittrock pwittrock merged commit 966df30 into kubernetes-sigs:master Mar 19, 2018
jkevlin pushed a commit to jkevlin/kubebuilder that referenced this pull request Aug 22, 2018
# This is the 1st commit message:

Document adding an external type

# This is the commit message kubernetes-sigs#2:

Fix typo in book: flag is --owner, not --owners

# This is the commit message kubernetes-sigs#3:

gitbook: fixed installation instructions

# This is the commit message kubernetes-sigs#4:

Fix domain resource issues in controller

- fix in controller-tools and vendor in kubebuilder
- bind resource for controller based on whether resource is created.

# This is the commit message kubernetes-sigs#5:

improve contributing guide

# This is the commit message kubernetes-sigs#6:

Fix URL for the Gitbook

The URL is .io, not .com
# This is the commit message kubernetes-sigs#7:

Check go version

Fixes kubernetes-sigs#353

# This is the commit message kubernetes-sigs#8:

Validate create api flags

Fixes kubernetes-sigs#321

# This is the commit message kubernetes-sigs#9:

Update stable version in book

Update newest stable version to "1.0.1".

# This is the commit message kubernetes-sigs#10:

thirdparty tools: Dockerfile uses k8s 1.11

# This is the commit message kubernetes-sigs#11:

build: update cloudbuild config for building tools to use k8s 1.11

# This is the commit message kubernetes-sigs#12:

add document for connecting to existing kind

# This is the commit message kubernetes-sigs#13:

add document for connecting to existing kind

# This is the commit message kubernetes-sigs#14:

removed company from doc

# This is the commit message kubernetes-sigs#15:

fixed typo
3ks pushed a commit to 3ks/kubebuilder that referenced this pull request Jul 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants