-
Notifications
You must be signed in to change notification settings - Fork 149
/
artifact_update_predicate.go
43 lines (34 loc) · 1.08 KB
/
artifact_update_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
package controller
import (
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/predicate"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
)
// ArtifactUpdatePredicate triggers an update event when a HelmRepository artifact revision changes.
// i.e.: Repo information was updated.
type ArtifactUpdatePredicate struct {
predicate.Funcs
}
func (ArtifactUpdatePredicate) Update(e event.UpdateEvent) bool {
if e.ObjectOld == nil || e.ObjectNew == nil {
return false
}
oldSource, ok := e.ObjectOld.(sourcev1.Source)
if !ok {
return false
}
newSource, ok := e.ObjectNew.(sourcev1.Source)
if !ok {
return false
}
if oldSource.GetArtifact() == nil && newSource.GetArtifact() != nil {
return true
}
// There is no way that the old artifact is newer here. We just care that they are of a different revision.
// Kubernetes takes care of setting old and new accordingly.
if oldSource.GetArtifact() != nil && newSource.GetArtifact() != nil &&
oldSource.GetArtifact().Revision != newSource.GetArtifact().Revision {
return true
}
return false
}