fix(generator): use args and command
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:
@@ -83,9 +83,7 @@ func NewCronJob(service types.ServiceConfig, chart *HelmChart, appName string) (
|
|||||||
{
|
{
|
||||||
Name: "cronjob",
|
Name: "cronjob",
|
||||||
Image: "{{ .Values." + service.Name + ".cronjob.repository.image }}:{{ default .Values." + service.Name + ".cronjob.repository.tag \"latest\" }}",
|
Image: "{{ .Values." + service.Name + ".cronjob.repository.image }}:{{ default .Values." + service.Name + ".cronjob.repository.tag \"latest\" }}",
|
||||||
Command: []string{
|
Args: []string{
|
||||||
"sh",
|
|
||||||
"-c",
|
|
||||||
mapping.Command,
|
mapping.Command,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@@ -38,8 +38,8 @@ services:
|
|||||||
if cronJob.Spec.JobTemplate.Spec.Template.Spec.Containers[0].Image != "alpine:latest" {
|
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)
|
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, " ")
|
combinedCommand := strings.Join(cronJob.Spec.JobTemplate.Spec.Template.Spec.Containers[0].Args, " ")
|
||||||
if combinedCommand != "sh -c echo hello" {
|
if combinedCommand != "echo hello" {
|
||||||
t.Errorf("Expected command to be sh -c echo hello, got %s", combinedCommand)
|
t.Errorf("Expected command to be sh -c echo hello, got %s", combinedCommand)
|
||||||
}
|
}
|
||||||
if cronJob.Spec.Schedule != "*/1 * * * *" {
|
if cronJob.Spec.Schedule != "*/1 * * * *" {
|
||||||
|
@@ -137,7 +137,8 @@ func (d *Deployment) AddContainer(service types.ServiceConfig) {
|
|||||||
Resources: corev1.ResourceRequirements{
|
Resources: corev1.ResourceRequirements{
|
||||||
Requests: corev1.ResourceList{},
|
Requests: corev1.ResourceList{},
|
||||||
},
|
},
|
||||||
Command: service.Command,
|
Command: service.Entrypoint,
|
||||||
|
Args: service.Command,
|
||||||
}
|
}
|
||||||
if _, ok := d.chart.Values[service.Name]; !ok {
|
if _, ok := d.chart.Values[service.Name]; !ok {
|
||||||
d.chart.Values[service.Name] = NewValue(service, d.isMainApp)
|
d.chart.Values[service.Name] = NewValue(service, d.isMainApp)
|
||||||
|
@@ -524,7 +524,7 @@ services:
|
|||||||
t.Errorf(unmarshalError, err)
|
t.Errorf(unmarshalError, err)
|
||||||
}
|
}
|
||||||
// find the command in the container
|
// 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 {
|
if len(command) != 3 {
|
||||||
t.Errorf("Expected command to have 3 elements, got %d", len(command))
|
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, " "))
|
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, " "))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user