Commit 1f21f242 authored by Mikhail Shevtsov's avatar Mikhail Shevtsov
Browse files

feat: add ability to specify command and args for the application

parent 1677049b
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -35,6 +35,8 @@
| application.secretName        | Pass in the name of a Secret which the deployment will [load all key-value pairs from the Secret as environment variables](https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#configure-all-key-value-pairs-in-a-configmap-as-container-environment-variables) in the application container. | `nil` |
| application.secretChecksum    | Pass in the checksum of the secrets referenced by `application.secretName`. | `nil` |
| application.database_url      | If present, sets the `DATABASE_URL` environment variable. If postgres is enabled this will be autogenerated. | `nil` |
| application.command           | If present, overrides docker image `ENTRYPOINT`. Needs to be an array. | `nil` |
| application.args              | If present, overrides docker image `CMD`. Needs to be an array. | `nil` |
| hpa.enabled                   | If true, enables horizontal pod autoscaler. A resource request is also required to be set, such as `resources.requests.cpu: 200m`.| `false` |
| hpa.minReplicas               |             | `1`                                |
| hpa.maxReplicas               |             | `5`                                |
+8 −0
Original line number Diff line number Diff line
@@ -80,6 +80,14 @@ spec:
      - name: {{ .Chart.Name }}
        image: {{ template "imagename" . }}
        imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- if .Values.application.command }}
        command:
{{ toYaml .Values.application.command | indent 8 }}
{{- end }}
{{- if .Values.application.args }}
        args:
{{ toYaml .Values.application.args | indent 8 }}
{{- end }}
        {{- if .Values.application.secretName }}
        envFrom:
        - secretRef:
+53 −0
Original line number Diff line number Diff line
@@ -172,6 +172,59 @@ func TestDeploymentTemplate(t *testing.T) {
		})
	}

	for _, tc := range []struct {
		CaseName        string
		Release         string
		Values          map[string]string
		ExpectedCommand []string
		ExpectedArgs    []string
	}{
		{
			CaseName: "application-command",
			Release:  "production",
			Values: map[string]string{
				"application.command[0]": "foo",
				"application.command[1]": "bar",
				"application.command[2]": "baz",
			},
			ExpectedCommand: []string{"foo", "bar", "baz"},
		},
		{
			CaseName: "application-args",
			Release:  "production",
			Values: map[string]string{
				"application.args[0]": "foo",
				"application.args[1]": "bar",
				"application.args[2]": "baz",
			},
			ExpectedArgs: []string{"foo", "bar", "baz"},
		},
	} {
		t.Run(tc.CaseName, func(t *testing.T) {
			namespaceName := "minimal-ruby-app-" + strings.ToLower(random.UniqueId())

			values := map[string]string{
				"gitlab.app": "auto-devops-examples/minimal-ruby-app",
				"gitlab.env": "prod",
			}

			mergeStringMap(values, tc.Values)

			options := &helm.Options{
				SetValues:      values,
				KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName),
			}

			output := helm.RenderTemplate(t, options, helmChartPath, tc.Release, []string{"templates/deployment.yaml"})

			var deployment appsV1.Deployment
			helm.UnmarshalK8SYaml(t, output, &deployment)

			require.Equal(t, tc.ExpectedCommand, deployment.Spec.Template.Spec.Containers[0].Command)
			require.Equal(t, tc.ExpectedArgs, deployment.Spec.Template.Spec.Containers[0].Args)
		})
	}

	// serviceAccountName
	for _, tc := range []struct {
		CaseName                   string