-
Notifications
You must be signed in to change notification settings - Fork 114
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 config daemon #519
Merged
+91
−4
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,52 @@ | ||
package daemon | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/golang/glog" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/kubernetes" | ||
"k8s.io/client-go/kubernetes/scheme" | ||
typedv1core "k8s.io/client-go/kubernetes/typed/core/v1" | ||
"k8s.io/client-go/tools/record" | ||
|
||
snclientset "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/client/clientset/versioned" | ||
) | ||
|
||
type EventRecorder struct { | ||
client snclientset.Interface | ||
node string | ||
eventRecorder record.EventRecorder | ||
eventBroadcaster record.EventBroadcaster | ||
} | ||
|
||
// NewEventRecorder Create a new EventRecorder | ||
func NewEventRecorder(c snclientset.Interface, n string, kubeclient kubernetes.Interface) *EventRecorder { | ||
eventBroadcaster := record.NewBroadcaster() | ||
eventBroadcaster.StartStructuredLogging(4) | ||
eventBroadcaster.StartRecordingToSink(&typedv1core.EventSinkImpl{Interface: kubeclient.CoreV1().Events("")}) | ||
eventRecorder := eventBroadcaster.NewRecorder(scheme.Scheme, corev1.EventSource{Component: "config-daemon"}) | ||
return &EventRecorder{ | ||
client: c, | ||
node: n, | ||
eventRecorder: eventRecorder, | ||
eventBroadcaster: eventBroadcaster, | ||
} | ||
} | ||
|
||
// SendEvent Send an Event on the NodeState object | ||
func (e *EventRecorder) SendEvent(eventType string, msg string) { | ||
nodeState, err := e.client.SriovnetworkV1().SriovNetworkNodeStates(namespace).Get(context.Background(), e.node, metav1.GetOptions{}) | ||
if err != nil { | ||
glog.Warningf("SendEvent(): Failed to fetch node state %s (%v); skip SendEvent", e.node, err) | ||
return | ||
} | ||
e.eventRecorder.Event(nodeState, corev1.EventTypeNormal, eventType, msg) | ||
} | ||
|
||
// Shutdown Close the EventBroadcaster | ||
func (e *EventRecorder) Shutdown() { | ||
e.eventBroadcaster.Shutdown() | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can we use operator namespace for the Events? I think that way we can get a list of all events happened in the cluster via
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 events are on sriovnetworknodestate which is a namespaced object. so they will be available.
Note that the events will disappear after 1 hour. (kubernetes/kubernetes#52521)
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.
Oh, that's exactly what I was referring to. Thanks for explaining.
About the deletion of the events, it looks like it can be tuned via a kubeapi-server argument:
IMO it's OK that is on the cluster administrator's side