From 5f5cd0268a627e3bd72d5ef140159fe5982a8a32 Mon Sep 17 00:00:00 2001 From: Patrice Ferlet Date: Sun, 13 Jul 2025 00:07:07 +0200 Subject: [PATCH] fix(deployment): Missed the command from compose file Fixes #133 --- generator/deployment.go | 1 + generator/deployment_test.go | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/generator/deployment.go b/generator/deployment.go index 2345882..0e8fafb 100644 --- a/generator/deployment.go +++ b/generator/deployment.go @@ -136,6 +136,7 @@ func (d *Deployment) AddContainer(service types.ServiceConfig) { Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{}, }, + Command: service.Command, } if _, ok := d.chart.Values[service.Name]; !ok { d.chart.Values[service.Name] = NewValue(service, d.isMainApp) diff --git a/generator/deployment_test.go b/generator/deployment_test.go index d9e3f97..6139629 100644 --- a/generator/deployment_test.go +++ b/generator/deployment_test.go @@ -495,3 +495,39 @@ services: t.Errorf("Expected valueFrom to be set") } } + +func TestCheckCommand(t *testing.T) { + composeFile := ` +services: + web-app: + image: nginx:1.29 + command: + - sh + - -c + - |- + echo "Hello, World!" + echo "Done" +` + + // composeFile = fmt.Sprintf(composeFile, labels.Prefix()) + tmpDir := setup(composeFile) + defer teardown(tmpDir) + + currentDir, _ := os.Getwd() + os.Chdir(tmpDir) + defer os.Chdir(currentDir) + + output := internalCompileTest(t, "-s", "templates/web_app/deployment.yaml") + dt := v1.Deployment{} + if err := yaml.Unmarshal([]byte(output), &dt); err != nil { + t.Errorf(unmarshalError, err) + } + // find the command in the container + command := dt.Spec.Template.Spec.Containers[0].Command + if len(command) != 3 { + t.Errorf("Expected command to have 3 elements, got %d", len(command)) + } + if command[0] != "sh" || command[1] != "-c" { + t.Errorf("Expected command to be 'sh -c', got %s", strings.Join(command, " ")) + } +}