Skip to content

Commit

Permalink
Format codes
Browse files Browse the repository at this point in the history
  • Loading branch information
workingloong committed Jan 18, 2023
1 parent 3ec95e7 commit 410e9f3
Show file tree
Hide file tree
Showing 19 changed files with 700 additions and 1,124 deletions.
19 changes: 5 additions & 14 deletions dlrover/go/operator/api/v1alpha1/scaleplan_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package v1alpha1

import (
commonv1 "github.com/intelligent-machine-learning/easydl/dlrover/go/operator/pkg/common/api/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -41,7 +42,7 @@ type ScaleSpec struct {
CreatePods []PodMeta `json:"createPods,omitempty"`

// RemovePods are Pods to be removed
RemovePods []string `json:"removePods,omitempty"`
RemovePods []PodMeta `json:"removePods,omitempty"`

// MigratePods are Pods to be migrated to other Pods with the new resource.
MigratePods []PodMeta `json:"migratePods,omitempty"`
Expand All @@ -62,17 +63,7 @@ type ReplicaResourceSpec struct {
Replicas int `json:"replicas,omitempty"`

// Resource defines the resource of each replica
Resource ResourceSpec `json:"resource,omitempty"`
}

// ResourceSpec specifies the resources of a repalica
type ResourceSpec struct {
// CPU is the requested CPU cores of a replica
CPU string `json:"cpu,omitempty"`
// Memory is the requested memory (MB) of a replica
Memory string `json:"memory,omitempty"`
// GPU is the requested GPU of a replica
GPU string `json:"gpu,omitempty"`
Resource corev1.ResourceList `json:"resource,omitempty"`
}

// PodMeta specifies the meta of a Pod.
Expand All @@ -84,7 +75,7 @@ type PodMeta struct {
ID int `json:"id,omitempty"`

// Type is the type of the Pod
Type string `json:"type,omitempty"`
Type commonv1.ReplicaType `json:"type,omitempty"`

// RankIndex is the index of the Pod
RankIndex int `json:"randIndex,omitempty"`
Expand All @@ -93,7 +84,7 @@ type PodMeta struct {
Service string `json:"service,omitempty"`

// Resource defines the resource of each replica
Resource ResourceSpec `json:"resource,omitempty"`
Resource corev1.ResourceList `json:"resource,omitempty"`
}

// ScalePlanStatus defines the observed state of ElasticJob
Expand Down
47 changes: 25 additions & 22 deletions dlrover/go/operator/api/v1alpha1/zz_generated.deepcopy.go

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

2 changes: 1 addition & 1 deletion dlrover/go/operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (

elasticv1alpha1 "github.com/intelligent-machine-learning/easydl/dlrover/go/operator/api/v1alpha1"
"github.com/intelligent-machine-learning/easydl/dlrover/go/operator/pkg/controllers"
_ "github.com/intelligent-machine-learning/easydl/dlrover/go/operator/pkg/controllers/psstrategy"
_ "github.com/intelligent-machine-learning/easydl/dlrover/go/operator/pkg/controllers/training"
//+kubebuilder:scaffold:imports
)

Expand Down
4 changes: 3 additions & 1 deletion dlrover/go/operator/pkg/common/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,16 @@ const (
LabelReplicaTypeKey = "replica-type"
// LabelReplicaIndexKey is the key of ReplicaIndex in labels
LabelReplicaIndexKey = "replica-index"
// LabelRankIndexKey is the key of rankIndex.
LabelRankIndexKey = "rank-index"
)

// ReplicaManagers contains the manager for each ReplicaType
var ReplicaManagers = make(map[commonv1.ReplicaType]ReplicaManager)

// ReplicaManager manage pods of ReplicaType
type ReplicaManager interface {
ReconcilePods(client runtime_client.Client, job *elasticv1alpha1.ElasticJob, resourceSpec *elasticv1alpha1.ReplicaResourceSpec) error
ReconcilePods(client runtime_client.Client, job *elasticv1alpha1.ElasticJob, scalePlan *elasticv1alpha1.ScalePlan) error

SyncJobState(client runtime_client.Client, job *elasticv1alpha1.ElasticJob) error

Expand Down
5 changes: 2 additions & 3 deletions dlrover/go/operator/pkg/controllers/elasticjob_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,9 @@ func (r *ElasticJobReconciler) getJobScalePlan(job *elasticv1alpha1.ElasticJob)
}

func (r *ElasticJobReconciler) executeScaling(job *elasticv1alpha1.ElasticJob, scalePlan *elasticv1alpha1.ScalePlan) error {
for replicaType, resourceSpec := range scalePlan.Spec.ReplicaResourceSpecs {
logger.Infof("Replica %s, resource %v", replicaType, resourceSpec)
for replicaType := range scalePlan.Spec.ReplicaResourceSpecs {
replicaManager := common.ReplicaManagers[replicaType]
err := replicaManager.ReconcilePods(r.Client, job, &resourceSpec)
err := replicaManager.ReconcilePods(r.Client, job, scalePlan)
if err != nil {
r.Recorder.Eventf(
job,
Expand Down
2 changes: 1 addition & 1 deletion dlrover/go/operator/pkg/controllers/master/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (m *Manager) newJobMaster(
func (m *Manager) ReconcilePods(
client runtime_client.Client,
job *elasticv1alpha1.ElasticJob,
resourceSpec *elasticv1alpha1.ReplicaResourceSpec,
scalePlan *elasticv1alpha1.ScalePlan,
) error {
masterPod := m.newJobMaster(job, initMasterIndex)
err := client.Create(context.Background(), masterPod)
Expand Down
77 changes: 0 additions & 77 deletions dlrover/go/operator/pkg/controllers/psstrategy/chief.go

This file was deleted.

82 changes: 0 additions & 82 deletions dlrover/go/operator/pkg/controllers/psstrategy/chief_test.go

This file was deleted.

Loading

0 comments on commit 410e9f3

Please sign in to comment.