Which Kasten policies actually use a blueprint? A quick audit script

Which Kasten policies actually use a blueprint? A quick audit script

GitHub - jdtate101/kasten-bp-report: Blueprint audit script
Blueprint audit script. Contribute to jdtate101/kasten-bp-report development by creating an account on GitHub.

I wrote a small bash script that lists every Veeam Kasten backup policy, the Kanister blueprint it uses, the application type, and how that blueprint is attached. One command, one table, and you know which policies are application-consistent and which are quietly crash-consistent.

Why this question is harder than it looks

"Which of our backups are app-consistent?" comes up in almost every Kasten conversation I have. It sounds like a simple question. In practice the answer is scattered across three different places in the cluster.

A blueprint can be referenced from the policy itself, from a separate BlueprintBinding object, or from an annotation on the workload. None of the views in the Kasten dashboard pull those together per policy. On a cluster with a few dozen policies, working it out by hand means a lot of kubectl get -o yaml and a notepad.

So I scripted it.

Three ways a blueprint gets attached

Kasten gives you three ways to tie a Kanister blueprint to an application, and they behave differently.

1. Policy hooks. The blueprint is named in the policy itself, under backupParameters.hooks. A preHook runs before the snapshot, while onSuccess and onFailure run afterwards. This is the usual pattern for quiesce/unquiesce work: freezing MongoDB, sealing Vault, putting a database into backup mode. A hook can optionally name a subject, the specific resource the blueprint acts on.

actions:
  - action: backup
    backupParameters:
      hooks:
        preHook:
          blueprint: mongo-hooks
          actionName: freeze
        onSuccess:
          blueprint: mongo-hooks
          actionName: unfreeze

2. BlueprintBindings. A BlueprintBinding in the Kasten namespace says "apply this blueprint to every resource that matches this selector". The selector can match on resource type, namespace, labels and annotations. Bindings are the scalable option: one binding can cover every PostgreSQL StatefulSet in the cluster.

3. Workload annotations. The classic approach: annotate the Deployment or StatefulSet directly.

metadata:
  annotations:
    kanister.kasten.io/blueprint: postgresql-bp

Two precedence rules matter. If a resource has an annotation and matches a binding, the binding wins. If it matches several bindings, the earliest-created one wins. It's easy to annotate a workload and not realise a binding is overriding it.

How the script works

The script is plain bash plus jq. It fetches everything up front with one kubectl call per resource type: policies, blueprints, BlueprintBindings, Deployments, StatefulSets (and DeploymentConfigs on OpenShift), namespaces and pod images. Then it walks the backup policies one at a time.

  1. Work out which namespaces the policy covers. The policy selector is converted into a namespace label selector. k10.kasten.io/appNamespace maps onto the built-in kubernetes.io/metadata.name label, so selection by name and by namespace label both work. An empty selector means every namespace.
  2. Look for hooks. Any object under spec.actions[] that names a blueprint counts, so pre, success and failure hooks are all found, on backup and export actions alike. If a policy has hooks, that's its answer and the script moves on.
  3. Evaluate BlueprintBindings. For hook-free policies, every workload in scope is tested against the enabled bindings, using Kasten's matching rules (matchAll / matchAny; type, namespace, label and annotation requirements; earliest-created wins). The namespace objects are tested too, which catches bindings aimed at namespaces, such as the OpenShift etcd backup blueprint.
  4. Check annotations. Workloads not matched by a binding are checked for kanister.kasten.io/blueprint.
  5. Otherwise, none. No hook, binding or annotation means the policy is crash-consistent only.

Two extras fall out of the same data:

  • App type detection. The script guesses the application type (mongodb, postgresql, mysql, redis, vault, etcd and about fifteen more) from container image names. It falls back to the blueprint name, then to every pod image in the policy's namespaces. That last step matters for operator-managed databases like CloudNativePG and EDB, whose pods aren't owned by a Deployment or StatefulSet.
  • Missing blueprint check. Every referenced blueprint is checked against what actually exists in kasten-io. A policy pointing at a deleted or misspelt blueprint is flagged in red.

Running it

You need bash 4+, kubectl and jq, plus cluster-wide read access. Out of the box it gives you a compact table:

./kasten-bp-report.sh
POLICY              APP TYPE    BLUEPRINT                METHOD
──────────────────  ──────────  ───────────────────────  ───────────────
edb-test            postgresql  edb-hooks                hook (pre,post)
etcd-backup-policy  etcd        ocp-etcd-backup          binding
pg-policy           postgresql  postgresql-bp            annotation
                    mysql       mysql-bp (missing)       binding
vault-backup        vault       vault-seal-unseal-hooks  hook (pre,post)
web-policy          redis       -                        none
──────────────────  ──────────  ───────────────────────  ───────────────
5 policies:  2 hook  2 binding  1 annotation  1 none
Missing blueprints in kasten-io: mysql-bp

In a terminal the method column is colour-coded: green for hooks, magenta for bindings, cyan for annotations, yellow for none. Missing blueprints show in red.

The options:

Flag

What it does

-d, --detail

One row per workload or hook phase. Adds namespace, workload, the hook action or binding name, and blueprint status. Also flags database workloads with no blueprint as none (unprotected db?).

--hide-none

Drops the none rows; the summary still counts them

-p, --policy NAME

Reports on a single policy

--csv

CSV output, for a spreadsheet or a customer report

-n, --namespace NS

Kasten namespace, if not kasten-io

--no-color

Turns off colour (it's off automatically when piped)

Detail mode is where the troubleshooting value is:

POLICY              NAMESPACE    WORKLOAD        APP TYPE    BLUEPRINT        METHOD                  HOOK ACTION / BINDING    BP STATUS
etcd-backup-policy  etcd-backup  ns/etcd-backup  etcd        ocp-etcd-backup  binding                 ocp-etcd-backup-binding  OK
pg-policy           pg           sts/postgres    postgresql  postgresql-bp    annotation              -                        OK
                    app1         sts/mysql       mysql       mysql-bp         binding                 mysql-binding            MISSING
web-policy          web          sts/redis       redis       -                none (unprotected db?)  -                        -

The footer also lists BlueprintBindings that matched nothing, and any that are disabled. Both are good clean-up candidates.