From d0d2d4f09d7ba55f7e14df5f7e31314fdeb21c79 Mon Sep 17 00:00:00 2001 From: leonliao Date: Fri, 10 Jan 2025 16:06:07 +0800 Subject: [PATCH] fix: instance template's name having dash leads to error. (#8773) (#8774) --- pkg/controller/component/workload_utils.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pkg/controller/component/workload_utils.go b/pkg/controller/component/workload_utils.go index 080abecd368..6df8c6c3c5e 100644 --- a/pkg/controller/component/workload_utils.go +++ b/pkg/controller/component/workload_utils.go @@ -164,14 +164,17 @@ func GenerateAllPodNamesToSet( func GetTemplateNameAndOrdinal(workloadName, podName string) (string, int32, error) { podSuffix := strings.Replace(podName, workloadName+"-", "", 1) - suffixArr := strings.Split(podSuffix, "-") + lastDashIndex := strings.LastIndex(podSuffix, "-") + if lastDashIndex == len(podSuffix)-1 { + return "", 0, fmt.Errorf("no pod ordinal found after the last dash") + } templateName := "" indexStr := "" - if len(suffixArr) == 2 { - templateName = suffixArr[0] - indexStr = suffixArr[1] + if lastDashIndex == -1 { + indexStr = podSuffix } else { - indexStr = suffixArr[0] + templateName = podSuffix[0:lastDashIndex] + indexStr = podSuffix[lastDashIndex+1:] } index, err := strconv.Atoi(indexStr) if err != nil {