-
Notifications
You must be signed in to change notification settings - Fork 18
/
main.go
77 lines (63 loc) · 1.41 KB
/
main.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
73
74
75
76
77
package main
import (
"flag"
"io"
"log"
"os"
"github.com/ibuildthecloud/wtfk8s/pkg/differ"
"github.com/ibuildthecloud/wtfk8s/pkg/watcher"
"github.com/rancher/wrangler/pkg/clients"
"github.com/rancher/wrangler/pkg/generic"
"github.com/rancher/wrangler/pkg/kubeconfig"
"github.com/rancher/wrangler/pkg/signals"
"github.com/sirupsen/logrus"
"k8s.io/klog/v2"
)
var (
kubeConfig = flag.String("kubeconfig", "", "Kube config location")
context = flag.String("context", "", "Kube config context")
namespace = flag.String("namespace", "", "Limit to namespace")
)
func main() {
flag.Parse()
if err := mainErr(); err != nil {
log.Fatalln(err)
}
}
func mainErr() error {
klog.SetOutput(io.Discard)
logrus.SetLevel(logrus.FatalLevel)
ctx := signals.SetupSignalContext()
restConfig := kubeconfig.GetNonInteractiveClientConfigWithContext(*kubeConfig, *context)
clients, err := clients.New(restConfig, &generic.FactoryOptions{
Namespace: *namespace,
})
if err != nil {
return err
}
watcher, err := watcher.New(clients)
if err != nil {
return err
}
for _, arg := range os.Args[1:] {
watcher.MatchName(arg)
}
differ, err := differ.New(clients)
if err != nil {
return err
}
objs, err := watcher.Start(ctx)
if err != nil {
return err
}
go func() {
for obj := range objs {
_ = differ.Print(obj)
}
}()
if err := clients.Start(ctx); err != nil {
return err
}
<-ctx.Done()
return nil
}