-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into DOC-288-running-on-kind-edits
- Loading branch information
Showing
35 changed files
with
1,434 additions
and
218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package predicate | ||
|
||
import ( | ||
"sigs.k8s.io/controller-runtime/pkg/event" | ||
"sigs.k8s.io/controller-runtime/pkg/predicate" | ||
) | ||
|
||
// AnnotationPredicate implements a predicate function based on the Annotation. | ||
// | ||
// This predicate will skip the following events: | ||
// 1. Create events that do not contain the Annotation. | ||
// 2. Update events where the Annotation value has not changed. | ||
type AnnotationPredicate struct { | ||
predicate.Funcs | ||
Annotation string | ||
} | ||
|
||
// Create filters CreateEvents based on the Annotation. | ||
func (cp AnnotationPredicate) Create(e event.CreateEvent) bool { | ||
if e.Object == nil { | ||
return false | ||
} | ||
|
||
_, ok := e.Object.GetAnnotations()[cp.Annotation] | ||
return ok | ||
} | ||
|
||
// Update filters UpdateEvents based on the Annotation. | ||
func (cp AnnotationPredicate) Update(e event.UpdateEvent) bool { | ||
if e.ObjectOld == nil || e.ObjectNew == nil { | ||
// this case should not happen | ||
return false | ||
} | ||
|
||
oldAnnotationVal := e.ObjectOld.GetAnnotations()[cp.Annotation] | ||
newAnnotationVal := e.ObjectNew.GetAnnotations()[cp.Annotation] | ||
|
||
return oldAnnotationVal != newAnnotationVal | ||
} |
Oops, something went wrong.