-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
51 lines (41 loc) · 1.01 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
package main
import (
"log"
"os"
"strconv"
"time"
"github.com/csepulveda/secret-sync/config"
"github.com/csepulveda/secret-sync/sync"
"github.com/csepulveda/secret-sync/sync/k8s"
)
func main() {
configPath := "/etc/config/config.json"
sleep, exists := os.LookupEnv("INTERVAL")
if !exists {
sleep = "120"
}
intSleep, err := strconv.Atoi(sleep)
if err != nil {
log.Printf("bar interval env_var: %v", err)
panic("oh no")
}
for {
log.Printf("running every %d seconds\n", intSleep)
cfg, err := config.ReadConfig(configPath)
if err != nil {
log.Printf("error reading config: %v", err)
panic("oh no")
}
//Create secrets
for i := range cfg.Secrets {
log.Printf("Sync %d of %d secrets\n", i+1, len(cfg.Secrets))
err := sync.SyncSecret(cfg.Secrets[i])
if err != nil {
log.Printf("error reading config: %v", err)
}
}
//Delete secrets by sync_secret but not defined in the actual configuration
k8s.DeleteSecrets(cfg)
time.Sleep(time.Second * time.Duration(intSleep))
}
}