-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Conversation
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.
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.
samples/controller/controller.go
Outdated
deploymentsLister: iargs.KubernetesInformers.Apps().V1().Deployments().Lister(), | ||
foosLister: iargs.Informers.Samplecontroller().V1alpha1().Foos().Lister(), | ||
recorder: iargs.CreateRecorder(controllerAgentName), | ||
} |
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.
wondering if Controller struct can have iargs in it ? because everything the controller needs is coming from iargs ?
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.
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.
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.
Yeah, I think that might be the way to go.
samples/controller/controller.go
Outdated
if shutdown { | ||
return false | ||
} | ||
genericController.WatchAndMapToControllerIf(&appsv1.Deployment{}, handlefunctions.ResourceVersionChanged, MapToDeploymentToTypes...) |
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.
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(...)" ?
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.
+1 to both
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 does look much simpler.
samples/controller/controller.go
Outdated
deploymentsLister: iargs.KubernetesInformers.Apps().V1().Deployments().Lister(), | ||
foosLister: iargs.Informers.Samplecontroller().V1alpha1().Foos().Lister(), | ||
recorder: iargs.CreateRecorder(controllerAgentName), | ||
} |
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.
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.
samples/controller/controller.go
Outdated
|
||
// Get the Foo resource with this namespace/name | ||
func (c *Controller) syncHandler(key types.ReconcileKey) error { | ||
namespace, name := key.Namespace, key.Name |
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.
major nit: why?! =))
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.
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.
samples/controller/controller.go
Outdated
return false | ||
} | ||
genericController.WatchAndMapToControllerIf(&appsv1.Deployment{}, handlefunctions.ResourceVersionChanged, | ||
metav1.GroupVersionKind{Group: "apps", Version: "v1", Kind: "Deployment"}) |
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 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?
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.
Yes good catch. Updated.
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.
/lgtm
@droot: changing LGTM is restricted to assignees, and only kubernetes-sigs org members may be assigned issues. In response to this:
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. |
# 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
fix icon and img of the index
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