-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
recording: Issue an event if a privileged pod is recorded with a log-…
…based recorder In addition to documenting that privileged pods can't be recorded with a log-based recorder, let's also issue an event.
- Loading branch information
Showing
4 changed files
with
72 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package utils | ||
|
||
import ( | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/client-go/tools/record" | ||
) | ||
|
||
type SafeRecorder struct { | ||
recorder record.EventRecorder | ||
} | ||
|
||
func NewSafeRecorder(recorder record.EventRecorder) *SafeRecorder { | ||
return &SafeRecorder{recorder: recorder} | ||
|
||
} | ||
|
||
func (sr *SafeRecorder) Event(object runtime.Object, eventtype, reason, message string) { | ||
if sr.recorder == nil { | ||
return | ||
} | ||
|
||
sr.recorder.Event(object, eventtype, reason, message) | ||
} | ||
|
||
// Eventf is just like Event, but with Sprintf for the message field. | ||
func (sr *SafeRecorder) Eventf(object runtime.Object, eventtype, reason, messageFmt string, args ...interface{}) { | ||
if sr.recorder == nil { | ||
return | ||
} | ||
|
||
sr.recorder.Eventf(object, eventtype, reason, messageFmt, args...) | ||
} | ||
|
||
// AnnotatedEventf is just like eventf, but with annotations attached | ||
func (sr *SafeRecorder) AnnotatedEventf(object runtime.Object, annotations map[string]string, eventtype, reason, messageFmt string, args ...interface{}) { | ||
if sr.recorder == nil { | ||
return | ||
} | ||
|
||
sr.recorder.AnnotatedEventf(object, annotations, eventtype, reason, messageFmt, args...) | ||
} |