-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmonitor.go
50 lines (42 loc) · 1.12 KB
/
monitor.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
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
"time"
)
var (
newNamespace = &namespace
apiHost = "http://127.0.0.1:8001"
customSecretsWithWatchEndpoint = fmt.Sprintf("/apis/cubiclerebels.com/v1/namespaces/%v/customsecrets?watch=true", *newNamespace)
customSecretsEndpoint = fmt.Sprintf("/apis/cubiclerebels.com/v1/namespaces/%v/customsecrets", *newNamespace)
)
func pollSecrets() <-chan VaultEvent {
log.Println(*newNamespace)
log.Println(fmt.Sprintf("/apis/%v/", *newNamespace))
events := make(chan VaultEvent)
log.Println(customSecretsWithWatchEndpoint)
go func() {
for {
log.Println("Polling")
// Add CallKubernetes API endpoint here
resp, err := http.Get(apiHost + customSecretsWithWatchEndpoint)
if err != nil {
log.Fatal(err)
}
decoder := json.NewDecoder(resp.Body)
for {
var vaultevent VaultEvent
err = decoder.Decode(&vaultevent)
if err != nil {
log.Println(customSecretsWithWatchEndpoint)
log.Fatal(err)
}
events <- vaultevent
}
time.Sleep(5 * time.Second)
}
}()
return events
}