Lesson 15 Hooks & Tests
Theme:

Homework

Complete these tasks before the next lesson. They reinforce hook and test concepts and push you to handle failure scenarios.

Task 1: Post-Upgrade Notification Hook

Goal: Create a post-upgrade hook that simulates sending a deployment notification.

Instructions

  1. In your hookdemo chart (or a new chart), create a file templates/hooks/notify.yaml.
  2. The hook should be a Job that:
    • Runs on the post-upgrade event
    • Has a hook weight of 10
    • Uses the hook-succeeded delete policy
    • Runs a busybox container that prints: Notification: Release <release-name> upgraded successfully at <timestamp>
  3. Install the chart, then upgrade it (change any value).
  4. Verify the notification hook ran by checking logs, then confirm it was deleted (because of hook-succeeded policy).

Deliverable

The YAML file for notify.yaml and terminal output showing:

Self-check

Task 2: Simulate a Failing Hook

Goal: Understand what happens when a pre-upgrade hook fails.

Instructions

  1. Create a pre-upgrade hook Job that deliberately fails (exit code 1):
    containers:
      - name: fail-check
        image: busybox:1.36
        command: ["sh", "-c", "echo 'Validation failed!' && exit 1"]
  2. Attempt an upgrade: helm upgrade hookdemo ./hookdemo --set replicaCount=3
  3. Observe what happens — does the upgrade proceed? Check the release status.
  4. Inspect the failed Job and its logs.
  5. Remove the failing hook, then perform a successful upgrade.

Deliverable

A short write-up (100–200 words) answering:

Self-check

Task 3: Multi-Step Test Suite

Goal: Build a test suite with three ordered test pods that validate different aspects of the release.

Instructions

  1. Create three test pod templates in templates/tests/:
    • test-dns.yaml (weight -10): Resolves the service DNS name using nslookup
    • test-http.yaml (weight 0): Makes an HTTP request to the service health endpoint using wget --spider
    • test-response.yaml (weight 10): Fetches the response body and checks it contains expected content using wget -qO- | grep
  2. All three should use before-hook-creation delete policy.
  3. Install or upgrade the chart, then run helm test hookdemo --logs.
  4. Verify all three tests pass and execute in the correct order.

Deliverable

The three test YAML files and the helm test output showing all three phases as Succeeded.

Self-check

Grading Rubric

Criterion Excellent Satisfactory Needs Work
Hook annotations All three annotations (hook, weight, delete-policy) used correctly in every hook Hook and delete-policy present; weight missing or default Missing annotations or incorrect event types
Execution ordering Weights produce the intended execution order and this is verified via timestamps or logs Weights are set but order not explicitly verified No weight ordering attempted
Failure handling Clearly explains that failed pre-hooks abort the release and describes the safety benefit Observes the abort but explanation is vague Did not test a failing hook
Test suite Three distinct tests covering DNS, HTTP, and content; all pass; order verified Two tests present and passing Only one test or tests do not pass
Delete policies Demonstrates both before-hook-creation and hook-succeeded with evidence of cleanup Uses one policy correctly No delete policy set; stale resources left behind

Submission

There is no formal submission for this course. These tasks are for your own development. However:

Next lesson: Lesson 16 — continuing your Helm journey.