Use traefik and fix major problems with same-pods and cronjobs #185

Open
metal3d wants to merge 7 commits from feature/move-to-traefik into master
2 changed files with 18 additions and 8 deletions
Showing only changes of commit 75dd6701a9 - Show all commits

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,
},
},
},

View File

@@ -2,7 +2,6 @@ package generator
import (
"os"
"strings"
"testing"
v1 "k8s.io/api/apps/v1"
@@ -38,9 +37,13 @@ services:
if cronJob.Spec.JobTemplate.Spec.Template.Spec.Containers[0].Image != "alpine:latest" {
t.Errorf("Expected image to be alpine, got %s", cronJob.Spec.JobTemplate.Spec.Template.Spec.Containers[0].Image)
}
combinedCommand := strings.Join(cronJob.Spec.JobTemplate.Spec.Template.Spec.Containers[0].Args, " ")
if combinedCommand != `sh -c "echo hello"` {
t.Errorf("Expected command to be sh -c \"echo hello\", got %s", combinedCommand)
if len(cronJob.Spec.JobTemplate.Spec.Template.Spec.Containers[0].Args) != 3 {
t.Errorf("Expected 3 args, got %d", len(cronJob.Spec.JobTemplate.Spec.Template.Spec.Containers[0].Args))
}
if cronJob.Spec.JobTemplate.Spec.Template.Spec.Containers[0].Args[0] != "sh" ||
cronJob.Spec.JobTemplate.Spec.Template.Spec.Containers[0].Args[1] != "-c" ||
cronJob.Spec.JobTemplate.Spec.Template.Spec.Containers[0].Args[2] != "echo hello" {
t.Errorf("Expected args [sh -c echo hello], got %v", cronJob.Spec.JobTemplate.Spec.Template.Spec.Containers[0].Args)
}
if cronJob.Spec.Schedule != "*/1 * * * *" {
t.Errorf("Expected schedule to be */1 * * * *, got %s", cronJob.Spec.Schedule)