Skip to content

Commit

Permalink
Support kubeflow.org/paddlejob
Browse files Browse the repository at this point in the history
Signed-off-by: Yuki Iwai <yuki.iwai.tz@gmail.com>
  • Loading branch information
tenzen-y committed Sep 21, 2023
1 parent f897699 commit f228a66
Show file tree
Hide file tree
Showing 20 changed files with 1,649 additions and 1 deletion.
1 change: 1 addition & 0 deletions apis/config/v1beta1/configuration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ type Integrations struct {
// - "kubeflow.org/mpijob"
// - "ray.io/rayjob"
// - "jobset.x-k8s.io/jobset"
// - "kubeflow.org/paddlejob"
// - "kubeflow.org/pytorchjob"
// - "kubeflow.org/tfjob"
// - "kubeflow.org/xgboostjob"
Expand Down
27 changes: 27 additions & 0 deletions charts/kueue/templates/rbac/paddlejob_editor_role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# permissions for end users to edit paddlejobs.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: '{{ include "kueue.fullname" . }}-paddlejob-editor-role'
labels:
rbac.kueue.x-k8s.io/batch-admin: "true"
rbac.kueue.x-k8s.io/batch-user: "true"
rules:
- apiGroups:
- kubeflow.org
resources:
- paddlejobs
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- kubeflow.org
resources:
- paddlejobs/status
verbs:
- get
23 changes: 23 additions & 0 deletions charts/kueue/templates/rbac/paddlejob_viewer_role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# permissions for end users to view paddlejobs.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: '{{ include "kueue.fullname" . }}-paddlejob-viewer-role'
labels:
rbac.kueue.x-k8s.io/batch-admin: "true"
rbac.kueue.x-k8s.io/batch-user: "true"
rules:
- apiGroups:
- kubeflow.org
resources:
- paddlejobs
verbs:
- get
- list
- watch
- apiGroups:
- kubeflow.org
resources:
- paddlejobs/status
verbs:
- get
17 changes: 17 additions & 0 deletions charts/kueue/templates/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,23 @@ rules:
verbs:
- get
- update
- apiGroups:
- kubeflow.org
resources:
- paddlejobs
verbs:
- get
- list
- patch
- update
- watch
- apiGroups:
- kubeflow.org
resources:
- paddlejobs/status
verbs:
- get
- update
- apiGroups:
- kubeflow.org
resources:
Expand Down
1 change: 1 addition & 0 deletions charts/kueue/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ managerConfig:
- "batch/job"
- "kubeflow.org/mpijob"
- "ray.io/rayjob"
- "kubeflow.org/paddlejob"
- "kubeflow.org/pytorchjob"
- "kubeflow.org/tfjob"
- "kubeflow.org/xgboostjob"
Expand Down
2 changes: 1 addition & 1 deletion cmd/kueue/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ integrations:
{
name: "bad integrations config",
configFile: badIntegrationsConfig,
wantError: fmt.Errorf("integrations.frameworks: Unsupported value: \"unregistered/jobframework\": supported values: \"batch/job\", \"jobset.x-k8s.io/jobset\", \"kubeflow.org/mpijob\", \"kubeflow.org/pytorchjob\", \"kubeflow.org/tfjob\", \"kubeflow.org/xgboostjob\", \"ray.io/rayjob\""),
wantError: fmt.Errorf("integrations.frameworks: Unsupported value: \"unregistered/jobframework\": supported values: \"batch/job\", \"jobset.x-k8s.io/jobset\", \"kubeflow.org/mpijob\", \"kubeflow.org/paddlejob\", \"kubeflow.org/pytorchjob\", \"kubeflow.org/tfjob\", \"kubeflow.org/xgboostjob\", \"ray.io/rayjob\""),
},
}

Expand Down
1 change: 1 addition & 0 deletions config/components/manager/controller_manager_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ integrations:
- "kubeflow.org/mpijob"
- "ray.io/rayjob"
- "jobset.x-k8s.io/jobset"
- "kubeflow.org/paddlejob"
- "kubeflow.org/pytorchjob"
- "kubeflow.org/tfjob"
- "kubeflow.org/xgboostjob"
2 changes: 2 additions & 0 deletions config/components/rbac/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ resources:
- tfjob_viewer_role.yaml
- xgboostjob_editor_role.yaml
- xgboostjob_viewer_role.yaml
- paddlejob_editor_role.yaml
- paddlejob_viewer_role.yaml
27 changes: 27 additions & 0 deletions config/components/rbac/paddlejob_editor_role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# permissions for end users to edit paddlejobs.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: paddlejob-editor-role
labels:
rbac.kueue.x-k8s.io/batch-admin: "true"
rbac.kueue.x-k8s.io/batch-user: "true"
rules:
- apiGroups:
- kubeflow.org
resources:
- paddlejobs
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- kubeflow.org
resources:
- paddlejobs/status
verbs:
- get
23 changes: 23 additions & 0 deletions config/components/rbac/paddlejob_viewer_role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# permissions for end users to view paddlejobs.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: paddlejob-viewer-role
labels:
rbac.kueue.x-k8s.io/batch-admin: "true"
rbac.kueue.x-k8s.io/batch-user: "true"
rules:
- apiGroups:
- kubeflow.org
resources:
- paddlejobs
verbs:
- get
- list
- watch
- apiGroups:
- kubeflow.org
resources:
- paddlejobs/status
verbs:
- get
17 changes: 17 additions & 0 deletions config/components/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,23 @@ rules:
verbs:
- get
- update
- apiGroups:
- kubeflow.org
resources:
- paddlejobs
verbs:
- get
- list
- patch
- update
- watch
- apiGroups:
- kubeflow.org
resources:
- paddlejobs/status
verbs:
- get
- update
- apiGroups:
- kubeflow.org
resources:
Expand Down
39 changes: 39 additions & 0 deletions config/components/webhook/manifests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,25 @@ webhooks:
resources:
- jobsets
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
service:
name: webhook-service
namespace: system
path: /mutate-kubeflow-org-v1-paddlejob
failurePolicy: Fail
name: mpaddlejob.kb.io
rules:
- apiGroups:
- kubeflow.org
apiVersions:
- v1
operations:
- CREATE
resources:
- paddlejobs
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
Expand Down Expand Up @@ -241,6 +260,26 @@ webhooks:
resources:
- jobsets
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
service:
name: webhook-service
namespace: system
path: /validate-kubeflow-org-v1-paddlejob
failurePolicy: Fail
name: vpaddlejob.kb.io
rules:
- apiGroups:
- kubeflow.org
apiVersions:
- v1
operations:
- CREATE
- UPDATE
resources:
- paddlejobs
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/jobs/kubeflow/jobs/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package jobs

