Fixes command expansion
All checks were successful
Go-Tests / tests (pull_request) Successful in 1m50s
Go-Tests / sonar (pull_request) Successful in 37s

This commit is contained in:
2026-05-03 22:20:49 +02:00
parent dc7a8bc422
commit 75dd6701a9
2 changed files with 18 additions and 8 deletions

View File

@@ -8,6 +8,7 @@ import (
"katenary.io/internal/logger"
"katenary.io/internal/utils"
"github.com/mattn/go-shellwords"
"github.com/compose-spec/compose-go/v2/types"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
@@ -64,8 +65,16 @@ func NewCronJob(service types.ServiceConfig, chart *HelmChart, appName string) (
}
command := mapping.Command
var commandParts []string
if !strings.HasPrefix(command, "sh -c") && !strings.HasPrefix(command, "/bin/sh") {
command = "sh -c \"" + command + "\""
commandParts = []string{"sh", "-c", command}
} else {
parts, err := shellwords.Parse(command)
if err != nil {
commandParts = []string{"sh", "-c", command}
} else {
commandParts = parts
}
}
cronjob := &CronJob{
@@ -90,9 +99,7 @@ func NewCronJob(service types.ServiceConfig, chart *HelmChart, appName string) (
{
Name: "cronjob",
Image: "{{ .Values." + service.Name + ".cronjob.repository.image }}:{{ default .Values." + service.Name + ".cronjob.repository.tag \"latest\" }}",
Args: []string{
command,
},
Args: commandParts,
},
},
},