Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/__test-action-helm-test-chart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ jobs:
uses: ./actions/helm/test-chart
with:
check-diff-only: false
namespace: chart-testing
helm-set: |
image.tag=${{ fromJson(needs.build-test-images.outputs.built-images).application-test.tags[0] }}
image.digest=${{ fromJson(needs.build-test-images.outputs.built-images).application-test.digest }}
Expand Down
6 changes: 6 additions & 0 deletions actions/helm/test-chart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ Mainly using [helm/chart-testing-action](https://github.com/helm/chart-testing-a
# Default: `${{ github.workspace }}`
working-directory: ${{ github.workspace }}

# Namespace used to install test releases.
# Defaults to a random namespace created for the current workflow run.
namespace: ""

# Set values for Helm chart.
# Multiple values can be set using multiline string.
# Example:
Expand Down Expand Up @@ -98,6 +102,8 @@ Mainly using [helm/chart-testing-action](https://github.com/helm/chart-testing-a
| **Input** | **Description** | **Required** | **Default** |
| --------------------------- | --------------------------------------------------------------------------------------------------- | ------------ | -------------------------------- |
| **`working-directory`** | Working directory | **false** | `${{ github.workspace }}` |
| **`namespace`** | Namespace used to install test releases. | **false** | random namespace for the run |
| | Defaults to a random namespace created for the current workflow run. | | |
| **`helm-set`** | Set values for Helm chart. | **false** | - |
| | Multiple values can be set using multiline string. | | |
| | Example: | | |
Expand Down
63 changes: 51 additions & 12 deletions actions/helm/test-chart/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ inputs:
description: "Working directory"
required: false
default: "${{ github.workspace }}"
namespace:
description: |
Namespace used to install test releases.
Defaults to a random namespace created for the current workflow run.
required: false
helm-set:
description: |
Set values for Helm chart.
Expand Down Expand Up @@ -150,6 +155,7 @@ runs:
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
INPUT_CHECK_DIFF_ONLY: ${{ inputs.check-diff-only }}
INPUT_NAMESPACE: ${{ inputs.namespace }}
CT_CONFIG_PATH: ${{ steps.check-ct-yaml.outputs.path }}
with:
script: |
Expand Down Expand Up @@ -177,9 +183,12 @@ runs:

core.setOutput('args', args.join(' '));
core.setOutput('args-json', JSON.stringify(args));
const namespace = process.env.INPUT_NAMESPACE?.trim();

core.setOutput(
'namespace',
`test-chart-${process.env.GITHUB_RUN_ID}-${randomUUID()}`,
namespace ||
`test-chart-${process.env.GITHUB_RUN_ID}-${randomUUID()}`,
);

- name: Run chart-testing (lint)
Expand Down Expand Up @@ -222,7 +231,35 @@ runs:

core.setOutput('name', secretName);

await exec.exec('kubectl', ['create', 'namespace', namespace]);
const namespaceExists = await exec.exec(
'kubectl',
['get', 'namespace', namespace],
{
ignoreReturnCode: true,
silent: true,
},
);

if (namespaceExists !== 0) {
await exec.exec('kubectl', ['create', 'namespace', namespace]);
}

const secretExists = await exec.exec(
'kubectl',
['get', 'secret', secretName, `--namespace=${namespace}`],
{
ignoreReturnCode: true,
silent: true,
},
);

if (secretExists === 0) {
core.info(
`[helm-test-chart] Reusing OCI registry secret '${secretName}' in namespace '${namespace}'.`,
);
return;
}

await exec.exec('kubectl', [
'--context',
'kind-chart-testing',
Expand Down Expand Up @@ -256,10 +293,7 @@ runs:
);
const namespace = process.env.NAMESPACE;
const ctArgs = JSON.parse(process.env.CT_ARGS_JSON ?? '[]');
const helmSetLines = [
`namespace=${namespace}`,
...(process.env.INPUT_HELM_SET ?? '').split(/\r?\n/),
]
const helmSetLines = (process.env.INPUT_HELM_SET ?? '').split(/\r?\n/)
.map((line) => line.trim())
.filter((line) => line.length > 0)
.map((line) => line.replaceAll(',', '\\,'));
Expand All @@ -279,15 +313,20 @@ runs:
);
}

const helmExtraSetArgs = `--set=${helmSetLines.join(',')}`;

await exec.exec('ct', [
const installArgs = [
'install',
...ctArgs,
'--namespace',
namespace,
'--helm-extra-set-args',
helmExtraSetArgs,
], {
];

if (helmSetLines.length > 0) {
installArgs.push(
'--helm-extra-set-args',
`--set=${helmSetLines.join(',')}`,
);
}

await exec.exec('ct', installArgs, {
cwd: workingDirectory,
});
1 change: 0 additions & 1 deletion tests/charts/application/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ A Helm chart for Kubernetes
| ingress.hosts[0].paths[0].pathType | string | `"ImplementationSpecific"` | |
| ingress.tls | list | `[]` | |
| nameOverride | string | `""` | |
| namespace | string | `"app-system"` | |
| networkPolicy.egress | list | `[]` | |
| networkPolicy.enabled | bool | `true` | |
| networkPolicy.ingress | list | `[]` | |
Expand Down
2 changes: 1 addition & 1 deletion tests/charts/application/templates/configmap.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: Secret
apiVersion: v1
metadata:
name: {{ template "test-application.fullname" . }}-config
namespace: {{ .Values.namespace | default "app-system" }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "test-application.labels" . | nindent 4 }}
type: Opaque
Expand Down
2 changes: 1 addition & 1 deletion tests/charts/application/templates/deployment.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "test-application.fullname" . }}
namespace: {{ .Values.namespace | default "app-system" }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "test-application.labels" . | nindent 4 }}
spec:
Expand Down
2 changes: 1 addition & 1 deletion tests/charts/application/templates/hpa.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "test-application.fullname" . }}
namespace: {{ .Values.namespace | default "app-system" }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "test-application.labels" . | nindent 4 }}
spec:
Expand Down
2 changes: 1 addition & 1 deletion tests/charts/application/templates/ingress.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: {{ $fullName }}
namespace: {{ .Values.namespace | default "app-system" }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "test-application.labels" . | nindent 4 }}
{{- with .Values.ingress.annotations }}
Expand Down
2 changes: 1 addition & 1 deletion tests/charts/application/templates/networkpolicy.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: {{ include "test-application.fullname" . }}
namespace: {{ .Values.namespace | default "app-system" }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "test-application.labels" . | nindent 4 }}
spec:
Expand Down
2 changes: 1 addition & 1 deletion tests/charts/application/templates/service.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: v1
kind: Service
metadata:
name: {{ include "test-application.fullname" . }}
namespace: {{ .Values.namespace | default "app-system" }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "test-application.labels" . | nindent 4 }}
spec:
Expand Down
2 changes: 1 addition & 1 deletion tests/charts/application/templates/serviceaccount.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "test-application.serviceAccountName" . }}
namespace: {{ .Values.namespace | default "app-system" }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "test-application.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
Expand Down
4 changes: 2 additions & 2 deletions tests/charts/application/templates/tests/test-connection.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: batch/v1
kind: Job
metadata:
name: "{{ include "test-application.fullname" . }}-test-connection"
namespace: {{ .Values.namespace | default "app-system" }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "test-application.labels" . | nindent 4 }}
annotations:
Expand Down Expand Up @@ -66,7 +66,7 @@ apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: "{{ include "test-application.fullname" . }}-test-connection"
namespace: {{ .Values.namespace | default "app-system" }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "test-application.labels" . | nindent 4 }}
annotations:
Expand Down
64 changes: 64 additions & 0 deletions tests/charts/application/values.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"$schema": "https://json-schema.org/draft-07/schema#",
"type": "object",
"additionalProperties": false,
"properties": {
"application": {
"type": "object"
},
"replicaCount": {
"type": "integer"
},
"image": {
"type": "object"
},
"imagePullSecrets": {
"type": "array"
},
"nameOverride": {
"type": "string"
},
"fullnameOverride": {
"type": "string"
},
"serviceAccount": {
"type": "object"
},
"podAnnotations": {
"type": "object"
},
"podSecurityContext": {
"type": "object"
},
"securityContext": {
"type": "object"
},
"service": {
"type": "object"
},
"ingress": {
"type": "object"
},
"resources": {
"type": "object"
},
"autoscaling": {
"type": "object"
},
"nodeSelector": {
"type": "object"
},
"tolerations": {
"type": "array"
},
"affinity": {
"type": "object"
},
"networkPolicy": {
"type": "object"
},
"valkey": {
"type": "object"
}
}
}
2 changes: 0 additions & 2 deletions tests/charts/application/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
---
namespace: "app-system"

