Skip to content

Commit

Permalink
fix: instance template's name having dash leads to error. (#8773) (#8774
Browse files Browse the repository at this point in the history
)
  • Loading branch information
leonliao authored Jan 10, 2025
1 parent ac3c0c8 commit d0d2d4f
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions pkg/controller/component/workload_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit d0d2d4f

Please sign in to comment.