-
Notifications
You must be signed in to change notification settings - Fork 686
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use low-level controller and handlers in SetupWithManager (#1315)
* Use low-level controller and handlers in SetupWithManager Signed-off-by: Jiaxin Shan <[email protected]> * Add job validation in reconcile loop Signed-off-by: Jiaxin Shan <[email protected]> * Set defaults in onOwnerCreateFunc Signed-off-by: Jiaxin Shan <[email protected]> * Correctly update job status in apiserver Signed-off-by: Jiaxin Shan <[email protected]> * Remove Flag for Kubeconfig to fix flag redefined CI reports `flag redefined: kubeconfig` issue and this is due to duplicate flag registration. See #1316 for more details. Signed-off-by: Jiaxin Shan <[email protected]> * Fix tensorflow job missing default port issue This is to fix original controller issue. It leverages init to register default to scheme. In our unversal operator project, we did clean up for register.go and break the case. For more details, please check #1317 (comment) Signed-off-by: Jiaxin Shan <[email protected]>
- Loading branch information
Showing
9 changed files
with
481 additions
and
128 deletions.
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.