Skip to content

feat: Helm chart install test for deployment operator #410

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

47 changes: 47 additions & 0 deletions .github/workflows/helm-chart-install-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Helm Chart Install Test

on:
push:
branches: [main]
paths:
- 'charts/**'
pull_request:
branches: [main]
paths:
- 'charts/**'
workflow_dispatch:

jobs:
helm-install-test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Helm
uses: azure/setup-helm@v3
with:
version: v3.12.3

- name: Set up kind cluster
uses: helm/[email protected]
with:
cluster_name: kind
wait: 300s

- name: Test deployment-operator chart installation
run: |
# Install the chart - this should succeed without errors
helm install deployment-operator ./charts/deployment-operator \
--set secrets.deployToken=test-token \
--set fullnameOverride=deployment-operator-test

# Verify the chart was installed
if ! helm list | grep -q deployment-operator; then
echo "Helm chart installation failed"
exit 1
fi

echo "Helm chart installed successfully"
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,23 @@ use (
Now the Go Workspace settings will allow me to use the local version of the `polly` source code when compiling and testing


# Helm Chart Tests

To test that the deployment-operator Helm chart can be successfully installed, run:

```sh
./test/helm/test-chart-install.sh
```

This script will:
1. Create a temporary Kind cluster
2. Validate the chart using `helm lint`
3. Verify template rendering with `helm template`
4. Perform a dry-run installation with `helm install --dry-run`
5. Automatically clean up the cluster when the test completes

See [test/helm/README.md](test/helm/README.md) for more details.


# Unit Tests
## Pre Reqs
Expand Down
40 changes: 40 additions & 0 deletions test/helm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Helm Chart Tests

This directory contains tests for the Helm charts in the deployment-operator project.

## Running the Chart Installation Test

The `test-chart-install.sh` script verifies that the deployment-operator Helm chart can be successfully installed in a Kubernetes cluster.

### Prerequisites

The script requires the following tools to be installed:

- [Helm](https://helm.sh/docs/intro/install/) (v3.x)
- [Kind](https://kind.sigs.k8s.io/docs/user/quick-start/#installation)
- [kubectl](https://kubernetes.io/docs/tasks/tools/#kubectl)

### Usage

From the root of the repository, run:

```bash
./test/helm/test-chart-install.sh
```

The script will:

1. Create a temporary Kind cluster with a unique name
2. Validate the chart using `helm lint`
3. Verify template rendering with `helm template`
4. Perform a dry-run installation with `helm install --dry-run`
5. Automatically clean up the cluster when the test completes

### CI/CD Integration

This test is also integrated into GitHub Actions workflows to catch Helm chart issues in PRs and pushes to the main branch.

## Test Chart Directories

- `deployment-operator/`: Test chart for the deployment-operator
- `yet-another-cloudwatch-exporter/`: Test chart for YACE integration
6 changes: 6 additions & 0 deletions test/helm/deployment-operator/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v2
name: deployment-operator
description: Test chart for deployment-operator
type: application
version: 0.1.0
appVersion: "0.1.0"
10 changes: 10 additions & 0 deletions test/helm/deployment-operator/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
replicaCount: 1
image:
repository: ghcr.io/pluralsh/deployment-operator
tag: "latest"
pullPolicy: IfNotPresent
serviceAccount:
create: true
fullnameOverride: "deployment-operator-test"
secrets:
deployToken: "test-token"
80 changes: 80 additions & 0 deletions test/helm/test-chart-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/bin/bash
set -e

# This script tests the deployment-operator Helm chart installation
# It verifies that the chart can be installed without errors
# Usage: ./test/helm/test-chart-install.sh

CHART_DIR="charts/deployment-operator"
RELEASE_NAME="deployment-operator-test"
NAMESPACE="default"
KIND_CLUSTER_NAME="chart-test-$(date +%s)"

echo "Testing Helm chart installation for deployment-operator..."

# Check if Helm is installed
if ! command -v helm &> /dev/null; then
echo "Error: Helm is not installed. Please install Helm first."
exit 1
fi

# Check if Kind is installed
if ! command -v kind &> /dev/null; then
echo "Error: Kind is not installed. Please install Kind first."
echo "On macOS, you can use: brew install kind"
echo "Other platforms: https://kind.sigs.k8s.io/docs/user/quick-start/#installation"
exit 1
fi

# Check if the chart directory exists
if [ ! -d "$CHART_DIR" ]; then
echo "Error: Chart directory $CHART_DIR not found."
exit 1
fi

# Setup cleanup function for graceful exit
cleanup() {
echo "Cleaning up..."
if kind get clusters | grep -q "$KIND_CLUSTER_NAME"; then
echo "Deleting Kind cluster $KIND_CLUSTER_NAME..."
kind delete cluster --name "$KIND_CLUSTER_NAME"
fi
echo "Cleanup complete."
}

# Register cleanup function to run on script exit
trap cleanup EXIT

# Create a temporary Kind cluster for testing
echo "Creating a temporary Kind cluster for testing..."
kind create cluster --name "$KIND_CLUSTER_NAME" --wait 60s

# Check cluster access
if ! kubectl cluster-info &> /dev/null; then
echo "Error: Cannot access Kubernetes cluster. Please check your kubeconfig."
exit 1
fi

echo "Kubernetes cluster is ready for testing."

# Validate the chart
echo "Validating Helm chart..."
helm lint "$CHART_DIR"

# Verify template rendering
echo "Verifying template rendering..."
helm template "$RELEASE_NAME" "$CHART_DIR" \
--set secrets.deployToken=test-token \
--set fullnameOverride="$RELEASE_NAME" > /dev/null

# Install the chart with dry-run first
echo "Performing dry-run installation..."
helm install "$RELEASE_NAME" "$CHART_DIR" \
--dry-run \
--set secrets.deployToken=test-token \
--set fullnameOverride="$RELEASE_NAME" \
--namespace "$NAMESPACE" \
--create-namespace

echo "All tests passed! The deployment-operator Helm chart is installable."
# Cleanup happens automatically via the trap
Loading