This repository has been archived by the owner on Jan 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
predicate.go
88 lines (71 loc) · 1.67 KB
/
predicate.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package migration
import (
libref "github.com/konveyor/controller/pkg/ref"
api "github.com/konveyor/forklift-controller/pkg/apis/forklift/v1beta1"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/predicate"
)
type MigrationPredicate struct {
predicate.Funcs
}
func (r MigrationPredicate) Create(e event.CreateEvent) bool {
_, cast := e.Object.(*api.Migration)
if cast {
libref.Mapper.Create(e)
return true
}
return false
}
func (r MigrationPredicate) Update(e event.UpdateEvent) bool {
object, cast := e.ObjectNew.(*api.Migration)
if !cast {
return false
}
changed := object.Status.ObservedGeneration < object.Generation
if changed {
libref.Mapper.Update(e)
}
return changed
}
func (r MigrationPredicate) Delete(e event.DeleteEvent) bool {
_, cast := e.Object.(*api.Migration)
if cast {
libref.Mapper.Delete(e)
return true
}
return false
}
type PlanPredicate struct {
predicate.Funcs
}
func (r PlanPredicate) Create(e event.CreateEvent) bool {
p, cast := e.Object.(*api.Plan)
if cast {
reconciled := p.Status.ObservedGeneration == p.Generation
return reconciled
}
return false
}
func (r PlanPredicate) Update(e event.UpdateEvent) bool {
p, cast := e.ObjectNew.(*api.Plan)
if cast {
reconciled := p.Status.ObservedGeneration == p.Generation
return reconciled
}
return false
}
func (r PlanPredicate) Delete(e event.DeleteEvent) bool {
_, cast := e.Object.(*api.Plan)
if cast {
return true
}
return false
}
func (r PlanPredicate) Generic(e event.GenericEvent) bool {
p, cast := e.Object.(*api.Plan)
if cast {
reconciled := p.Status.ObservedGeneration == p.Generation
return reconciled
}
return false
}