application:
dbConnection: valkey
dbHost: "valkey"
Expand Down
1 change: 0 additions & 1 deletion tests/charts/umbrella-application/charts/app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ An umbrella Helm chart for Kubernetes (app component)
| ingress.hosts[0].paths[0].pathType | string | `"ImplementationSpecific"` | |
| ingress.tls | list | `[]` | |
| nameOverride | string | `""` | |
| namespace | string | `"app-system"` | |
| networkPolicy.egress | list | `[]` | |
| networkPolicy.enabled | bool | `true` | |
| networkPolicy.ingress | list | `[]` | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: v1
kind: Secret
metadata:
name: {{ include "app.fullname" . }}-config
namespace: {{ .Values.namespace | default "app-system" }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "app.labels" . | nindent 4 }}
type: Opaque
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "app.fullname" . }}
namespace: {{ .Values.namespace | default "app-system" }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "app.labels" . | nindent 4 }}
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "app.fullname" . }}
namespace: {{ .Values.namespace | default "app-system" }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "app.labels" . | nindent 4 }}
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: {{ $fullName }}
namespace: {{ .Values.namespace | default "app-system" }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "app.labels" . | nindent 4 }}
{{- with .Values.ingress.annotations }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: {{ include "app.fullname" . }}
namespace: {{ .Values.namespace | default "app-system" }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "app.labels" . | nindent 4 }}
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: v1
kind: Service
metadata:
name: {{ include "app.fullname" . }}
namespace: {{ .Values.namespace | default "app-system" }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "app.labels" . | nindent 4 }}
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "app.serviceAccountName" . }}
namespace: {{ .Values.namespace | default "app-system" }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "app.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: batch/v1
kind: Job
metadata:
name: "{{ include "app.fullname" . }}-test-connection"
namespace: {{ .Values.namespace | default "app-system" }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "app.labels" . | nindent 4 }}
annotations:
Expand Down Expand Up @@ -65,7 +65,7 @@ apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: "{{ include "app.fullname" . }}-test-connection"
namespace: {{ .Values.namespace | default "app-system" }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "app.labels" . | nindent 4 }}
annotations:
Expand Down
2 changes: 0 additions & 2 deletions tests/charts/umbrella-application/charts/app/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
# Declare variables to be passed into your templates.
---
# Namespace for the application (defaults to "app-system" if not specified)
namespace: "app-system"

app:
dbConnection: valkey
dbHost: "database"
Expand Down
Loading