-
Notifications
You must be signed in to change notification settings - Fork 993
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
Clean code #92
Clean code #92
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,12 +17,9 @@ limitations under the License. | |
package job | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/golang/glog" | ||
|
||
"k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/util/runtime" | ||
"k8s.io/apimachinery/pkg/util/wait" | ||
"k8s.io/client-go/informers" | ||
"k8s.io/client-go/kubernetes" | ||
|
@@ -38,8 +35,6 @@ import ( | |
kbinfo "github.com/kubernetes-sigs/kube-batch/pkg/client/informers/externalversions/scheduling/v1alpha1" | ||
kblister "github.com/kubernetes-sigs/kube-batch/pkg/client/listers/scheduling/v1alpha1" | ||
|
||
v1corev1 "volcano.sh/volcano/pkg/apis/bus/v1alpha1" | ||
"volcano.sh/volcano/pkg/apis/helpers" | ||
vkver "volcano.sh/volcano/pkg/client/clientset/versioned" | ||
vkscheme "volcano.sh/volcano/pkg/client/clientset/versioned/scheme" | ||
vkinfoext "volcano.sh/volcano/pkg/client/informers/externalversions" | ||
|
@@ -127,53 +122,18 @@ func NewJobController(config *rest.Config) *Controller { | |
cc.jobSynced = cc.jobInformer.Informer().HasSynced | ||
|
||
cc.cmdInformer = vkinfoext.NewSharedInformerFactory(cc.vkClients, 0).Bus().V1alpha1().Commands() | ||
cc.cmdInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{ | ||
FilterFunc: func(obj interface{}) bool { | ||
switch t := obj.(type) { | ||
case *v1corev1.Command: | ||
return helpers.ControlledBy(t, helpers.JobKind) | ||
case cache.DeletedFinalStateUnknown: | ||
if cmd, ok := t.Obj.(*v1corev1.Command); ok { | ||
return helpers.ControlledBy(cmd, helpers.JobKind) | ||
} | ||
runtime.HandleError(fmt.Errorf("unable to convert object %T to *v1.Command", obj)) | ||
return false | ||
default: | ||
runtime.HandleError(fmt.Errorf("unable to handle object %T", obj)) | ||
return false | ||
} | ||
}, | ||
Handler: cache.ResourceEventHandlerFuncs{ | ||
AddFunc: cc.addCommand, | ||
}, | ||
cc.cmdInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ | ||
AddFunc: cc.addCommand, | ||
}) | ||
cc.cmdLister = cc.cmdInformer.Lister() | ||
cc.cmdSynced = cc.cmdInformer.Informer().HasSynced | ||
|
||
cc.sharedInformers = informers.NewSharedInformerFactory(cc.kubeClients, 0) | ||
podInformer := cc.sharedInformers.Core().V1().Pods() | ||
|
||
podInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{ | ||
FilterFunc: func(obj interface{}) bool { | ||
switch t := obj.(type) { | ||
case *v1.Pod: | ||
return helpers.ControlledBy(t, helpers.JobKind) | ||
case cache.DeletedFinalStateUnknown: | ||
if pod, ok := t.Obj.(*v1.Pod); ok { | ||
return helpers.ControlledBy(pod, helpers.JobKind) | ||
} | ||
runtime.HandleError(fmt.Errorf("unable to convert object %T to *v1.Pod", obj)) | ||
return false | ||
default: | ||
runtime.HandleError(fmt.Errorf("unable to handle object %T", obj)) | ||
return false | ||
} | ||
}, | ||
Handler: cache.ResourceEventHandlerFuncs{ | ||
AddFunc: cc.addPod, | ||
UpdateFunc: cc.updatePod, | ||
DeleteFunc: cc.deletePod, | ||
}, | ||
podInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ | ||
AddFunc: cc.addPod, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not needed, we already have many other checks in event handlers, like this
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Which is faster, just asking. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The above check is inevitable, so it's enough, if we check twice, then absolutely double time wasting |
||
UpdateFunc: cc.updatePod, | ||
DeleteFunc: cc.deletePod, | ||
}) | ||
|
||
cc.podLister = podInformer.Lister() | ||
|
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.
Can we keep the
ControllerdBy
filter logic here?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 there any command resource not managed by volcano?
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.
No for now.