-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcleaner.go
More file actions
36 lines (28 loc) · 1.09 KB
/
cleaner.go
File metadata and controls
36 lines (28 loc) · 1.09 KB
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
// Package cleaner is a background process that compares the kubernetes namespace list with the folders in the local git home directory, deleting what's not in the namespace list
package cleaner
import (
"log"
"os"
"k8s.io/kubernetes/pkg/api"
"github.com/deis/builder/pkg/k8s"
)
const (
dotGitSuffix = ".git"
)
// Run starts the deleted app cleaner. Every pollSleepDuration, it compares the result of nsLister.List with the directories in the top level of gitHome on the local file system. On any error, it uses log messages to output a human readable description of what happened.
func Run(gitHome string, nsLister k8s.NamespaceWatcher) error {
watcher, err := nsLister.Watch(nil, nil, "")
if err != nil {
log.Printf("unable to get watch events (%s)", err)
}
for {
event := <-watcher.ResultChan()
if event.Type == "DELETED" {
namespace := event.Object.(*api.Namespace)
appToDelete := gitHome + "/" + namespace.ObjectMeta.Name + dotGitSuffix
if err := os.RemoveAll(appToDelete); err != nil {
log.Printf("Cleaner error removing deleted app %s (%s)", appToDelete, err)
}
}
}
}