-
Notifications
You must be signed in to change notification settings - Fork 712
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 podGroup instead of PDB in v1beta2 #954
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
apiVersion: apiextensions.k8s.io/v1beta1 | ||
kind: CustomResourceDefinition | ||
metadata: | ||
name: podgroups.scheduling.incubator.k8s.io | ||
spec: | ||
group: scheduling.incubator.k8s.io | ||
names: | ||
kind: PodGroup | ||
plural: podgroups | ||
scope: Namespaced | ||
validation: | ||
openAPIV3Schema: | ||
properties: | ||
apiVersion: | ||
type: string | ||
kind: | ||
type: string | ||
metadata: | ||
type: object | ||
spec: | ||
properties: | ||
minMember: | ||
format: int32 | ||
type: integer | ||
type: object | ||
status: | ||
properties: | ||
succeeded: | ||
format: int32 | ||
type: integer | ||
failed: | ||
format: int32 | ||
type: integer | ||
running: | ||
format: int32 | ||
type: integer | ||
type: object | ||
type: object | ||
version: v1alpha1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ import ( | |
"fmt" | ||
"strings" | ||
|
||
"github.com/kubernetes-sigs/kube-batch/pkg/apis/scheduling/v1alpha1" | ||
kubebatchclient "github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned" | ||
log "github.com/sirupsen/logrus" | ||
"k8s.io/api/core/v1" | ||
"k8s.io/api/policy/v1beta1" | ||
|
@@ -88,6 +90,9 @@ type JobController struct { | |
// kubeClientSet is a standard kubernetes clientset. | ||
KubeClientSet kubeclientset.Interface | ||
|
||
//KubeBatchClientSet is a standard kube-batch clientset. | ||
KubeBatchClientSet kubebatchclient.Interface | ||
|
||
// podLister can list/get pods from the shared informer's store. | ||
PodLister corelisters.PodLister | ||
|
||
|
@@ -135,6 +140,7 @@ func NewJobController( | |
reconcilerSyncPeriod metav1.Duration, | ||
enableGangScheduling bool, | ||
kubeClientSet kubeclientset.Interface, | ||
kubeBatchClientSet kubebatchclient.Interface, | ||
kubeInformerFactory kubeinformers.SharedInformerFactory, | ||
workQueueName string) JobController { | ||
|
||
|
@@ -160,14 +166,15 @@ func NewJobController( | |
} | ||
|
||
jc := JobController{ | ||
Controller: controllerImpl, | ||
Config: jobControllerConfig, | ||
PodControl: realPodControl, | ||
ServiceControl: realServiceControl, | ||
KubeClientSet: kubeClientSet, | ||
Expectations: controller.NewControllerExpectations(), | ||
WorkQueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), workQueueName), | ||
Recorder: recorder, | ||
Controller: controllerImpl, | ||
Config: jobControllerConfig, | ||
PodControl: realPodControl, | ||
ServiceControl: realServiceControl, | ||
KubeClientSet: kubeClientSet, | ||
KubeBatchClientSet: kubeBatchClientSet, | ||
Expectations: controller.NewControllerExpectations(), | ||
WorkQueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), workQueueName), | ||
Recorder: recorder, | ||
} | ||
return jc | ||
|
||
|
@@ -197,6 +204,31 @@ func (jc *JobController) GenLabels(jobName string) map[string]string { | |
} | ||
} | ||
|
||
func (jc *JobController) SyncPodGroup(job metav1.Object, minAvailableReplicas int32) (*v1alpha1.PodGroup, error) { | ||
|
||
kubeBatchClientInterface := jc.KubeBatchClientSet | ||
// Check whether podGroup exists or not | ||
podGroup, err := kubeBatchClientInterface.SchedulingV1alpha1().PodGroups(job.GetNamespace()).Get(job.GetName(), metav1.GetOptions{}) | ||
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. nitpick: use jc.KubeBatchClientSet directly? |
||
if err == nil { | ||
return podGroup, nil | ||
} | ||
|
||
// create podGroup for gang scheduling by kube-batch | ||
minAvailable := intstr.FromInt(int(minAvailableReplicas)) | ||
createPodGroup := &v1alpha1.PodGroup{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: job.GetName(), | ||
OwnerReferences: []metav1.OwnerReference{ | ||
*jc.GenOwnerReference(job), | ||
}, | ||
}, | ||
Spec: v1alpha1.PodGroupSpec{ | ||
MinMember: minAvailable.IntVal, | ||
}, | ||
} | ||
return kubeBatchClientInterface.SchedulingV1alpha1().PodGroups(job.GetNamespace()).Create(createPodGroup) | ||
} | ||
|
||
// SyncPdb will create a PDB for gang scheduling by kube-arbitrator. | ||
func (jc *JobController) SyncPdb(job metav1.Object, minAvailableReplicas int32) (*v1beta1.PodDisruptionBudget, error) { | ||
labelJobName := jc.Controller.GetJobNameLabelKey() | ||
|
@@ -231,6 +263,25 @@ func (jc *JobController) SyncPdb(job metav1.Object, minAvailableReplicas int32) | |
return jc.KubeClientSet.PolicyV1beta1().PodDisruptionBudgets(job.GetNamespace()).Create(createPdb) | ||
} | ||
|
||
func (jc *JobController) DeletePodGroup(job metav1.Object) error { | ||
kubeBatchClientInterface := jc.KubeBatchClientSet | ||
|
||
//check whether podGroup exists or not | ||
_, err := kubeBatchClientInterface.SchedulingV1alpha1().PodGroups(job.GetNamespace()).Get(job.GetName(), metav1.GetOptions{}) | ||
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. nitpick: use jc.KubeBatchClientSet directly? |
||
if err != nil && k8serrors.IsNotFound(err) { | ||
return nil | ||
} | ||
|
||
log.Infof("Deleting PodGroup %s", job.GetName()) | ||
|
||
//delete podGroup | ||
err = kubeBatchClientInterface.SchedulingV1alpha1().PodGroups(job.GetNamespace()).Delete(job.GetName(), &metav1.DeleteOptions{}) | ||
if err != nil { | ||
return fmt.Errorf("unable to delete PodGroup: %v", err) | ||
} | ||
return nil | ||
} | ||
|
||
func (jc *JobController) DeletePdb(job metav1.Object) error { | ||
|
||
// Check the pdb exist or not | ||
|
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.
let's use 0.4
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.
When using using v0.4 of kube-batch, there is dependency conflict for k8s.io/api, which in kubeflow, v1.11.2 is used but in kube-batch 1.13.2 is used, that is why v0.3 is used for kube-batch
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.
@richardsliu , any plan to upgrade k8s version? 1.14 is going to be release, and upstream only support three latest versions (1.12, 1.13, 1.14) until LTS.
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.
With v1beta2, the subresource status requires 1.13.