mirror of
https://github.com/wassname/ray.git
synced 2026-08-16 11:27:09 +08:00
[operator] Minor cleanup (#7498)
This commit is contained in:
@@ -22,30 +22,20 @@ func DefaultPodConfig(instance *rayiov1alpha1.RayCluster, podTypeName string, po
|
||||
}
|
||||
}
|
||||
|
||||
// Build a pod for the cluster instance.
|
||||
func BuildPod(conf *PodConfig) *corev1.Pod {
|
||||
// build label for cluster
|
||||
rayLabels := labelsForCluster(*conf.RayCluster, conf.PodName, conf.PodTypeName, conf.Extension.Labels)
|
||||
|
||||
// build container for pod, now only handle one container for each pod
|
||||
var containers []corev1.Container
|
||||
container := buildContainer(conf)
|
||||
containers = append(containers, container)
|
||||
|
||||
// create volume
|
||||
volumes := conf.Extension.Volumes
|
||||
// Build the containers for the pod (there is currently only one).
|
||||
containers := []corev1.Container{buildContainer(conf)}
|
||||
|
||||
spec := corev1.PodSpec{
|
||||
Volumes: volumes,
|
||||
Volumes: conf.Extension.Volumes,
|
||||
Containers: containers,
|
||||
Affinity: conf.Extension.Affinity,
|
||||
Tolerations: conf.Extension.Tolerations,
|
||||
ServiceAccountName: conf.RayCluster.Namespace,
|
||||
}
|
||||
|
||||
// build annotations and store podCompareHash for comparison
|
||||
annotations := conf.Extension.Annotations
|
||||
|
||||
pod := &corev1.Pod{
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
APIVersion: "v1",
|
||||
@@ -55,7 +45,7 @@ func BuildPod(conf *PodConfig) *corev1.Pod {
|
||||
Name: conf.PodName,
|
||||
Namespace: conf.RayCluster.Namespace,
|
||||
Labels: rayLabels,
|
||||
Annotations: annotations,
|
||||
Annotations: conf.Extension.Annotations,
|
||||
},
|
||||
Spec: spec,
|
||||
}
|
||||
@@ -63,51 +53,38 @@ func BuildPod(conf *PodConfig) *corev1.Pod {
|
||||
return pod
|
||||
}
|
||||
|
||||
// Build container for pod.
|
||||
func buildContainer(conf *PodConfig) corev1.Container {
|
||||
|
||||
redisPort := defaultRedisPort
|
||||
httpServerPort := defaultHTTPServerPort
|
||||
jobManagerPort := defaultRedisPort
|
||||
|
||||
// assign image by typeName
|
||||
image := conf.RayCluster.Spec.Images.DefaultImage
|
||||
if conf.Extension.Image != "" {
|
||||
image = conf.Extension.Image
|
||||
}
|
||||
|
||||
volumeMounts := conf.Extension.VolumeMounts
|
||||
|
||||
// add instance name and namespace to container env to identify cluster pods
|
||||
var containerEnv []corev1.EnvVar
|
||||
containerEnv = conf.Extension.ContainerEnv
|
||||
containerEnv = append(containerEnv,
|
||||
// Add instance name and namespace to container env to identify cluster pods.
|
||||
// Add pod IP address to container env.
|
||||
containerEnv := append(conf.Extension.ContainerEnv,
|
||||
corev1.EnvVar{Name: namespace, Value: conf.RayCluster.Namespace},
|
||||
corev1.EnvVar{Name: clusterName, Value: conf.RayCluster.Name})
|
||||
corev1.EnvVar{Name: clusterName, Value: conf.RayCluster.Name},
|
||||
corev1.EnvVar{Name: "MY_POD_IP", ValueFrom: &corev1.EnvVarSource{FieldRef: &corev1.ObjectFieldSelector{FieldPath: "status.podIP"}}},
|
||||
)
|
||||
|
||||
container := corev1.Container{
|
||||
return corev1.Container{
|
||||
Name: strings.ToLower(conf.PodTypeName),
|
||||
Image: image,
|
||||
Command: []string{"/bin/bash", "-c", "--"},
|
||||
Args: []string{conf.Extension.Command},
|
||||
Env: containerEnv,
|
||||
Resources: conf.Extension.Resources,
|
||||
VolumeMounts: volumeMounts,
|
||||
VolumeMounts: conf.Extension.VolumeMounts,
|
||||
ImagePullPolicy: conf.RayCluster.Spec.ImagePullPolicy,
|
||||
Ports: []corev1.ContainerPort{
|
||||
{
|
||||
ContainerPort: int32(redisPort),
|
||||
ContainerPort: int32(defaultRedisPort),
|
||||
Name: "redis",
|
||||
},
|
||||
{
|
||||
ContainerPort: int32(httpServerPort),
|
||||
ContainerPort: int32(defaultHTTPServerPort),
|
||||
Name: "http-server",
|
||||
},
|
||||
{
|
||||
ContainerPort: int32(jobManagerPort),
|
||||
Name: "job-manager",
|
||||
},
|
||||
},
|
||||
}
|
||||
return container
|
||||
}
|
||||
|
||||
@@ -20,9 +20,11 @@ func DefaultServiceConfig(instance rayiov1alpha1.RayCluster, podName string) *Se
|
||||
}
|
||||
}
|
||||
|
||||
// Build service for pod, for now only head pod will have service.
|
||||
// Build the service for a pod. Currently, there is only one service that allows
|
||||
// the worker nodes to connect to the head node.
|
||||
func ServiceForPod(conf *ServiceConfig) *corev1.Service {
|
||||
name := conf.PodName
|
||||
// Format the service name as "<cluster_name>-head."
|
||||
if strings.Contains(conf.PodName, Head) {
|
||||
name = utils.Before(conf.PodName, Head) + "head"
|
||||
}
|
||||
@@ -34,8 +36,10 @@ func ServiceForPod(conf *ServiceConfig) *corev1.Service {
|
||||
},
|
||||
Spec: corev1.ServiceSpec{
|
||||
Ports: []corev1.ServicePort{{Name: "redis", Port: int32(defaultRedisPort)}},
|
||||
ClusterIP: "None",
|
||||
// select this raycluster's component
|
||||
// TODO(edoakes): ClusterIPNone (headless service) should work but I wasn't
|
||||
// able to get the environment variables for service discovery to work.
|
||||
// ClusterIP: corev1.ClusterIPNone,
|
||||
// This selector must match the label of the head node.
|
||||
Selector: map[string]string{
|
||||
rayclusterComponent: conf.PodName,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user