-
Notifications
You must be signed in to change notification settings - Fork 731
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
Reorganize controllers code structure #1302
Reorganize controllers code structure #1302
Conversation
CustomResourceDefinition.apiextensions.k8s.io "tfjobs.kubeflow.org" is invalid: spec.validation.openAPIV3Schema.properties[metadata]: Forbidden: must not specify anything other than name and generateName, but metadata is implicitly specified Signed-off-by: Jiaxin Shan <[email protected]>
1. Move all ControllerInterface implementations to [framework]_controller.go 2. Clean up job.go pod.go service.go status.go 3. Follow exact same method order here https://github.com/kubeflow/common/blob/9ffa565bc60e08936f7f80cb3f491cf53f256e7f/pkg/apis/common/v1/interface.go Signed-off-by: Jiaxin Shan <[email protected]>
/hold |
db91333
to
4902eca
Compare
I notice previous change embed TFController which means most of the methods still use tfjob client. We need to make controller consistent and `TFJobReconciler` should override `common.JobController`. With this change, it would be very easy to make original tf operator and new reconciler work together. We also avoid one more refactor when we will remove original TFController codes Signed-off-by: Jiaxin Shan <[email protected]>
4902eca
to
22cc34e
Compare
Thanks for your contribution! 🎉 👍 Is it ready to review? |
@gaocegege It is. I am running some coarse-grained testing and leave |
/hold cancel |
} | ||
// setup FieldIndexer to inform the manager that this controller owns pods and services, | ||
// so that it will automatically call Reconcile on the underlying MXJob when a Pod or Service changes, is deleted, etc. | ||
if err := mgr.GetFieldIndexer().IndexField(context.Background(), &corev1.Pod{}, jobOwnerKey, func(rawObj client.Object) []string { |
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.
what is the difference of this from earlier watch?
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.
@johnugeorge c, err := controller.New(controllerName, mgr, controller.Options{Reconciler: r})
creates a separate controller and it is still a low level concepts which leverages "sigs.k8s.io/controller-runtime/pkg/controller"
in v1. ctrl.Manager
facing programing is higher level and use doesn't need handles things like predicate funds.
I think both way work and this is just kubebuilder v2-v3 fashion.
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 we use controller.Watch?
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.
@gaocegege do you mean you preferred to use controller
directly with some event handlers?
Technically, ctrl.NewControllerManagedBy(mgr).....Complete(r)
will create the controller eventually.
https://github.com/kubernetes-sigs/controller-runtime/blob/1e4d87c9f9e15e4a58bb81909dd787f30ede7693/pkg/builder/controller.go#L169
I am ok with either way, Kubebuilder v1 does use controller
way https://book-v1.book.kubebuilder.io/basics/simple_controller.html . In kubebuilder v2 and v3, this has been changed. I am running more tests if high level can meet all the cases. If not, we can fallback to lower level. What do you think?
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.
Thanks, I am just curious. Both way LGTM.
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 pretty buggy using kubebuilder v3 + common (with many expectation operations). I think it's better to change back to kubebuilder v1 way to manually control the pods events.
LGTM |
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.
Thanks!
/lgtm
if h := os.Getenv("HOME"); h != "" { | ||
return h | ||
} | ||
return os.Getenv("USERPROFILE") // windows | ||
} | ||
|
||
// TODO (Jeffwan@): Find an elegant way to either use delegatingReader or directly use clientss |
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.
// TODO (Jeffwan@): Find an elegant way to either use delegatingReader or directly use clientss | |
// TODO (Jeffwan@): Find an elegant way to either use delegatingReader or directly use clients |
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.
Nice catch. I will address all grammar issue in one PR.
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: Jeffwan, terrytangyuan 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 |
* Fix crd installation issue CustomResourceDefinition.apiextensions.k8s.io "tfjobs.kubeflow.org" is invalid: spec.validation.openAPIV3Schema.properties[metadata]: Forbidden: must not specify anything other than name and generateName, but metadata is implicitly specified Signed-off-by: Jiaxin Shan <[email protected]> * Clean up controllers 1. Move all ControllerInterface implementations to [framework]_controller.go 2. Clean up job.go pod.go service.go status.go 3. Follow exact same method order here https://github.com/kubeflow/common/blob/9ffa565bc60e08936f7f80cb3f491cf53f256e7f/pkg/apis/common/v1/interface.go Signed-off-by: Jiaxin Shan <[email protected]> * Embed common.JobController instead of TFController I notice previous change embed TFController which means most of the methods still use tfjob client. We need to make controller consistent and `TFJobReconciler` should override `common.JobController`. With this change, it would be very easy to make original tf operator and new reconciler work together. We also avoid one more refactor when we will remove original TFController codes Signed-off-by: Jiaxin Shan <[email protected]>
This PR is part of #1299 kubeflow/common#138
It resolves "3. Simplify controller code structures. Merge pods.go service.go job.go into one file which is the core JobController implementation."
Major changes
metadata.name
andmetadata.generateName
ifmetada
is specified. (https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#specifying-a-structural-schema)common.JobController
instead ofTFController
in TFJobReconciler. The major motivation ispytorch_controller.go
has all codes of its controller implementation. Language specific setting will be inpytorch.go
./cc @kubeflow/wg-training-leads @zw0610