// Reference the job framework integration packages to ensure linking.
import (
_ "sigs.k8s.io/kueue/pkg/controller/jobs/kubeflow/jobs/paddlejob"
_ "sigs.k8s.io/kueue/pkg/controller/jobs/kubeflow/jobs/pytorchjob"
_ "sigs.k8s.io/kueue/pkg/controller/jobs/kubeflow/jobs/tfjob"
_ "sigs.k8s.io/kueue/pkg/controller/jobs/kubeflow/jobs/xgboostjob"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
Copyright 2023 The Kubernetes 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 paddlejob

import (
"context"

kftraining "github.com/kubeflow/training-operator/pkg/apis/kubeflow.org/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"sigs.k8s.io/controller-runtime/pkg/client"

"sigs.k8s.io/kueue/pkg/controller/jobframework"
"sigs.k8s.io/kueue/pkg/controller/jobs/kubeflow/kubeflowjob"
)

var (
gvk = kftraining.SchemeGroupVersion.WithKind(kftraining.PaddleJobKind)
FrameworkName = "kubeflow.org/paddlejob"
)

func init() {
utilruntime.Must(jobframework.RegisterIntegration(FrameworkName, jobframework.IntegrationCallbacks{
SetupIndexes: SetupIndexes,
NewReconciler: NewReconciler,
SetupWebhook: SetupPaddleJobWebhook,
JobType: &kftraining.PaddleJob{},
AddToScheme: kftraining.AddToScheme,
}))
}

// +kubebuilder:rbac:groups=scheduling.k8s.io,resources=priorityclasses,verbs=list;get;watch
// +kubebuilder:rbac:groups="",resources=events,verbs=create;watch;update;patch
// +kubebuilder:rbac:groups=kubeflow.org,resources=paddlejobs,verbs=get;list;watch;update;patch
// +kubebuilder:rbac:groups=kubeflow.org,resources=paddlejobs/status,verbs=get;update
// +kubebuilder:rbac:groups=kueue.x-k8s.io,resources=workloads,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=kueue.x-k8s.io,resources=workloads/status,verbs=get;update;patch
// +kubebuilder:rbac:groups=kueue.x-k8s.io,resources=workloads/finalizers,verbs=update
// +kubebuilder:rbac:groups=kueue.x-k8s.io,resources=resourceflavors,verbs=get;list;watch

var NewReconciler = jobframework.NewGenericReconciler(func() jobframework.GenericJob {
return &kubeflowjob.KubeflowJob{KFJobControl: (*JobControl)(&kftraining.PaddleJob{})}
}, nil)

type JobControl kftraining.PaddleJob

var _ kubeflowjob.KFJobControl = (*JobControl)(nil)

func (j *JobControl) Object() client.Object {
return (*kftraining.PaddleJob)(j)
}

func fromObject(o runtime.Object) *kubeflowjob.KubeflowJob {
return &kubeflowjob.KubeflowJob{KFJobControl: (*JobControl)(o.(*kftraining.PaddleJob))}
}

func (j *JobControl) GVK() schema.GroupVersionKind {
return gvk
}

func (j *JobControl) RunPolicy() *kftraining.RunPolicy {
return &j.Spec.RunPolicy
}

func (j *JobControl) ReplicaSpecs() map[kftraining.ReplicaType]*kftraining.ReplicaSpec {
return j.Spec.PaddleReplicaSpecs
}

func (j *JobControl) JobStatus() kftraining.JobStatus {
return j.Status
}

func (j *JobControl) OrderedReplicaTypes() []kftraining.ReplicaType {
return []kftraining.ReplicaType{kftraining.PaddleJobReplicaTypeMaster, kftraining.PaddleJobReplicaTypeWorker}
}

func SetupIndexes(ctx context.Context, indexer client.FieldIndexer) error {
return jobframework.SetupWorkloadOwnerIndex(ctx, indexer, gvk)
}

func GetWorkloadNameForPaddleJob(jobName string) string {
return jobframework.GetWorkloadNameForOwnerWithGVK(jobName, gvk)
}
Loading

0 comments on commit f228a66

Please sign in to comment.