-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
63 lines (54 loc) · 1.25 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
package main
import (
"flag"
"time"
log "github.com/Sirupsen/logrus"
"github.com/paulbellamy/kubewatch/docker"
"github.com/paulbellamy/kubewatch/kubernetes"
)
func main() {
var (
dockerHost string
kubeconfig string
resyncPeriod time.Duration
)
flag.StringVar(&dockerHost, "docker", "", "docker host, default is from the environment.")
flag.StringVar(&kubeconfig, "kubeconfig", "", "Kubeconfig file")
flag.DurationVar(&resyncPeriod, "resync-period", 10*time.Second, "how often to do a full resync of the kubernetes data")
flag.Parse()
// Connect to kubernetes
kube, err := kubernetes.NewClient(kubeconfig, resyncPeriod)
if err != nil {
log.Fatal(err)
}
defer kube.Close()
log.Infof("Connected to kubernetes")
// Connect to docker
d, err := docker.NewClient(dockerHost)
if err != nil {
log.Fatal(err)
}
defer d.Close()
log.Infof("Connected to docker")
errors := d.Errors()
images := d.Images()
for {
select {
case err, ok := <-errors:
if !ok {
return
}
if err != nil {
log.Error(err)
}
case image, ok := <-images:
if !ok {
return
}
log.Infof("New Image: %s:%s", image.Name, image.Version)
if err := kube.UpdateImage(image.Name, image.Version); err != nil {
log.Error(err)
}
}
}
}