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
52 changes: 34 additions & 18 deletions charts/kruize/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,40 @@ Kruize is an intelligent resource optimization platform that helps you optimize

## Installing the Chart

To install the chart with the release name `kruize`:
### OpenShift Installation

To install the chart with OpenShift-specific configuration:

```bash
helm install kruize ./charts/kruize
helm install kruize ./charts/kruize -f ./charts/kruize/values-openshift.yaml
```

To install in a specific namespace:

```bash
helm install kruize ./charts/kruize --namespace kruize --create-namespace
helm install kruize ./charts/kruize -f ./charts/kruize/values-openshift.yaml --namespace openshift-tuning --create-namespace
```

### Minikube Installation

To install the chart with Minikube-specific configuration:

```bash
helm install kruize ./charts/kruize -f ./charts/kruize/values-minikube.yaml
```

To install in a specific namespace:

```bash
helm install kruize ./charts/kruize -f ./charts/kruize/values-minikube.yaml --namespace monitoring --create-namespace
```

### Generic Kubernetes Installation

To install with default values (generic Kubernetes):

```bash
helm install kruize ./charts/kruize
```

## Uninstalling the Chart
Expand Down Expand Up @@ -72,7 +96,7 @@ The following table lists the configurable parameters of the Kruize chart and th
| Parameter | Description | Default |
|-----------|-------------|---------|
| `kruize.config.clusterType` | Type of cluster | `kubernetes` |
| `kruize.config.k8sType` | Kubernetes distribution type | `openshift` |
| `kruize.config.k8sType` | Kubernetes distribution type (openshift/minikube/kubernetes) | `kubernetes` |
| `kruize.config.authType` | Authentication type | `""` |
| `kruize.config.monitoringAgent` | Monitoring agent to use | `prometheus` |
| `kruize.config.monitoringService` | Monitoring service name | `prometheus-k8s` |
Expand Down Expand Up @@ -116,20 +140,12 @@ The following table lists the configurable parameters of the Kruize chart and th

| Parameter | Description | Default |
|-----------|-------------|---------|
| `kruize.config.datasource[0].name` | Name of the first datasource | `prometheus-1` |
| `kruize.config.datasource[0].provider` | Provider type | `prometheus` |
| `kruize.config.datasource[0].serviceName` | Service name | `prometheus-k8s` |
| `kruize.config.datasource[0].namespace` | Namespace | `openshift-monitoring` |
| `kruize.config.datasource[0].url` | Datasource URL | `""` |
| `kruize.config.datasource[0].authentication.type` | Authentication type | `bearer` |
| `kruize.config.datasource[0].authentication.credentials.tokenFilePath` | Token file path | `/var/run/secrets/kubernetes.io/serviceaccount/token` |
| `kruize.config.datasource[1].name` | Name of the second datasource | `thanos-1` |
| `kruize.config.datasource[1].provider` | Provider type | `prometheus` |
| `kruize.config.datasource[1].serviceName` | Service name | `thanos-querier` |
| `kruize.config.datasource[1].namespace` | Namespace | `openshift-monitoring` |
| `kruize.config.datasource[1].url` | Datasource URL | `""` |
| `kruize.config.datasource[1].authentication.type` | Authentication type | `bearer` |
| `kruize.config.datasource[1].authentication.credentials.tokenFilePath` | Token file path | `/var/run/secrets/kubernetes.io/serviceaccount/token` |
| `kruize.config.datasource` | Array of datasource configurations | `[]` (empty, platform-specific) |

**Note:** Datasource configuration is platform-specific:
- **OpenShift**: Configured in `values-openshift.yaml` with prometheus-k8s and thanos-querier in openshift-monitoring namespace
- **Minikube**: Configured in `values-minikube.yaml` with prometheus-k8s in monitoring namespace
- **Generic Kubernetes**: Empty by default, configure based on your monitoring setup

### Kruize Database Parameters

Expand Down
1 change: 1 addition & 0 deletions charts/kruize/templates/kruize_deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ metadata:
name: {{ include "kruize.deploymentName" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "kruize.labels" . | nindent 4 }}
app: {{ $fullName }}
spec:
replicas: {{ .Values.kruize.replicaCount | default 1 }}
Expand Down
16 changes: 0 additions & 16 deletions charts/kruize/templates/tests/test-connection.yaml

This file was deleted.

