-
Notifications
You must be signed in to change notification settings - Fork 698
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
Use low-level controller and handlers in SetupWithManager #1315
Merged
google-oss-robot
merged 6 commits into
kubeflow:all-in-one-operator
from
Jeffwan:make_it_work
Aug 2, 2021
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cb0841b
Use low-level controller and handlers in SetupWithManager
Jeffwan 93d5f0b
Add job validation in reconcile loop
Jeffwan 4082e03
Set defaults in onOwnerCreateFunc
Jeffwan fa844ea
Correctly update job status in apiserver
Jeffwan c434a71
Remove Flag for Kubeconfig to fix flag redefined
Jeffwan 19d03a3
Fix tensorflow job missing default port issue
Jeffwan 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 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,81 @@ | ||
// Copyright 2021 The Kubeflow Authors | ||
// | ||
// 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 validation | ||
|
||
import ( | ||
"fmt" | ||
|
||
xgboostv1 "github.com/kubeflow/tf-operator/pkg/apis/xgboost/v1" | ||
|
||
commonv1 "github.com/kubeflow/common/pkg/apis/common/v1" | ||
|
||
torchv1 "github.com/kubeflow/tf-operator/pkg/apis/pytorch/v1" | ||
) | ||
|
||
func ValidateV1XGBoostJobSpec(c *xgboostv1.XGBoostJobSpec) error { | ||
if c.XGBReplicaSpecs == nil { | ||
return fmt.Errorf("XGBoostJobSpec is not valid") | ||
} | ||
masterExists := false | ||
for rType, value := range c.XGBReplicaSpecs { | ||
if value == nil || len(value.Template.Spec.Containers) == 0 { | ||
return fmt.Errorf("XGBoostJobSpec is not valid: containers definition expected in %v", rType) | ||
} | ||
// Make sure the replica type is valid. | ||
validReplicaTypes := []commonv1.ReplicaType{xgboostv1.XGBoostReplicaTypeMaster, xgboostv1.XGBoostReplicaTypeWorker} | ||
|
||
isValidReplicaType := false | ||
for _, t := range validReplicaTypes { | ||
if t == rType { | ||
isValidReplicaType = true | ||
break | ||
} | ||
} | ||
|
||
if !isValidReplicaType { | ||
return fmt.Errorf("XGBoostReplicaType is %v but must be one of %v", rType, validReplicaTypes) | ||
} | ||
|
||
//Make sure the image is defined in the container | ||
defaultContainerPresent := false | ||
for _, container := range value.Template.Spec.Containers { | ||
if container.Image == "" { | ||
msg := fmt.Sprintf("XGBoostReplicaType is not valid: Image is undefined in the container of %v", rType) | ||
return fmt.Errorf(msg) | ||
} | ||
if container.Name == xgboostv1.DefaultContainerName { | ||
defaultContainerPresent = true | ||
} | ||
} | ||
//Make sure there has at least one container named "pytorch" | ||
if !defaultContainerPresent { | ||
msg := fmt.Sprintf("XGBoostReplicaType is not valid: There is no container named %s in %v", torchv1.DefaultContainerName, rType) | ||
return fmt.Errorf(msg) | ||
} | ||
if rType == xgboostv1.XGBoostReplicaTypeMaster { | ||
masterExists = true | ||
if value.Replicas != nil && int(*value.Replicas) != 1 { | ||
return fmt.Errorf("XGBoostReplicaType is not valid: There must be only 1 master replica") | ||
} | ||
} | ||
|
||
} | ||
|
||
if !masterExists { | ||
return fmt.Errorf("XGBoostReplicaType is not valid: Master ReplicaSpec must be present") | ||
} | ||
return nil | ||
|
||
} |
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,114 @@ | ||
// Copyright 2021 The Kubeflow Authors | ||
// | ||
// 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 validation | ||
|
||
import ( | ||
"testing" | ||
|
||
commonv1 "github.com/kubeflow/common/pkg/apis/common/v1" | ||
xgboostv1 "github.com/kubeflow/tf-operator/pkg/apis/xgboost/v1" | ||
|
||
v1 "k8s.io/api/core/v1" | ||
) | ||
|
||
func TestValidateV1XGBoostJobSpec(t *testing.T) { | ||
testCases := []xgboostv1.XGBoostJobSpec{ | ||
{ | ||
XGBReplicaSpecs: nil, | ||
}, | ||
{ | ||
XGBReplicaSpecs: map[commonv1.ReplicaType]*commonv1.ReplicaSpec{ | ||
xgboostv1.XGBoostReplicaTypeWorker: &commonv1.ReplicaSpec{ | ||
Template: v1.PodTemplateSpec{ | ||
Spec: v1.PodSpec{ | ||
Containers: []v1.Container{}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
XGBReplicaSpecs: map[commonv1.ReplicaType]*commonv1.ReplicaSpec{ | ||
xgboostv1.XGBoostReplicaTypeWorker: &commonv1.ReplicaSpec{ | ||
Template: v1.PodTemplateSpec{ | ||
Spec: v1.PodSpec{ | ||
Containers: []v1.Container{ | ||
v1.Container{ | ||
Image: "", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
XGBReplicaSpecs: map[commonv1.ReplicaType]*commonv1.ReplicaSpec{ | ||
xgboostv1.XGBoostReplicaTypeWorker: &commonv1.ReplicaSpec{ | ||
Template: v1.PodTemplateSpec{ | ||
Spec: v1.PodSpec{ | ||
Containers: []v1.Container{ | ||
v1.Container{ | ||
Name: "", | ||
Image: "gcr.io/kubeflow-ci/xgboost-dist-mnist_test:1.0", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
XGBReplicaSpecs: map[commonv1.ReplicaType]*commonv1.ReplicaSpec{ | ||
xgboostv1.XGBoostReplicaTypeMaster: &commonv1.ReplicaSpec{ | ||
Replicas: xgboostv1.Int32(2), | ||
Template: v1.PodTemplateSpec{ | ||
Spec: v1.PodSpec{ | ||
Containers: []v1.Container{ | ||
v1.Container{ | ||
Name: "xgboost", | ||
Image: "gcr.io/kubeflow-ci/xgboost-dist-mnist_test:1.0", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
XGBReplicaSpecs: map[commonv1.ReplicaType]*commonv1.ReplicaSpec{ | ||
xgboostv1.XGBoostReplicaTypeWorker: &commonv1.ReplicaSpec{ | ||
Replicas: xgboostv1.Int32(1), | ||
Template: v1.PodTemplateSpec{ | ||
Spec: v1.PodSpec{ | ||
Containers: []v1.Container{ | ||
v1.Container{ | ||
Name: "xgboost", | ||
Image: "gcr.io/kubeflow-ci/xgboost-dist-mnist_test:1.0", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
for _, c := range testCases { | ||
err := ValidateV1XGBoostJobSpec(&c) | ||
if err == nil { | ||
t.Error("Failed validate the v1.XGBoostJobSpec") | ||
} | ||
} | ||
} |
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
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.
is it temporary?
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 can not find a way to workaround it. User can still use
KUBECONFIG
to specify the path of config files. This is the only user facing change to tf controller.v1 users.Next step is to build universal operator to replace tf controller and hit against all test case. Once conformance test pass. We will remove tf controller.v1