-
Notifications
You must be signed in to change notification settings - Fork 303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add events for major lifecycle events #1137
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,9 +17,22 @@ limitations under the License. | |
package events | ||
|
||
import ( | ||
v1 "k8s.io/api/core/v1" | ||
"k8s.io/client-go/tools/record" | ||
) | ||
|
||
const ( | ||
AddNodes = "IngressGCE_AddNodes" | ||
RemoveNodes = "IngressGCE_RemoveNodes" | ||
|
||
SyncIngress = "Sync" | ||
TranslateIngress = "Translate" | ||
IPChanged = "IPChanged" | ||
GarbageCollection = "GarbageCollection" | ||
|
||
SyncService = "Sync" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is the difference between this and SyncIngress? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the value is the same, but this identifies it so we can easily change it if needed |
||
) | ||
|
||
type RecorderProducer interface { | ||
Recorder(ns string) record.EventRecorder | ||
} | ||
|
@@ -30,3 +43,39 @@ type RecorderProducerMock struct { | |
func (r RecorderProducerMock) Recorder(ns string) record.EventRecorder { | ||
return &record.FakeRecorder{} | ||
} | ||
|
||
// GloablEventf records a Cluster level event not attached to a given object. | ||
func GlobalEventf(r record.EventRecorder, eventtype, reason, messageFmt string, args ...interface{}) { | ||
// Using an empty ObjectReference to indicate no associated | ||
// resource. This apparently works, see the package | ||
// k8s.io/client-go/tools/record. | ||
r.Eventf(&v1.ObjectReference{}, eventtype, reason, messageFmt, args...) | ||
} | ||
|
||
// truncatedStringListMax is a variable to make testing easier. This | ||
// value should not be modified. | ||
var truncatedStringListMax = 2000 | ||
|
||
// TruncateStringList will render the list of items as a string, | ||
// eliding elements with elipsis at the end if there are more than a | ||
// reasonable number of characters in the resulting string. This is | ||
// used to prevent accidentally dumping enormous strings into the | ||
// Event description. | ||
func TruncatedStringList(items []string) string { | ||
var ( | ||
ret = "[" | ||
first = true | ||
) | ||
for _, s := range items { | ||
if len(ret)+len(s)+1 > truncatedStringListMax { | ||
ret += ", ..." | ||
break | ||
} | ||
if !first { | ||
ret += ", " | ||
} | ||
first = false | ||
ret += s | ||
} | ||
return ret + "]" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package events | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func TestTruncatedStringList(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. address TODO |
||
var saved int | ||
truncatedStringListMax, saved = 30, truncatedStringListMax | ||
defer func() { truncatedStringListMax = saved }() | ||
|
||
for _, tc := range []struct { | ||
desc string | ||
count int | ||
want string | ||
}{ | ||
{"zero", 0, "[]"}, | ||
{"one", 1, "[elt-0]"}, | ||
{"not truncated", 4, "[elt-0, elt-1, elt-2, elt-3]"}, | ||
{"truncated", 20, "[elt-0, elt-1, elt-2, elt-3, ...]"}, | ||
} { | ||
t.Run(tc.desc, func(t *testing.T) { | ||
var l []string | ||
for i := 0; i < tc.count; i++ { | ||
l = append(l, fmt.Sprintf("elt-%d", i)) | ||
} | ||
got := TruncatedStringList(l) | ||
if got != tc.want { | ||
t.Errorf("TruncatedString(%v) = %q; want %q", l, got, tc.want) | ||
} | ||
}) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need the IngressGCE prefix? Is it to distinguish from other Ingress controllers for the same type of action?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The event is not associated with a resource, so there is no other way to tell where this event came from.