217 changes: 217 additions & 0 deletions charts/kruize/tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
# Kruize Helm Chart Tests

This directory contains unit tests for the Kruize Helm chart using the [helm-unittest](https://github.com/helm-unittest/helm-unittest) plugin.

## Prerequisites

Install the helm-unittest plugin:

```bash
helm plugin install https://github.com/helm-unittest/helm-unittest
```

## Running Tests

> **Note:** The default `helm unittest charts/kruize` command will not find tests in subdirectories. You must explicitly specify test file patterns using the `-f` flag.

### Run all tests
```bash
helm unittest -f 'tests/common-tests/*.yaml' -f 'tests/openshift/*.yaml' -f 'tests/minikube/*.yaml' charts/kruize
```

Or from within the chart directory:
```bash
cd charts/kruize
helm unittest -f 'tests/common-tests/*.yaml' -f 'tests/openshift/*.yaml' -f 'tests/minikube/*.yaml' .
```

### Run common tests only
```bash
cd charts/kruize
helm unittest -f 'tests/common-tests/*.yaml' .
```

### Run OpenShift-specific tests
```bash
cd charts/kruize
helm unittest -f 'tests/openshift/*.yaml' .
```

### Run Minikube-specific tests
```bash
cd charts/kruize
helm unittest -f 'tests/minikube/*.yaml' .
```

### Run tests with verbose output
```bash
cd charts/kruize
helm unittest -v -f 'tests/common-tests/*.yaml' -f 'tests/openshift/*.yaml' -f 'tests/minikube/*.yaml' .
```

### Generate JUnit Test Report
```bash
cd charts/kruize
helm unittest --output-type JUnit --output-file test-results.xml -f 'tests/common-tests/*.yaml' -f 'tests/openshift/*.yaml' -f 'tests/minikube/*.yaml' .
```

## Directory Structure

```
tests/
├── common-tests/ # Tests that work across all platforms (39 tests)
│ ├── configmap_test.yaml
│ ├── cronjobs_test.yaml
│ ├── kruize_db_deployment_test.yaml
│ ├── kruize_db_service_test.yaml
│ ├── kruize_service_test.yaml
│ ├── kruize_ui_test.yaml
│ ├── network_policy_test.yaml
│ ├── service_monitor_test.yaml
│ └── storage_test.yaml
├── openshift/ # OpenShift-specific tests (20 tests)
│ ├── kruize_deployment_test.yaml
│ └── rbac_test.yaml
└── minikube/ # Minikube-specific tests (34 tests)
├── kruize_db_deployment_minikube_test.yaml
├── kruize_deployment_minikube_test.yaml
├── network_policy_minikube_test.yaml
├── rbac_minikube_test.yaml
├── service_monitor_minikube_test.yaml
└── storage_minikube_test.yaml
```


## Environment-specific Tests

### Common Tests (`tests/common-tests/`)
Tests that work across all platforms using default `values.yaml`. These validate core functionality that is consistent regardless of deployment platform.

### OpenShift Tests (`tests/openshift/`)
Tests that use `values-openshift.yaml` to validate OpenShift-specific configurations:
- `serviceAccount.create: true` — creates a dedicated service account
- `rbac.create: true` — includes OpenShift-specific ClusterRoleBindings (cluster-monitoring-view, SCC anyuid)
- Resource requests/limits are set
- Full KAFKA_RESPONSE_FILTER_INCLUDE configuration

### Minikube Tests (`tests/minikube/`)
Tests that use `values-minikube.yaml` to validate minikube-specific configurations:
- `serviceAccount.create: false` — uses the `default` service account
- `rbac.create: false` — skips OpenShift-specific ClusterRoleBindings
- `db.pgData: ""` — PGDATA env var is not set
- `db.volumeMountPath: /var/lib/postgresql/data` — minikube postgres path
- `db.pvc.storageSize: 1Gi` — smaller storage for minikube
- `db.pvc.accessModes: [ReadWriteOnce]` — minikube storage access mode
- `db.pvc.hostPath: /data/postgres` — minikube host path
- `db.pvc.reclaimPolicy: Retain` — retain policy for minikube
- `networkPolicy.enabled: true` — network policy is enabled on minikube
- `monitoring.enabled: true` — monitoring is enabled on minikube
- Empty resource requests/limits — no resource constraints on minikube
- `KAFKA_RESPONSE_FILTER_INCLUDE: summary` — simplified kafka filter for minikube

## Test File Structure

Each test file follows the below style:

```yaml
suite: test <template-name>
templates:
- <template-file>

tests:
- it: should create a <Resource> with the correct default settings
asserts:
- hasDocuments:
count: 1
- equal:
path: kind
value: <Kind>
- equal:
path: metadata.name
value: RELEASE-NAME-<name>
# ... all default assertions grouped together

- it: should create a <Resource> with the correct settings overrides
set:
some.value: override
asserts:
- equal:
path: spec.someField
value: override

- it: should create a <Resource> in the release namespace
release:
namespace: custom-namespace
asserts:
- equal:
path: metadata.namespace
value: custom-namespace
```

## Common Assertions

- `equal` - Checks if a value equals the expected value
- `notEqual` - Checks if a value does not equal the expected value
- `exists` - Checks if a path exists
- `notExists` - Checks if a path does not exist
- `contains` - Checks if an array contains a specific element
- `hasDocuments` - Checks the number of documents in the output
- `matchRegex` - Checks if a value matches a regex pattern


## Adding New Tests

When adding new templates or modifying existing ones:

1. **For common functionality** (works across all platforms):
- Create or update test file in `charts/kruize/tests/common-tests/`
- Follow naming convention: `<template-name>_test.yaml`
- Use default `values.yaml`

2. **For OpenShift-specific behavior**:
- Create or update test file in `charts/kruize/tests/openshift/`
- Add `values: - ../../values-openshift.yaml` to the test suite
- Test OpenShift-specific features (RBAC, SCC, monitoring, etc.)

3. **For Minikube-specific behavior**:
- Create or update test file in `charts/kruize/tests/minikube/`
- Add `values: - ../../values-minikube.yaml` to the test suite
- Test minikube-specific overrides (empty resources, default SA, etc.)

4. Include tests for:
- Default values
- Settings overrides (using `set:`)
- Conditional resource creation (enabled/disabled flags)
- Namespace propagation (using `release.namespace`)
- Label and selector validation

## Troubleshooting

### Plugin Not Found

```bash
helm plugin list
helm plugin install https://github.com/helm-unittest/helm-unittest
```

### Test Failures

Run with verbose output to see detailed failure information:
```bash
helm unittest -v -f 'tests/common-tests/*.yaml' -f 'tests/openshift/*.yaml' -f 'tests/minikube/*.yaml' charts/kruize
```

### Debugging Specific Tests

```bash
helm unittest -f 'tests/common-tests/kruize_db_deployment_test.yaml' -v charts/kruize
helm unittest -f 'tests/openshift/kruize_deployment_test.yaml' -v charts/kruize
helm unittest -f 'tests/minikube/kruize_deployment_minikube_test.yaml' -v charts/kruize
```

## Resources

- [Helm Unittest Documentation](https://github.com/helm-unittest/helm-unittest/blob/main/DOCUMENT.md)
- [Helm Chart Testing Guide](https://helm.sh/docs/topics/chart_tests/)
60 changes: 60 additions & 0 deletions charts/kruize/tests/common-tests/configmap_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
suite: test configmap templates
templates:
- configmap_kruize.yaml
- configmap_nginx.yaml

tests:
- it: should create a kruize ConfigMap with the correct default settings
template: configmap_kruize.yaml
asserts:
- hasDocuments:
count: 1
- equal:
path: kind
value: ConfigMap
- equal:
path: apiVersion
value: v1
- equal:
path: metadata.name
value: RELEASE-NAME-kruize-config
- exists:
path: data.dbconfigjson
- exists:
path: data.kruizeconfigjson

- it: should create a kruize ConfigMap in the release namespace
template: configmap_kruize.yaml
release:
namespace: custom-namespace
asserts:
- equal:
path: metadata.namespace
value: custom-namespace

- it: should create a nginx ConfigMap with the correct default settings
template: configmap_nginx.yaml
asserts:
- hasDocuments:
count: 1
- equal:
path: kind
value: ConfigMap
- equal:
path: apiVersion
value: v1
- equal:
path: metadata.name
value: RELEASE-NAME-kruize-nginx-config
- exists:
path: data["nginx.conf"]

- it: should create a nginx ConfigMap in the release namespace
template: configmap_nginx.yaml
release:
namespace: custom-namespace
asserts:
- equal:
path: metadata.namespace
value: custom-namespace

Loading