Class ReferenceExtractors

java.lang.Object
dev.zucca_ops.kustomtrace.parser.ReferenceExtractors

public class ReferenceExtractors extends Object
Provides various strategies (ReferenceExtractor instances) for extracting and resolving file path references from different fields within Kustomization files.

Each factory method returns a functional interface that takes the reference value (e.g., a string or a list from the Kustomization map) and the base directory of the current Kustomization file, and returns a Stream of resolved Paths.

  • Constructor Details

    • ReferenceExtractors

      public ReferenceExtractors()
  • Method Details

    • directory

      public static ReferenceExtractor directory()
      Returns a ReferenceExtractor for Kustomize fields (e.g., 'bases', 'components') that must reference directories.

      The returned extractor expects the resolved path to be a directory and will then attempt to find a kustomization definition file (e.g., "kustomization.yaml") within it.

      Returns:
      A ReferenceExtractor. Its extract method returns a stream with a single Path to the resolved kustomization definition file. The extract method may throw an InvalidReferenceException if the input path is not a directory, if no valid kustomization definition is found, or if a self-reference is detected.
    • resourceOrDirectory

      public static ReferenceExtractor resourceOrDirectory()
      Extractor for Kustomize 'resources' field entries.

      Attempts to resolve the path as a Kustomization target first. If that fails, it treats the path as a direct Kubernetes resource file.

      Returns:
      A stream containing the resolved Path to either a kustomization definition file or a validated Kubernetes resource file. method may throw an InvalidReferenceException if the input path is not a directory, target nor a valid, existing Kubernetes resource file.
    • resource

      public static ReferenceExtractor resource()
      Returns a ReferenceExtractor specifically for resolving references that must be direct Kubernetes resource files (not directories).
    • inlinePathValue

      public static ReferenceExtractor inlinePathValue(String pathField)
      Returns a ReferenceExtractor for resolving a file path found within an inline map structure, typically used in Kustomize patches (e.g., the 'path' field in a patch definition that points to a YAML fragment file).
      Parameters:
      pathField - The key within the referenceValue map (which represents the patch data) that holds the string value of the path to be resolved.
      Returns:
      A stream containing the resolved Path to the Kubernetes resource, or an empty stream if the pathField is not found or the referenceValue is not a map.
    • generatorFiles

      public static ReferenceExtractor generatorFiles()
      Returns a ReferenceExtractor for extracting file paths from the envs and files fields of generator entries such as configMapGenerator and secretGenerator. Handles parsing of key=path format in the files list.
    • configMapGeneratorFiles

      @Deprecated(forRemoval=false) public static ReferenceExtractor configMapGeneratorFiles()
      Deprecated.