Skip to content

Commit

Permalink
Allow custom args on deployment spec (#143)
Browse files Browse the repository at this point in the history
* feat(custom args): enable support for custom args on deployment spec

* tests(template): add template tests for the new args parameter
  • Loading branch information
thiagosalvatore authored Aug 12, 2022
1 parent 95f3bf4 commit 67a53e5
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
5 changes: 4 additions & 1 deletion charts/k8s-service/templates/_deployment_spec.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,10 @@ spec:
command:
{{ toYaml .Values.containerCommand | indent 12 }}
{{- end }}
{{- if .Values.containerArgs }}
args:
{{ toYaml .Values.containerArgs | indent 12 }}
{{- end }}
{{- if index $hasInjectionTypes "exposePorts" }}
ports:
{{- /*
Expand Down
13 changes: 11 additions & 2 deletions charts/k8s-service/values.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
#----------------------------------------------------------------------------------------------------------------------
# CHART PARAMETERS
# This file declares the configuration input values for the k8s-service Helm chart.
Expand Down Expand Up @@ -34,7 +35,6 @@
# applicationName is a string that names the application. This is used to label the pod and to name the main application
# container in the pod spec. The label is keyed under "gruntwork.io/app-name"


#----------------------------------------------------------------------------------------------------------------------
# OPTIONAL VALUES
# These values have defaults, but may be overridden by the operator
Expand All @@ -50,6 +50,16 @@
# - "Hello World"
containerCommand: null

# containerArgs is a list of strings that indicate custom args that will be passed to the container (CMD) place of the default
# configured on the image. Omit to use the default args configured in the image
#
# Example (run echo "Hello World"):
#
# containerArgs:
# - "echo"
# - "Hello World"
containerArgs: null

# containerPorts is a map that specifies the ports to open on the container. This is a nested map: the first map lists
# the named ports, while the second layer lists the port spec. The named references can be used to refer to the specific
# port of the container in other resources, like Service.
Expand Down Expand Up @@ -126,7 +136,6 @@ securityContext: {}
# fsGroup: 2000
podSecurityContext: {}


# shutdownDelay is the number of seconds to delay the shutdown sequence of the Pod by. This is implemented as a sleep
# call in the preStop hook. By default, this chart includes a preStop hook with a shutdown delay for eventual
# consistency reasons. You can read more about why you might want to do this in
Expand Down
28 changes: 28 additions & 0 deletions test/k8s_service_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,34 @@ func TestK8SServiceWithContainerCommandHasCommandSpec(t *testing.T) {
assert.Equal(t, appContainer.Command, []string{"echo", "Hello world"})
}

// Test that omitting containerArgs does not set args attribute on the Deployment container spec.
func TestK8SServiceDefaultHasNullArgSpec(t *testing.T) {
t.Parallel()

deployment := renderK8SServiceDeploymentWithSetValues(t, map[string]string{})
renderedPodContainers := deployment.Spec.Template.Spec.Containers
require.Equal(t, len(renderedPodContainers), 1)
appContainer := renderedPodContainers[0]
assert.Nil(t, appContainer.Args)
}

// Test that setting containerCommand sets the command attribute on the Deployment container spec.
func TestK8SServiceWithContainerArgsHasArgsSpec(t *testing.T) {
t.Parallel()

deployment := renderK8SServiceDeploymentWithSetValues(
t,
map[string]string{
"containerArgs[0]": "echo",
"containerArgs[1]": "Hello world",
},
)
renderedPodContainers := deployment.Spec.Template.Spec.Containers
require.Equal(t, len(renderedPodContainers), 1)
appContainer := renderedPodContainers[0]
assert.Equal(t, appContainer.Args, []string{"echo", "Hello world"})
}

// Test that providing tls configuration to Ingress renders correctly
func TestK8SServiceIngressMultiCert(t *testing.T) {
t.Parallel()
Expand Down

0 comments on commit 67a53e5

Please sign in to comment.