Skip to content

Latest commit

 

History

History
164 lines (127 loc) · 4.78 KB

File metadata and controls

164 lines (127 loc) · 4.78 KB

Helm-Unittest Upgrade to v0.5.1 - Issue #414

Overview

This document summarizes all changes made to upgrade the StackStorm Kubernetes Helm chart from using an outdated version of helm-unittest (v0.2.11 from quintush/helm-unittest) to the latest version (v0.5.1 from helm-unittest/helm-unittest).

Changes Summary

1. Repository Reference Update

  • Old: https://github.com/quintush/helm-unittest
  • New: https://github.com/helm-unittest/helm-unittest.git

The upstream repository for helm-unittest has moved from a community fork (quintush) to the official helm-unittest organization.

Files Updated:

  • .github/workflows/unit.yaml - GitHub Actions CI/CD workflow
  • tests/README.md - Documentation

2. Version Upgrade

  • Old: v0.2.11
  • New: v0.5.1

The upgrade introduces several breaking changes and new features:

  • v0.3.0: Added JSONPath support (critical for updating test syntax)
  • v0.4.x: Refactored assertion functions with clearer naming
  • v0.5.x: Additional improvements and bug fixes

Files Updated:

  • .github/workflows/unit.yaml - CI/CD workflow version
  • tests/README.md - Installation instructions

3. Test Syntax Updates for JSONPath Support

Path Syntax (JSONPath Format)

The new version requires paths to use jq-style bracket notation for keys containing special characters (dots, dashes, etc.).

Old Syntax:

path: metadata.labels.[app.kubernetes.io/name]

New Syntax:

path: metadata.labels["app.kubernetes.io/name"]

Numeric array indexing remains the same:

path: spec.template.spec.containers[0].imagePullPolicy

Files Updated: All test files in tests/unit/:

  • custom_annotations_test.yaml
  • dns_test.yaml
  • env_test.yaml
  • extra_volumes_test.yaml
  • image_entrypoint_test.yaml
  • image_pull_test.yaml
  • image_test.yaml
  • ingress_test.yaml
  • labels_test.yaml
  • overrides_test.yaml
  • packs_volumes_test.yaml
  • placement_test.yaml
  • post_start_script_test.yaml
  • resources_test.yaml
  • secrets_test.yaml
  • security_context_test.yaml
  • service_account_test.yaml
  • services_test.yaml
  • st2_conf_files_test.yaml
  • st2sensors_test.yaml

Assertion Function Refactoring

The assertion functions were refactored in v0.3.2+ for clearer semantics:

Old Function New Function Behavior
isNull notExists Path does not exist
isNotNull exists Path exists
isEmpty isNullOrEmpty Path exists but is empty or "null"
isNotEmpty isNotNullOrEmpty Path exists and is not empty

Example:

# Old syntax
- isNotNull:
    path: metadata.labels["app.kubernetes.io/name"]

# New syntax
- exists:
    path: metadata.labels["app.kubernetes.io/name"]

4. Template Fixes for imagePullSecrets Placement

The old test suite would fail when imagePullSecrets was defined but empty. The fix involves conditionally including the entire imagePullSecrets block only when a pull secret is configured.

Old Pattern:

spec:
  imagePullSecrets:
  {{- if .Values.image.pullSecret }}
  - name: {{ .Values.image.pullSecret }}
  {{- end }}

This resulted in an empty imagePullSecrets: key when no secret was configured.

New Pattern:

spec:
  {{- if .Values.image.pullSecret }}
  imagePullSecrets:
  - name: {{ .Values.image.pullSecret }}
  {{- end }}

Files Updated:

  • templates/deployments.yaml - Updated 17 instances
  • templates/jobs.yaml - Updated 7 instances
  • templates/service-account.yaml - Updated 1 instance with proper indentation fix

5. Documentation Updates

tests/README.md:

  • Updated helm-unittest repository reference from quintush to helm-unittest organization
  • Updated installation command to use v0.5.1
  • Updated documentation link to point to main branch (instead of master)

Testing & Verification

All unit tests pass with helm-unittest v0.5.1:

  • 20 test suites
  • 98 tests total
  • All assertions use new syntax and functions
  • All templates render correctly without empty keys

Running Tests Locally

# Install helm-unittest v0.5.1
helm plugin install https://github.com/helm-unittest/helm-unittest.git --version v0.5.1

# Install chart dependencies
helm dependency update

# Run unit tests
helm unittest -f 'tests/unit/*_test.yaml' .

Backward Compatibility

This upgrade introduces breaking changes in the test syntax:

  • Old helm-unittest versions (< v0.3.0) will not recognize the new JSONPath syntax
  • Assertion functions from v0.2.x are considered deprecated in v0.3.0+

References