Skip to content
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

Add envs in cluster service api #432

Merged
merged 12 commits into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apiserver/pkg/model/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func PopulateHeadNodeSpec(spec v1alpha1.HeadGroupSpec) *api.HeadGroupSpec {
ServiceType: string(spec.ServiceType),
Image: spec.Template.Annotations[util.RayClusterImageAnnotationKey],
ComputeTemplate: spec.Template.Annotations[util.RayClusterComputeTemplateAnnotationKey],
Envs: spec.Envs,
}

return headNodeSpec
Expand Down
4 changes: 4 additions & 0 deletions apiserver/pkg/util/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/klog/v2"
)

type RayCluster struct {
Expand All @@ -23,6 +24,8 @@ func NewRayCluster(apiCluster *api.Cluster, computeTemplateMap map[string]*api.C
computeTemplate := computeTemplateMap[apiCluster.ClusterSpec.HeadGroupSpec.ComputeTemplate]
headPodTemplate := buildHeadPodTemplate(apiCluster, apiCluster.ClusterSpec.HeadGroupSpec, computeTemplate)
headReplicas := int32(1)
//log.Info("NewRayCluster: ", "HeadGroupSpec.Envs", apiCluster.ClusterSpec.HeadGroupSpec.Envs)
klog.Warningf("NewRayCluster HeadGroupSpec.Envs: %s", apiCluster.ClusterSpec.HeadGroupSpec.Envs)
rayCluster := &rayclusterapi.RayCluster{
ObjectMeta: metav1.ObjectMeta{
Name: apiCluster.Name,
Expand All @@ -37,6 +40,7 @@ func NewRayCluster(apiCluster *api.Cluster, computeTemplateMap map[string]*api.C
Template: headPodTemplate,
Replicas: &headReplicas,
RayStartParams: apiCluster.ClusterSpec.HeadGroupSpec.RayStartParams,
Envs: apiCluster.ClusterSpec.HeadGroupSpec.Envs,
},
WorkerGroupSpecs: []rayclusterapi.WorkerGroupSpec{},
},
Expand Down
1 change: 1 addition & 0 deletions proto/cluster.proto
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ message HeadGroupSpec {
map<string, string> ray_start_params = 4;
// Optional. The volumes mount to head pod
repeated Volume volumes = 5;
map<string, string> envs = 6;
}

message WorkerGroupSpec {
Expand Down
271 changes: 144 additions & 127 deletions proto/go_client/cluster.pb.go

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions proto/swagger/cluster.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,12 @@
"$ref": "#/definitions/protoVolume"
},
"title": "Optional. The volumes mount to head pod"
},
"envs": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
},
Expand Down
1 change: 1 addition & 0 deletions ray-operator/apis/ray/v1alpha1/raycluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type HeadGroupSpec struct {
Replicas *int32 `json:"replicas,omitempty"`
// RayStartParams are the params of the start command: node-manager-port, object-store-memory, ...
RayStartParams map[string]string `json:"rayStartParams"`
Envs map[string]string `json:"Envs"`
// Template is the eaxct pod template used in K8s depoyments, statefulsets, etc.
Template v1.PodTemplateSpec `json:"template"`
}
Expand Down
9 changes: 8 additions & 1 deletion ray-operator/apis/ray/v1alpha1/zz_generated.deepcopy.go

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

5 changes: 5 additions & 0 deletions ray-operator/controllers/ray/common/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func DefaultHeadPodTemplate(instance rayiov1alpha1.RayCluster, headSpec rayiov1a
// TODO (Dmitri) The argument headPort is essentially unused;
// headPort is passed into setMissingRayStartParams but unused there for the head pod.
// To mitigate this awkwardness and reduce code redundancy, unify head and worker pod configuration logic.
log.Info("DefaultHeadPodTemplate called", "head envs ", headSpec.Envs)
MissiontoMars marked this conversation as resolved.
Show resolved Hide resolved
podTemplate := headSpec.Template
podTemplate.GenerateName = podName
if podTemplate.ObjectMeta.Namespace == "" {
Expand Down Expand Up @@ -140,6 +141,10 @@ func DefaultHeadPodTemplate(instance rayiov1alpha1.RayCluster, headSpec rayiov1a
podTemplate.Spec.Containers[0].Ports[dupIndex] = metricsPort
}

podTemplate.Spec.Containers[0].Env = append(podTemplate.Spec.Containers[0].Env, v1.EnvVar{
Name: "WANXING_TEST_ENV",
Value: "true",
})
return podTemplate
}

Expand Down
3 changes: 2 additions & 1 deletion ray-operator/controllers/ray/common/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,8 @@ func TestBuildPodWithAutoscalerOptions(t *testing.T) {
}
}

func TestDefaultHeadPodTemplate_WithAutoscalingEnabled(t *testing.T) {
func TestHeadPodTemplate_WithAutoscalingEnabled(t *testing.T) {
t.Log("TestHeadPodTemplate_WithAutoscalingEnabled called")
cluster := instance.DeepCopy()
cluster.Spec.EnableInTreeAutoscaling = &trueFlag
podName := strings.ToLower(cluster.Name + DashSymbol + string(rayiov1alpha1.HeadNode) + DashSymbol + utils.FormatInt32(0))
Expand Down
3 changes: 3 additions & 0 deletions ray-operator/controllers/ray/raycluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ func (r *RayClusterReconciler) eventReconcile(request ctrl.Request, event *v1.Ev
func (r *RayClusterReconciler) rayClusterReconcile(request ctrl.Request, instance *rayiov1alpha1.RayCluster) (ctrl.Result, error) {
_ = r.Log.WithValues("raycluster", request.NamespacedName)
r.Log.Info("reconciling RayCluster", "cluster name", request.Name)
r.Log.Info("reconciling RayCluster", "head envs", instance.Spec.HeadGroupSpec.Envs)
Jeffwan marked this conversation as resolved.
Show resolved Hide resolved
r.Log.Info("reconciling RayCluster", "head start params", instance.Spec.HeadGroupSpec.RayStartParams)

if instance.DeletionTimestamp != nil && !instance.DeletionTimestamp.IsZero() {
r.Log.Info("RayCluster is being deleted, just ignore", "cluster name", request.Name)
Expand Down Expand Up @@ -214,6 +216,7 @@ func (r *RayClusterReconciler) rayClusterReconcile(request ctrl.Request, instanc
}
return ctrl.Result{RequeueAfter: DefaultRequeueDuration}, err
}
r.Log.Info("reconciling RayCluster 2", "head envs", instance.Spec.HeadGroupSpec.Envs)
// update the status if needed
if err := r.updateStatus(instance); err != nil {
if errors.IsNotFound(err) {
Expand Down