Skip to content

wwmoraes/kubegraph

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kubegraph

Yet another kubernetes resource graph generator

Kubegraph sample

Status GitHub Issues GitHub Pull Requests

pre-commit.ci status Maintainability Test Coverage

License FOSSA Status CII Best Practices

Docker Image Size (latest semver) Docker Image Version (latest semver) Docker Pulls


📝 Table of Contents

🧐 About

Kubegraph is a CLI tool that parses kubernetes resources and generates a graph with the relations between those. The graph is done using Graphviz, and can be further customized after generation.

🏁 Getting Started

Fetch the dependencies and build with

make build

Prerequisites

Kubegraph is done using Golang 1.15, using a pure Go graphviz implementation to generate the graph.

Everything is set as a direct dependency, and go mod vendor will install for you.

Installing

It can be installed using standard go install

go install ./...

Then, if you have GOPATH on your path, you can call kubepath directly anywhere.

🔧 Running the tests

WIP, there's no tests yet 😞

🎈 Usage

kubegraph my-multidoc.yaml

or using the docker image

docker run --rm -it -v ${PWD}:/home/kubegraph wwmoraes/kubegraph:latest my-multidoc.yaml

On this example, a my-multidoc.dot file will be generated, alongside with an icons folder used by the graph. You can convert it to an image using dot, e.g.

dot -Tsvg -o my-multidoc.svg my-multidoc.dot

If your graphviz installation has been compiled with pango, cairo and rsvg, you'll also be able to generate static formats as png or jpeg. Do note that currently kubegraph uses svg icons, and cairo mess up when generating raster images with those (namely they'll either look blurred or won't be drawn at all). A future version will address this by using raster icons.

How to add support for a single/suite of custom resource definitions

First, import the scheme and add it to client-go's scheme on internal/loader/getDecoder.go@init:

import (
  "k8s.io/client-go/kubernetes/scheme"
  // import the target scheme
  myAwesomeScheme "githost.com/owner/repository/pkg/client/clientset/scheme"
)

func init() {
  // add the scheme to client-go's scheme
  _ = myAwesomeScheme.AddToScheme(scheme.Scheme)
}

then:

  1. vendor it with go mod vendor to update go.mod and go.sum

  2. add adapters for the kinds on that scheme at internal/adapters/<api-group>/<api-version>. You can copy from an existing one, or use the internal/adapters/dummy/v1/dummy.go as a guide.

  3. import your API versions on the group level (check internal/adapters/dummy/dummy.go)

  4. import the group on the top level on internal/adapters/adapters.go

  5. [optional, recommended] add a SVG icon for the new kinds on icons/ and set it on your adapter's Create function, on the call to statefulGraph.AddStyledNode

  6. regenerate the icons embedded asset module with make icons

  7. commit and profit :D

🛠 Built Using

🧑‍💻 Authors

🎉 Acknowledgements

  • Kubernetes sigs members for the excellent abstractions and interfaces available on Golang
  • @damianopetrungaro for the honest reviews and patience