-
Notifications
You must be signed in to change notification settings - Fork 737
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
Add XGBoost controller #1293
Merged
google-oss-robot
merged 2 commits into
kubeflow:all-in-one-operator
from
Jeffwan:add_xgboost_controller
Jul 7, 2021
Merged
Add XGBoost controller #1293
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
apiVersion: kubeflow.org/v1 | ||
kind: XGBoostJob | ||
metadata: | ||
name: xgboost-dist-iris-test-train | ||
spec: | ||
xgbReplicaSpecs: | ||
Master: | ||
replicas: 1 | ||
restartPolicy: Never | ||
template: | ||
spec: | ||
containers: | ||
- name: xgboostjob | ||
image: docker.io/merlintang/xgboost-dist-iris:1.1 | ||
ports: | ||
- containerPort: 9991 | ||
name: xgboostjob-port | ||
imagePullPolicy: Always | ||
args: | ||
- --job_type=Train | ||
- --xgboost_parameter=objective:multi:softprob,num_class:3 | ||
- --n_estimators=10 | ||
- --learning_rate=0.1 | ||
- --model_path=/tmp/xgboost-model | ||
- --model_storage_type=local | ||
Worker: | ||
replicas: 2 | ||
restartPolicy: ExitCode | ||
template: | ||
spec: | ||
containers: | ||
- name: xgboostjob | ||
image: docker.io/merlintang/xgboost-dist-iris:1.1 | ||
ports: | ||
- containerPort: 9991 | ||
name: xgboostjob-port | ||
imagePullPolicy: Always | ||
args: | ||
- --job_type=Train | ||
- --xgboost_parameter="objective:multi:softprob,num_class:3" | ||
- --n_estimators=10 | ||
- --learning_rate=0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package xgboost | ||
|
||
import ( | ||
"fmt" | ||
commonv1 "github.com/kubeflow/common/pkg/apis/common/v1" | ||
"github.com/kubeflow/common/pkg/controller.v1/common" | ||
"github.com/kubeflow/common/pkg/controller.v1/expectation" | ||
v1 "github.com/kubeflow/tf-operator/pkg/apis/xgboost/v1" | ||
"github.com/sirupsen/logrus" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
utilruntime "k8s.io/apimachinery/pkg/util/runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/event" | ||
"sigs.k8s.io/controller-runtime/pkg/reconcile" | ||
) | ||
|
||
// satisfiedExpectations returns true if the required adds/dels for the given job have been observed. | ||
// Add/del counts are established by the controller at sync time, and updated as controllees are observed by the controller | ||
// manager. | ||
func (r *XGBoostJobReconciler) satisfiedExpectations(xgbJob *v1.XGBoostJob) bool { | ||
satisfied := false | ||
key, err := common.KeyFunc(xgbJob) | ||
if err != nil { | ||
utilruntime.HandleError(fmt.Errorf("couldn't get key for job object %#v: %v", xgbJob, err)) | ||
return false | ||
} | ||
for rtype := range xgbJob.Spec.XGBReplicaSpecs { | ||
// Check the expectations of the pods. | ||
expectationPodsKey := expectation.GenExpectationPodsKey(key, string(rtype)) | ||
satisfied = satisfied || r.Expectations.SatisfiedExpectations(expectationPodsKey) | ||
// Check the expectations of the services. | ||
expectationServicesKey := expectation.GenExpectationServicesKey(key, string(rtype)) | ||
satisfied = satisfied || r.Expectations.SatisfiedExpectations(expectationServicesKey) | ||
} | ||
return satisfied | ||
} | ||
|
||
// onDependentCreateFunc modify expectations when dependent (pod/service) creation observed. | ||
func onDependentCreateFunc(r reconcile.Reconciler) func(event.CreateEvent) bool { | ||
return func(e event.CreateEvent) bool { | ||
xgbr, ok := r.(*XGBoostJobReconciler) | ||
if !ok { | ||
return true | ||
} | ||
rtype := e.Object.GetLabels()[commonv1.ReplicaTypeLabel] | ||
if len(rtype) == 0 { | ||
return false | ||
} | ||
|
||
logrus.Info("Update on create function ", xgbr.ControllerName(), " create object ", e.Object.GetName()) | ||
if controllerRef := metav1.GetControllerOf(e.Object); controllerRef != nil { | ||
var expectKey string | ||
if _, ok := e.Object.(*corev1.Pod); ok { | ||
expectKey = expectation.GenExpectationPodsKey(e.Object.GetNamespace()+"/"+controllerRef.Name, rtype) | ||
} | ||
|
||
if _, ok := e.Object.(*corev1.Service); ok { | ||
expectKey = expectation.GenExpectationServicesKey(e.Object.GetNamespace()+"/"+controllerRef.Name, rtype) | ||
} | ||
xgbr.Expectations.CreationObserved(expectKey) | ||
return true | ||
} | ||
|
||
return true | ||
} | ||
} | ||
|
||
// onDependentDeleteFunc modify expectations when dependent (pod/service) deletion observed. | ||
func onDependentDeleteFunc(r reconcile.Reconciler) func(event.DeleteEvent) bool { | ||
return func(e event.DeleteEvent) bool { | ||
xgbr, ok := r.(*XGBoostJobReconciler) | ||
if !ok { | ||
return true | ||
} | ||
|
||
rtype := e.Object.GetLabels()[commonv1.ReplicaTypeLabel] | ||
if len(rtype) == 0 { | ||
return false | ||
} | ||
|
||
logrus.Info("Update on deleting function ", xgbr.ControllerName(), " delete object ", e.Object.GetName()) | ||
if controllerRef := metav1.GetControllerOf(e.Object); controllerRef != nil { | ||
var expectKey string | ||
if _, ok := e.Object.(*corev1.Pod); ok { | ||
expectKey = expectation.GenExpectationPodsKey(e.Object.GetNamespace()+"/"+controllerRef.Name, rtype) | ||
} | ||
|
||
if _, ok := e.Object.(*corev1.Service); ok { | ||
expectKey = expectation.GenExpectationServicesKey(e.Object.GetNamespace()+"/"+controllerRef.Name, rtype) | ||
} | ||
|
||
xgbr.Expectations.DeletionObserved(expectKey) | ||
return true | ||
} | ||
|
||
return true | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Do we still need expectations if we use controller-runtime?
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.
Correct me if I am wrong. I think they are just helpers and help us save some efforts to determine if we need to resync job. Technically, I think we can definitely remove helpers if rest of the logics are solid.
kubernetes-sigs/controller-runtime#644