-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add custom event aggregator function with annotations (#9247)
* feat: Add custom event aggregator function with annotations Signed-off-by: Yuan Tang <terrytangyuan@gmail.com> * chore: test env var Signed-off-by: Yuan Tang <terrytangyuan@gmail.com> * chore: sort the vals Signed-off-by: Yuan Tang <terrytangyuan@gmail.com> * Update event_recorder_manager.go
- Loading branch information
1 parent
1899a7b
commit fd6c7a7
Showing
5 changed files
with
90 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package events | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
apiv1 "k8s.io/api/core/v1" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
const aggregationWithAnnotationsEnvKey = "EVENT_AGGREGATION_WITH_ANNOTATIONS" | ||
|
||
func TestCustomEventAggregatorFuncWithAnnotations(t *testing.T) { | ||
event := apiv1.Event{} | ||
key, msg := customEventAggregatorFuncWithAnnotations(&event) | ||
assert.Equal(t, "", key) | ||
assert.Equal(t, "", msg) | ||
|
||
event.Source = apiv1.EventSource{Component: "component1", Host: "host1"} | ||
event.InvolvedObject.Name = "name1" | ||
event.Message = "message1" | ||
|
||
key, msg = customEventAggregatorFuncWithAnnotations(&event) | ||
assert.Equal(t, "component1host1name1", key) | ||
assert.Equal(t, "message1", msg) | ||
|
||
// Test default behavior where annotations are not used for aggregation | ||
event.ObjectMeta.Annotations = map[string]string{"key1": "val1", "key2": "val2"} | ||
key, msg = customEventAggregatorFuncWithAnnotations(&event) | ||
assert.Equal(t, "component1host1name1", key) | ||
assert.Equal(t, "message1", msg) | ||
|
||
_ = os.Setenv(aggregationWithAnnotationsEnvKey, "true") | ||
key, msg = customEventAggregatorFuncWithAnnotations(&event) | ||
assert.Equal(t, "component1host1name1val1val2", key) | ||
assert.Equal(t, "message1", msg) | ||
|
||
// Test annotations with values in different order | ||
_ = os.Setenv(aggregationWithAnnotationsEnvKey, "true") | ||
event.ObjectMeta.Annotations = map[string]string{"key2": "val2", "key1": "val1"} | ||
key, msg = customEventAggregatorFuncWithAnnotations(&event) | ||
assert.Equal(t, "component1host1name1val1val2", key) | ||
assert.Equal(t, "message1", msg) | ||
|
||
_ = os.Unsetenv(aggregationWithAnnotationsEnvKey) | ||
} |