-
Notifications
You must be signed in to change notification settings - Fork 0
/
graph.go
72 lines (56 loc) · 1.61 KB
/
graph.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"flag"
"fmt"
"github.com/kelseyhightower/envconfig"
"github.com/n3wscott/knap/pkg/config"
"github.com/n3wscott/knap/pkg/graph"
"github.com/n3wscott/knap/pkg/knative"
"k8s.io/client-go/dynamic"
"log"
"os"
// Uncomment the following line to load the gcp plugin (only required to authenticate against GKE clusters).
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
)
type envConfig struct {
// Name of this pod.
Name string `envconfig:"POD_NAME" required:"true"`
// Namespace this pod exists in.
Namespace string `envconfig:"POD_NAMESPACE" required:"true"`
}
// To use:
// go run cmd/dot/graph.go cmd/dot/flags.go | dot -Tpng > output.png && open output.png
// or
// go run cmd/dot/graph.go cmd/dot/flags.go | dot -Tsvg > output.svg && open output.svg
func main() {
flag.Parse()
var env envConfig
if err := envconfig.Process("", &env); err != nil {
log.Printf("[ERROR] Failed to process env var: %s", err)
os.Exit(1)
}
cfg, err := config.BuildClientConfig(kubeconfig, cluster)
if err != nil {
log.Fatalf("Error building kubeconfig", err)
}
dynamicClient := dynamic.NewForConfigOrDie(cfg)
c := knative.New(dynamicClient)
g := graph.New(env.Namespace)
// load the brokers
for _, broker := range c.Brokers(env.Namespace) {
g.AddBroker(broker)
}
// load the sources
for _, source := range c.Sources(env.Namespace) {
g.AddSource(source)
}
// load the triggers
for _, trigger := range c.Triggers(env.Namespace) {
g.AddTrigger(trigger)
}
// load the services
for _, service := range c.KnServices(env.Namespace) {
g.AddKnService(service)
}
fmt.Print(g.String())
}