fix(generator): use args and command
All checks were successful
Go-Tests / tests (pull_request) Successful in 1m57s
Go-Tests / sonar (pull_request) Successful in 47s

Common mistake...

- Docker and Podman uses "command" as argument to "entrypoint"
- Kubernetes uses "command" as entrypoint and "args" as argument

So, we needed to use Command and Args in all related objects.

Fixes #163
This commit is contained in:
2025-08-20 09:28:48 +02:00
parent d1f2957512
commit b7a036a3dd
4 changed files with 37 additions and 7 deletions

View File

@@ -83,9 +83,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\" }}",
Command: []string{
"sh",
"-c",
Args: []string{
mapping.Command,
},
},

View File

@@ -38,8 +38,8 @@ 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].Command, " ")
if combinedCommand != "sh -c echo hello" {
combinedCommand := strings.Join(cronJob.Spec.JobTemplate.Spec.Template.Spec.Containers[0].Args, " ")
if combinedCommand != "echo hello" {
t.Errorf("Expected command to be sh -c echo hello, got %s", combinedCommand)
}
if cronJob.Spec.Schedule != "*/1 * * * *" {

View File

@@ -137,7 +137,8 @@ func (d *Deployment) AddContainer(service types.ServiceConfig) {
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{},
},
Command: service.Command,
Command: service.Entrypoint,
Args: service.Command,
}
if _, ok := d.chart.Values[service.Name]; !ok {
d.chart.Values[service.Name] = NewValue(service, d.isMainApp)

View File

@@ -524,7 +524,7 @@ services:
t.Errorf(unmarshalError, err)
}
// find the command in the container
command := dt.Spec.Template.Spec.Containers[0].Command
command := dt.Spec.Template.Spec.Containers[0].Args
if len(command) != 3 {
t.Errorf("Expected command to have 3 elements, got %d", len(command))
}
@@ -532,3 +532,34 @@ services:
t.Errorf("Expected command to be 'sh -c', got %s", strings.Join(command, " "))
}
}
func TestEntryPoint(t *testing.T) {
composeFile := `
services:
web:
image: nginx:1.29
entrypoint: /bin/foo
command: bar baz
`
tmpDir := setup(composeFile)
defer teardown(tmpDir)
currentDir, _ := os.Getwd()
os.Chdir(tmpDir)
defer os.Chdir(currentDir)
output := internalCompileTest(t, "-s", "templates/web/deployment.yaml")
t.Logf("Output: %s", output)
deployment := v1.Deployment{}
if err := yaml.Unmarshal([]byte(output), &deployment); err != nil {
t.Errorf(unmarshalError, err)
}
entryPoint := deployment.Spec.Template.Spec.Containers[0].Command
command := deployment.Spec.Template.Spec.Containers[0].Args
if entryPoint[0] != "/bin/foo" {
t.Errorf("Expected entrypoint to be /bin/foo, got %s", entryPoint[0])
}
if len(command) != 2 || command[0] != "bar" || command[1] != "baz" {
t.Errorf("Expected command to be 'bar baz', got %s", strings.Join(command, " "))
}
}