-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
58 lines (49 loc) · 1.29 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
package main
import (
"fmt"
"os"
"time"
exports "github.com/redhat-cne/ptp-listener-exports"
lib "github.com/redhat-cne/ptp-listener-lib"
ptpEvent "github.com/redhat-cne/sdk-go/pkg/event/ptp"
"github.com/sirupsen/logrus"
)
const (
podName = `linuxptp-daemon-5kzpd`
nodeName = `master1`
kubeconfig = `/home/deliedit/.kube/config.bos2.cluster-2`
k8sAPI = `https://api.cluster-2.cnfcertlab.org:6443`
namespace = `openshift-ptp`
eventLocalhostPort = 9085
eventAPIRemotePort = exports.Port9085
localHTTPServerPort = 8989
)
func main() {
lib.InitPubSub()
listener := func(name string, ch <-chan exports.StoredEvent) {
for i := range ch {
logrus.Infof("[%s] got %v\n", name, i)
}
logrus.Infof("[%s] done\n", name)
}
ch1 := lib.Ps.Subscribe(string(ptpEvent.OsClockSyncStateChange))
err := lib.StartListening(
eventLocalhostPort,
eventAPIRemotePort,
localHTTPServerPort,
podName,
nodeName,
namespace,
kubeconfig,
k8sAPI,
)
if err != nil {
logrus.Errorf("could not start listening for events, err=%s", err)
os.Exit(1)
}
go listener("1", ch1)
const sleepTimeout = 1
time.Sleep(time.Minute * sleepTimeout)
lib.UnsubscribeAllEvents(fmt.Sprintf("localhost:%d", eventLocalhostPort), nodeName)
lib.Ps.Close()
}