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

Unify code structure of training job api #1300

Merged
merged 6 commits into from
Jul 14, 2021

Conversation

Jeffwan
Copy link
Member

@Jeffwan Jeffwan commented Jul 12, 2021

This PR is part of #1299 kubeflow/common#138

It resolves "1. Eliminate difference between operators and make them have same coding structure (including apis, docs, openapi specs)"

We use this opportunity to unify the apis code structure. kubebuilder and code-generator will be used together to achieve the goal

  1. kubebuilder leverage controller-runtime to generate codes. However, it won't give us clientset, openapis, etc. Ideally, we would like to generate clientset,informer,lister for any tools that want to interact with training jobs. In this case, we still need code-generator.

Kubebuilder only gives us following objects.

├── pytorch
│   ├── v1
│   │   ├── groupversion_info.go
│   │   ├── pytorchjob_types.go
│   │   ├── zz_generated.deepcopy.go
  1. Kubebuilder leverages webhook to mutate object and give default values. We definitely don't want to bring extra components to the training operators. Instead, we still leverage defaults.go and manually assign default values to job objects.
  2. Keep openapi for sdk generation in the future
├── pytorch
│   ├── v1
│   │   ├── constants.go                      -> owner: developer. DefaultPort, DefaultContainerName, etc
│   │   ├── defaults.go                         -> owner: developer SetJobDefaults
│   │   ├── doc.go                                -> owner: developer  global markers to generate code.  remove deepcopy marker 
│   │   ├── groupversion_info.go        -> generated by kubebudiler
│   │   ├── openapi_generated.go     -> generated by openapi-gen
│   │   ├── pytorchjob_types.go.       -> originally generated by kubebudiler
│   │   ├── register.go                        -> owner: developer.  used by clientset
│   │   ├── zz_generated.deepcopy.go -> generate by kubebuilder
│   │   └── zz_generated.defaults.go    -> generated by defaulter-gen

- Clean up register.go and use reference in groupversion_info.go (generated by kubebuilder) instead
- Add doc.go and register.go for framework missing them
- Remove global tag “+k8s:deepcopy-gen=package,register” and this should be taken care of by controller-gen.

Signed-off-by: Jiaxin Shan <[email protected]>
1. Update codegen scripts to generate defaulters and openapi spec for all frameworks
2. Create defaults.go for framework which miss it.

Signed-off-by: Jiaxin Shan <[email protected]>
@Jeffwan Jeffwan changed the title Unify Unify code structure of training job api Jul 12, 2021
@Jeffwan
Copy link
Member Author

Jeffwan commented Jul 12, 2021

/cc @kubeflow/wg-training-leads @zw0610 Please have a review on this change

@google-oss-robot google-oss-robot requested review from zw0610 and a team July 12, 2021 17:17
@google-oss-robot
Copy link

@Jeffwan: GitHub didn't allow me to request PR reviews from the following users: a, review, on, change, Please, have, this.

Note that only kubeflow members and repo collaborators can review this PR, and authors cannot review their own PRs.

In response to this:

/cc @kubeflow/wg-training-leads @zw0610 Please have a review on this change

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.

hack/update-codegen.sh Show resolved Hide resolved
pkg/controller.v1/mxnet/mxjob_controller.go Outdated Show resolved Hide resolved
pkg/apis/mxnet/v1/defaults.go Outdated Show resolved Hide resolved
pkg/apis/xgboost/v1/defaults.go Outdated Show resolved Hide resolved
Copy link
Member

@zw0610 zw0610 left a comment

Choose a reason for hiding this comment

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

looking good.

pkg/apis/xgboost/v1/defaults.go Outdated Show resolved Hide resolved
@Jeffwan
Copy link
Member Author

Jeffwan commented Jul 13, 2021

@gaocegege @zw0610 Please have another check. Rerun goimports -w pkg/.

Copy link
Member

@terrytangyuan terrytangyuan left a comment

Choose a reason for hiding this comment

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

LGTM. Consider adding goimports check to the CI?

@Jeffwan
Copy link
Member Author

Jeffwan commented Jul 13, 2021

LGTM. Consider adding goimports check to the CI?

Yeah, that's a good idea. I will add it in a separate PR. there're some more cleanups on the CI tools.

@johnugeorge
Copy link
Member

Great @Jeffwan
LGTM

@@ -123,7 +123,7 @@ type MXJobReconciler struct {

func (r *MXJobReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
_ = log.FromContext(ctx)
logger := r.Log.WithValues(mxjobv1.Singular, req.NamespacedName)
logger := r.Log.WithValues("mxjobs", req.NamespacedName)
Copy link
Member

Choose a reason for hiding this comment

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

@Jeffwan Do we want to keep Singular and Plural in the constants also ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, nice catch. I've moved them to constants.go now

@@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// +k8s:deepcopy-gen=package,register
Copy link
Member Author

Choose a reason for hiding this comment

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

We don't need deepcopy-gen to generate file anymore since we have controller-gen from kubebuilder. They do the same work

@Jeffwan
Copy link
Member Author

Jeffwan commented Jul 14, 2021

Seems it looks good to most reviewers. Can someone leave a /lgtm ?

/cc @kubeflow/wg-training-leads

@google-oss-robot google-oss-robot requested a review from a team July 14, 2021 19:08
Copy link
Member

@terrytangyuan terrytangyuan left a comment

Choose a reason for hiding this comment

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

/lgtm

@Jeffwan
Copy link
Member Author

Jeffwan commented Jul 14, 2021

/approve

@google-oss-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Jeffwan, terrytangyuan, zw0610

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@google-oss-robot google-oss-robot merged commit ae7ffd6 into kubeflow:all-in-one-operator Jul 14, 2021
@Jeffwan Jeffwan deleted the cleanup_apis branch July 14, 2021 19:12
Jeffwan added a commit that referenced this pull request Aug 5, 2021
* Add docs, register in job apis

- Clean up register.go and use reference in groupversion_info.go (generated by kubebuilder) instead
- Add doc.go and register.go for framework missing them
- Remove global tag “+k8s:deepcopy-gen=package,register” and this should be taken care of by controller-gen.

Signed-off-by: Jiaxin Shan <[email protected]>

* Generate defaults and openapi for all frameworks

1. Update codegen scripts to generate defaulters and openapi spec for all frameworks
2. Create defaults.go for framework which miss it.

Signed-off-by: Jiaxin Shan <[email protected]>

* Add Kind in constants.go

Signed-off-by: Jiaxin Shan <[email protected]>

* Update update-codegen to generate openapi-gen

Signed-off-by: Jiaxin Shan <[email protected]>

* Run goimports to format the files

* Add Plural and Singular to apis constants.go

Signed-off-by: Jiaxin Shan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants