Skip to content

Commit 6fd7906

Browse files
authored
Merge pull request #32 from gruntwork-io/yori-custom-command
Add ability to set container command
2 parents 1a06b26 + fcecba3 commit 6fd7906

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

charts/k8s-service/templates/deployment.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ spec:
7979
{{- $tag := required "containerImage.tag is required" .Values.containerImage.tag }}
8080
image: "{{ $repo }}:{{ $tag }}"
8181
imagePullPolicy: {{ .Values.containerImage.pullPolicy | default "IfNotPresent" }}
82+
{{- if .Values.containerCommand }}
83+
command:
84+
{{ toYaml .Values.containerCommand | indent 12 }}
85+
{{- end }}
8286

8387
{{- if .Values.containerPorts }}
8488
ports:

charts/k8s-service/values.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@
4040
# These values have defaults, but may be overridden by the operator
4141
#----------------------------------------------------------------------------------------------------------------------
4242

43+
# containerCommand is a list of strings that indicate a custom command to run for the container in place of the default
44+
# configured on the image. Omit to run the default command configured on the image.
45+
#
46+
# Example (run echo "Hello World"):
47+
#
48+
# containerCommand:
49+
# - "echo"
50+
# - "Hello World"
51+
containerCommand: null
52+
4353
# containerPorts is a map that specifies the ports to open on the container. This is a nested map: the first map lists
4454
# the named ports, while the second layer lists the port spec. The named references can be used to refer to the specific
4555
# port of the container in other resources, like Service.

test/k8s_service_template_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,3 +475,31 @@ func TestK8SServiceManagedCertificateDefaultsDoesNotCreateManagedCertificate(t *
475475
assert.NoError(t, err)
476476
assert.Equal(t, len(rendered), 0)
477477
}
478+
479+
// Test that omitting containerCommand does not set command attribute on the Deployment container spec.
480+
func TestK8SServiceDefaultHasNullCommandSpec(t *testing.T) {
481+
t.Parallel()
482+
483+
deployment := renderK8SServiceDeploymentWithSetValues(t, map[string]string{})
484+
renderedPodContainers := deployment.Spec.Template.Spec.Containers
485+
require.Equal(t, len(renderedPodContainers), 1)
486+
appContainer := renderedPodContainers[0]
487+
assert.Nil(t, appContainer.Command)
488+
}
489+
490+
// Test that setting containerCommand sets the command attribute on the Deployment container spec.
491+
func TestK8SServiceWithContainerCommandHasCommandSpec(t *testing.T) {
492+
t.Parallel()
493+
494+
deployment := renderK8SServiceDeploymentWithSetValues(
495+
t,
496+
map[string]string{
497+
"containerCommand[0]": "echo",
498+
"containerCommand[1]": "Hello world",
499+
},
500+
)
501+
renderedPodContainers := deployment.Spec.Template.Spec.Containers
502+
require.Equal(t, len(renderedPodContainers), 1)
503+
appContainer := renderedPodContainers[0]
504+
assert.Equal(t, appContainer.Command, []string{"echo", "Hello world"})
505+
}

0 commit comments

Comments
 (0)