From cb75cd029cd7a7ad23785ef53560f96e76d4215b Mon Sep 17 00:00:00 2001 From: Chenyu Jiang <38214590+scarlet25151@users.noreply.github.com> Date: Thu, 7 Jul 2022 15:31:11 -0700 Subject: [PATCH] fix apiserver created raycluster metrics port missing and check (#356) Co-authored-by: chenyu.jiang --- apiserver/pkg/util/cluster.go | 4 ++++ ray-operator/controllers/ray/common/pod.go | 13 ++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/apiserver/pkg/util/cluster.go b/apiserver/pkg/util/cluster.go index 2b08c0cca1..7db60207d7 100644 --- a/apiserver/pkg/util/cluster.go +++ b/apiserver/pkg/util/cluster.go @@ -141,6 +141,10 @@ func buildHeadPodTemplate(cluster *api.Cluster, spec *api.HeadGroupSpec, compute Name: "dashboard", ContainerPort: 8265, }, + { + Name: "metrics", + ContainerPort: 8080, + }, }, Resources: v1.ResourceRequirements{ Limits: v1.ResourceList{ diff --git a/ray-operator/controllers/ray/common/pod.go b/ray-operator/controllers/ray/common/pod.go index ac5773c287..ba36658bd3 100644 --- a/ray-operator/controllers/ray/common/pod.go +++ b/ray-operator/controllers/ray/common/pod.go @@ -66,7 +66,18 @@ func DefaultHeadPodTemplate(instance rayiov1alpha1.RayCluster, headSpec rayiov1a Name: "metrics", ContainerPort: int32(DefaultMetricsPort), } - podTemplate.Spec.Containers[0].Ports = append(podTemplate.Spec.Containers[0].Ports, metricsPort) + dupIndex := -1 + for i, port := range podTemplate.Spec.Containers[0].Ports { + if port.Name == metricsPort.Name { + dupIndex = i + break + } + } + if dupIndex < 0 { + podTemplate.Spec.Containers[0].Ports = append(podTemplate.Spec.Containers[0].Ports, metricsPort) + } else { + podTemplate.Spec.Containers[0].Ports[dupIndex] = metricsPort + } return podTemplate }