Commit c0ea260f authored by Shinya Maeda's avatar Shinya Maeda
Browse files

Merge branch 'master' into 'master'

parents b04cd317 682c1330
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -136,4 +136,5 @@
| cronjob.job.livenessProbe           | If defined, enables livenessProbe in the cronjob. If not defined, it uses top-level `livenessProbe` setting to the job. (To see details about the default probes check values.yaml) | |
| cronjob.job.readinessProbe           | If defined, enables readinessProbe in the cronjob. If not defined, it uses top-level `readinessProbe` setting to the job. (To see details about the default probes check values.yaml) | |
| cronjob.activeDeadlineSeconds           | Alternative to terminate a Job: Once a Job reaches `activeDeadlineSeconds` value, all of its running Pods are terminated and the Job status will become `type: Failed` with `reason: DeadlineExceeded` | `nil` |
| customResources | This field allows to add custom resources to your Deployment. | `[]` |
+3 −0
Original line number Diff line number Diff line
{{- range .Values.customResources }}
{{- toYaml . | nindent 0 }}
{{- end }}
 No newline at end of file
+67 −0
Original line number Diff line number Diff line
package main

import (
	"strings"
	"testing"

	"github.com/gruntwork-io/terratest/modules/helm"
	"github.com/gruntwork-io/terratest/modules/k8s"
	"github.com/gruntwork-io/terratest/modules/random"
	"github.com/stretchr/testify/require"
	"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
)

func TestCustomResource(t *testing.T) {
	releaseName := "custom-resource-test"
	Template := "templates/custom-resource.yaml" // Your template file path

	tcs := []struct {
		CaseName string
		Values   map[string]string
	}{
		{
			CaseName: "test-single-custom-resource",
			Values: map[string]string{
				"customResources[0].apiVersion":    "traefik.containo.us/v1alpha1",
				"customResources[0].kind":          "IngressRoute",
				"customResources[0].metadata.name": "ingress-route",
			},
		},
		{
			CaseName: "test-multiple-custom-resources",
			Values: map[string]string{
				"customResources[0].apiVersion":    "traefik.containo.us/v1alpha1",
				"customResources[0].kind":          "IngressRoute",
				"customResources[0].metadata.name": "ingress-route",
				"customResources[1].apiVersion":    "v1",
				"customResources[1].kind":          "Pod",
				"customResources[1].metadata.name": "my-pod",
			},
		},
	}

	for _, tc := range tcs {
		t.Run(tc.CaseName, func(t *testing.T) {

			namespaceName := "test-namespace-" + strings.ToLower(random.UniqueId())

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

			output, err := helm.RenderTemplateE(t, options, helmChartPath, releaseName, []string{Template})

			if err != nil {
				t.Error(err)
				return
			}

			var renderedObjects []*unstructured.Unstructured
			helm.UnmarshalK8SYaml(t, output, &renderedObjects)

			// Check if at least one custom resource is present
			require.GreaterOrEqual(t, len(renderedObjects), 1)
		})
	}
}
+24 −0
Original line number Diff line number Diff line
@@ -299,3 +299,27 @@ cronjobs: {}
  #   extraVolumes: []
  #   extraVolumeMounts: []
  #   extraEnvFrom: []

# customResources:
#   - apiVersion: "traefik.containo.us/v1alpha1"
#     kind: "IngressRoute"
#     metadata:
#       name: "ingress-route"
#       namespace: "default"
#     spec:
#       entryPoints:
#         - "web"
#       routes:
#         - match: "Host(`{{ .Values.envName }}.{{ .Values.envURL }}`)"
#           kind: "Rule"
#           services:
#             - name: "web"
#               port: {{ .Values.service.internalPort }}
#               weight: 100
#       tls:
#         secretName: "tls-secret"
#         options:
#           name: "tls-options"
#           namespace: "default"
#           kind: "TLSOptions"
#           minVersion: "VersionTLS12"