Skip to content

Commit

Permalink
[Refactor] Move constant.go from common to utils to avoid circular de…
Browse files Browse the repository at this point in the history
…pendency (ray-project#1726)
  • Loading branch information
kevin85421 authored Dec 9, 2023
1 parent be10373 commit 84f7368
Show file tree
Hide file tree
Showing 26 changed files with 489 additions and 493 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1"
schedulerinterface "github.com/ray-project/kuberay/ray-operator/controllers/ray/batchscheduler/interface"
"github.com/ray-project/kuberay/ray-operator/controllers/ray/batchscheduler/volcano"
"github.com/ray-project/kuberay/ray-operator/controllers/ray/common"
"github.com/ray-project/kuberay/ray-operator/controllers/ray/utils"
)

var schedulerContainers = map[string]schedulerinterface.BatchSchedulerFactory{
Expand Down Expand Up @@ -55,7 +55,7 @@ func NewSchedulerManager(config *rest.Config) *SchedulerManager {
}

func (batch *SchedulerManager) GetSchedulerForCluster(app *rayv1.RayCluster) (schedulerinterface.BatchScheduler, error) {
if schedulerName, ok := app.ObjectMeta.Labels[common.RaySchedulerName]; ok {
if schedulerName, ok := app.ObjectMeta.Labels[utils.RaySchedulerName]; ok {
return batch.GetScheduler(schedulerName)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
volcanoclient "volcano.sh/apis/pkg/client/clientset/versioned"

schedulerinterface "github.com/ray-project/kuberay/ray-operator/controllers/ray/batchscheduler/interface"
"github.com/ray-project/kuberay/ray-operator/controllers/ray/common"
"github.com/ray-project/kuberay/ray-operator/controllers/ray/utils"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
quotav1 "k8s.io/apiserver/pkg/quota/v1"
Expand Down Expand Up @@ -128,7 +127,7 @@ func createPodGroup(
podGroup.Spec.Queue = queue
}

if priorityClassName, ok := app.ObjectMeta.Labels[common.RayPriorityClassName]; ok {
if priorityClassName, ok := app.ObjectMeta.Labels[utils.RayPriorityClassName]; ok {
podGroup.Spec.PriorityClassName = priorityClassName
}

Expand All @@ -140,7 +139,7 @@ func (v *VolcanoBatchScheduler) AddMetadataToPod(app *rayv1.RayCluster, pod *cor
if queue, ok := app.ObjectMeta.Labels[QueueNameLabelKey]; ok {
pod.Labels[QueueNameLabelKey] = queue
}
if priorityClassName, ok := app.ObjectMeta.Labels[common.RayPriorityClassName]; ok {
if priorityClassName, ok := app.ObjectMeta.Labels[utils.RayPriorityClassName]; ok {
pod.Spec.PriorityClassName = priorityClassName
}
pod.Spec.SchedulerName = v.Name()
Expand Down
14 changes: 7 additions & 7 deletions ray-operator/controllers/ray/common/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ const IngressClassAnnotationKey = "kubernetes.io/ingress.class"
// This is used to expose dashboard for external traffic.
func BuildIngressForHeadService(cluster rayv1.RayCluster) (*networkingv1.Ingress, error) {
labels := map[string]string{
RayClusterLabelKey: cluster.Name,
RayIDLabelKey: utils.GenerateIdentifier(cluster.Name, rayv1.HeadNode),
KubernetesApplicationNameLabelKey: ApplicationName,
KubernetesCreatedByLabelKey: ComponentName,
utils.RayClusterLabelKey: cluster.Name,
utils.RayIDLabelKey: utils.GenerateIdentifier(cluster.Name, rayv1.HeadNode),
utils.KubernetesApplicationNameLabelKey: utils.ApplicationName,
utils.KubernetesCreatedByLabelKey: utils.ComponentName,
}

// Copy other ingress configurations from cluster annotations to provide a generic way
Expand All @@ -40,7 +40,7 @@ func BuildIngressForHeadService(cluster rayv1.RayCluster) (*networkingv1.Ingress
var paths []networkingv1.HTTPIngressPath
pathType := networkingv1.PathTypeExact
servicePorts := getServicePorts(cluster)
dashboardPort := int32(DefaultDashboardPort)
dashboardPort := int32(utils.DefaultDashboardPort)
if port, ok := servicePorts["dashboard"]; ok {
dashboardPort = port
}
Expand Down Expand Up @@ -113,8 +113,8 @@ func BuildIngressForRayService(service rayv1.RayService, cluster rayv1.RayCluste
ingress.ObjectMeta.Name = headSvcName
ingress.ObjectMeta.Namespace = service.Namespace
ingress.ObjectMeta.Labels = map[string]string{
RayServiceLabelKey: service.Name,
RayIDLabelKey: utils.CheckLabel(utils.GenerateIdentifier(service.Name, rayv1.HeadNode)),
utils.RayServiceLabelKey: service.Name,
utils.RayIDLabelKey: utils.CheckLabel(utils.GenerateIdentifier(service.Name, rayv1.HeadNode)),
}

return ingress, nil
Expand Down
2 changes: 1 addition & 1 deletion ray-operator/controllers/ray/common/ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func TestBuildIngressForHeadService(t *testing.T) {
assert.Nil(t, err)

// check ingress.class annotation
actualResult := ingress.Labels[RayClusterLabelKey]
actualResult := ingress.Labels[utils.RayClusterLabelKey]
expectedResult := instanceWithIngressEnabled.Name
if !reflect.DeepEqual(expectedResult, actualResult) {
t.Fatalf("Expected `%v` but got `%v`", expectedResult, actualResult)
Expand Down
3 changes: 2 additions & 1 deletion ray-operator/controllers/ray/common/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
semver "github.com/Masterminds/semver/v3"
"github.com/google/shlex"
rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1"
"github.com/ray-project/kuberay/ray-operator/controllers/ray/utils"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"sigs.k8s.io/yaml"
Expand Down Expand Up @@ -144,7 +145,7 @@ func GetDefaultSubmitterTemplate(rayClusterInstance *rayv1.RayCluster) corev1.Po
{
Name: "ray-job-submitter",
// Use the image of the Ray head to be defensive against version mismatch issues
Image: rayClusterInstance.Spec.HeadGroupSpec.Template.Spec.Containers[RayContainerIndex].Image,
Image: rayClusterInstance.Spec.HeadGroupSpec.Template.Spec.Containers[utils.RayContainerIndex].Image,
Resources: corev1.ResourceRequirements{
Limits: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("1"),
Expand Down
3 changes: 2 additions & 1 deletion ray-operator/controllers/ray/common/job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1"
"github.com/ray-project/kuberay/ray-operator/controllers/ray/utils"
"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
)
Expand Down Expand Up @@ -197,5 +198,5 @@ func TestGetDefaultSubmitterTemplate(t *testing.T) {
},
}
template := GetDefaultSubmitterTemplate(rayCluster)
assert.Equal(t, template.Spec.Containers[0].Image, rayCluster.Spec.HeadGroupSpec.Template.Spec.Containers[RayContainerIndex].Image)
assert.Equal(t, template.Spec.Containers[0].Image, rayCluster.Spec.HeadGroupSpec.Template.Spec.Containers[utils.RayContainerIndex].Image)
}
Loading

0 comments on commit 84f7368

Please sign in to comment.