Class KustomGraph

java.lang.Object
dev.zucca_ops.kustomtrace.model.KustomGraph

public class KustomGraph extends Object
Represents the complete graph of Kustomize resources and their relationships. It maintains an index of all discovered GraphNodes (Kustomizations and KustomFiles).
  • Constructor Details

    • KustomGraph

      public KustomGraph()
  • Method Details

    • addNode

      public void addNode(GraphNode node)
      Adds a GraphNode (like a Kustomization or KustomFile) to the graph. The node is indexed by its absolute, normalized path. If a node with the same path already exists, it will be replaced.
      Parameters:
      node - The GraphNode to add. Must not be null and must have a valid path.
    • getNode

      public GraphNode getNode(Path path)
      Retrieves a GraphNode from the graph by its path.
      Parameters:
      path - The path of the node to retrieve.
      Returns:
      The GraphNode if found, or null if no node exists for the given path.
    • containsNode

      public boolean containsNode(Path path)
      Checks if a node with the given path exists in the graph.
      Parameters:
      path - The path to check.
      Returns:
      true if a node with the path exists, false otherwise.
    • getRootApps

      public List<Kustomization> getRootApps()
      Gets all Kustomizations in the graph that are considered "root" applications (i.e., not depended upon by any other Kustomization).
      Returns:
      A list of root Kustomizations.
    • getRootAppsWithFile

      public List<Kustomization> getRootAppsWithFile(Path path) throws UnreferencedFileException
      Gets all root Kustomizations that directly or indirectly reference the given file path.
      Parameters:
      path - The file path to check for references.
      Returns:
      A list of root Kustomizations that depend on the given file.
      Throws:
      UnreferencedFileException - if the given path is not found as a node in the graph.
    • getAllAppFiles

      public List<Path> getAllAppFiles(Path appPath) throws KustomException
      Retrieves all file dependencies for a given application path. The input path can be a directory containing a kustomization file or a direct path to a kustomization file.
      Parameters:
      appPath - The path representing the application.
      Returns:
      A list of all unique Paths that the application depends on, including itself.
      Throws:
      KustomException - If the appPath is not a valid Kustomize application or other processing errors occur.
      IllegalArgumentException - if appPath is null.
    • getKustomFile

      public KustomFile getKustomFile(Path path)
      Retrieves a KustomFile from the graph, ensuring type safety.
      Parameters:
      path - The path of the KustomFile to retrieve.
      Returns:
      The KustomFile if found and is of the correct type, or null otherwise.
    • getKustomization

      public Kustomization getKustomization(Path path)
      Retrieves a Kustomization from the graph, ensuring type safety.
      Parameters:
      path - The path of the Kustomization to retrieve.
      Returns:
      The Kustomization if found and is of the correct type, or null otherwise.