forked from goharbor/harbor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
immediate.go
46 lines (39 loc) · 1.2 KB
/
immediate.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
package trigger
import (
"github.com/vmware/harbor/src/replication"
)
//ImmediateTrigger will setup watcher at the image pushing action to fire
//replication event at pushing happening time.
type ImmediateTrigger struct {
params ImmediateParam
}
//NewImmediateTrigger is constructor of ImmediateTrigger
func NewImmediateTrigger(params ImmediateParam) *ImmediateTrigger {
return &ImmediateTrigger{
params: params,
}
}
//Kind is the implementation of same method defined in Trigger interface
func (st *ImmediateTrigger) Kind() string {
return replication.TriggerKindImmediate
}
//Setup is the implementation of same method defined in Trigger interface
func (st *ImmediateTrigger) Setup() error {
//TODO: Need more complicated logic here to handle partial updates
for _, namespace := range st.params.Namespaces {
wt := WatchItem{
PolicyID: st.params.PolicyID,
Namespace: namespace,
OnDeletion: st.params.OnDeletion,
OnPush: true,
}
if err := DefaultWatchList.Add(wt); err != nil {
return err
}
}
return nil
}
//Unset is the implementation of same method defined in Trigger interface
func (st *ImmediateTrigger) Unset() error {
return DefaultWatchList.Remove(st.params.PolicyID)
}