← All recipes
Moderne licensed

Find dangling Kubernetes resource references

Recipe IDorg.openrewrite.kubernetes.search.FindDanglingResourceReferencesArtifactorg.openrewrite.recipe:rewrite-kubernetes

Find resources that refer by name to a ConfigMap, Secret, ServiceAccount, Service, PersistentVolumeClaim, Role, ClusterRole, PriorityClass or scale target that this repository declares nowhere. There is no safe automated fix for a dangling reference — the name is either a typo, a leftover, or satisfied out of band — so this only reports. Namespace is ignored when resolving, a kustomization's namePrefix and nameSuffix are replayed so that the name a cluster sees resolves as well as the one on disk, and references whose value is templated, whose target kind appears nowhere in the repository, or whose target kind has a name some template computes are all left alone.

Single recipeProprietary

Usage

This recipe has no required configuration options. You’ll need the Moderne CLI configured before running the command below.

mod run . --recipe org.openrewrite.kubernetes.search.FindDanglingResourceReferences

If the recipe isn’t available locally, install it with:

mod config recipes jar install org.openrewrite.recipe:rewrite-kubernetes:RELEASE

Options

NameTypeDescription
indexFileMatcherStringFiles to index resources from. This is a glob expression, and every YAML file is indexed when it is omitted. Narrowing this manufactures findings: a reference is dangling only when nothing anywhere declares its target.
e.g. **/*.yaml
fileMatcherStringOnly report references found in matching files. This is a glob expression. The whole repository is indexed either way.
e.g. **/overlays/**/*.yaml
requireTargetKindPresentBooleanOnly report a reference when the repository declares at least one resource of the kind being referred to. A repository with no PersistentVolumeClaim in it has its claims satisfied by an operator or an administrator, and reporting them is noise. Default true.

Data tables

Structured output this recipe can produce.

  • Dangling resource referencesReferences by name to a Kubernetes resource that this repository declares nowhere.org.openrewrite.kubernetes.table.DanglingResourceReferences
  • Source files that had resultsSource files that were modified by the recipe run.org.openrewrite.table.SourcesFileResults
  • Source files that had search resultsSearch results that were found during the recipe run.org.openrewrite.table.SearchResults
  • Source files that errored on a recipeThe details of all errors produced by a recipe run.org.openrewrite.table.SourcesFileErrors
  • Recipe performanceStatistics used in analyzing the performance of recipes.org.openrewrite.table.RecipeRunStats