Skip to content
This repository was archived by the owner on Sep 19, 2022. It is now read-only.

Ensure that PyTorch CRD exists #99

Merged
merged 2 commits into from
Nov 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ required = [
name = "k8s.io/apimachinery"
branch = "release-1.10"

[[constraint]]
name = "k8s.io/apiextensions-apiserver"
branch = "release-1.10"

[[constraint]]
name = "k8s.io/code-generator"
# We can not use master since the generated package name is changed from tensorflow to kubeflow.
Expand Down
2 changes: 1 addition & 1 deletion cmd/pytorch-operator.v1beta1/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@ func (s *ServerOption) AddFlags(fs *flag.FlagSet) {

fs.BoolVar(&s.JSONLogFormat, "json-log-format", true,
"Set true to use json style log format. Set false to use plaintext style log format")
fs.BoolVar(&s.EnableGangScheduling, "enable-gang-scheduling", false, "Set true to enable gang scheduling by kube-arbitrator.")
fs.BoolVar(&s.EnableGangScheduling, "enable-gang-scheduling", false, "Set true to enable gang scheduling by kube-batch.")
}
19 changes: 19 additions & 0 deletions cmd/pytorch-operator.v1beta1/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

log "github.com/sirupsen/logrus"
"k8s.io/api/core/v1"
crdclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
kubeinformers "k8s.io/client-go/informers"
kubeclientset "k8s.io/client-go/kubernetes"
Expand Down Expand Up @@ -154,6 +155,15 @@ func Run(opt *options.ServerOption) error {
}

func createClientSets(config *restclientset.Config) (kubeclientset.Interface, kubeclientset.Interface, jobclientset.Interface, error) {

crdClient, err := crdclient.NewForConfig(config)

if err != nil {
return nil, nil, nil, err
}

checkCRDExists(crdClient, v1beta1.PytorchCRD)

kubeClientSet, err := kubeclientset.NewForConfig(restclientset.AddUserAgent(config, "pytorch-operator"))
if err != nil {
return nil, nil, nil, err
Expand All @@ -171,3 +181,12 @@ func createClientSets(config *restclientset.Config) (kubeclientset.Interface, ku

return kubeClientSet, leaderElectionClientSet, jobClientSet, nil
}

func checkCRDExists(clientset crdclient.Interface, crdName string) {
_, err := clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Get(crdName, metav1.GetOptions{})

if err != nil {
log.Error(err)
os.Exit(1)
}
}
2 changes: 2 additions & 0 deletions pkg/apis/pytorch/v1beta1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ const (
Plural = "pytorchjobs"
// Singular is the singular for pytorchJob.
Singular = "pytorchjob"
// PytorchCRD is the CRD name for PytorchJob.
PytorchCRD = "pytorchjobs.kubeflow.org"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller.v1beta1/pytorch/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (pc *PyTorchController) cleanupPyTorchJob(job *v1beta1.PyTorchJob) error {
return nil
}

// deletePyTorchJob delets the given PyTorchJob.
// deletePyTorchJob deletes the given PyTorchJob.
func (pc *PyTorchController) deletePyTorchJob(job *v1beta1.PyTorchJob) error {
return pc.jobClientSet.KubeflowV1beta1().PyTorchJobs(job.Namespace).Delete(job.Name, &metav1.DeleteOptions{})
}
2 changes: 1 addition & 1 deletion pkg/controller.v1beta1/pytorch/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (

const (
// podTemplateRestartPolicyReason is the warning reason when the restart
// policy is setted in pod template.
// policy is set in pod template.
podTemplateRestartPolicyReason = "SettedPodTemplateRestartPolicy"
exitedWithCodeReason = "ExitedWithCode"
)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading