Skip to content
This repository was archived by the owner on Sep 19, 2022. It is now read-only.
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
26 changes: 13 additions & 13 deletions cmd/pytorch-operator.v1beta2/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

log "github.com/sirupsen/logrus"
"k8s.io/api/core/v1"
crdclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
kubeinformers "k8s.io/client-go/informers"
kubeclientset "k8s.io/client-go/kubernetes"
Expand Down Expand Up @@ -91,7 +91,10 @@ func Run(opt *options.ServerOption) error {
if err != nil {
return err
}

if !checkCRDExists(pytorchJobClientSet, opt.Namespace) {
log.Info("CRD doesn't exist. Exiting")
os.Exit(1)
}
// Create informer factory.
kubeInformerFactory := kubeinformers.NewFilteredSharedInformerFactory(kubeClientSet, resyncPeriod, opt.Namespace, nil)
pytorchJobInformerFactory := jobinformers.NewSharedInformerFactory(pytorchJobClientSet, resyncPeriod)
Expand Down Expand Up @@ -156,14 +159,6 @@ 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, v1beta2.PytorchCRD)

kubeClientSet, err := kubeclientset.NewForConfig(restclientset.AddUserAgent(config, "pytorch-operator"))
if err != nil {
return nil, nil, nil, err
Expand All @@ -182,11 +177,16 @@ 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{})
func checkCRDExists(clientset jobclientset.Interface, namespace string) bool {
_, err := clientset.KubeflowV1beta2().PyTorchJobs(namespace).List(metav1.ListOptions{})

if err != nil {
log.Error(err)
os.Exit(1)
if _, ok := err.(*errors.StatusError); ok {
if errors.IsNotFound(err) {
return false
}
}
}
return true
}
4 changes: 2 additions & 2 deletions pkg/common/util/v1beta2/unstructured/informer.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ func newFilteredUnstructuredInformer(resource schema.GroupVersionResource, clien
return cache.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
return client.Resource(resource).List(options)
return client.Resource(resource).Namespace(namespace).List(options)
},
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
return client.Resource(resource).Watch(options)
return client.Resource(resource).Namespace(namespace).Watch(options)
},
},
&unstructured.Unstructured{},
Expand Down