kubernetes/events: remove noise from logging
Removes logging of unnecessary k8s events that are
not monitored. This was only required during the
initial development phase to debug all events.
package kubernetes
import (
- "os"
"reflect"
"k8s.io/client-go/tools/cache"
a "github.com/openservicemesh/osm/pkg/announcements"
- "github.com/openservicemesh/osm/pkg/constants"
"github.com/openservicemesh/osm/pkg/kubernetes/events"
"github.com/openservicemesh/osm/pkg/metricsstore"
)
-var emitLogs = os.Getenv(constants.EnvVarLogKubernetesEvents) == "true"
-
// observeFilter returns true for YES observe and false for NO do not pay attention to this
// This filter could be added optionally by anything using GetKubernetesEventHandlers()
type observeFilter func(obj interface{}) bool
@@ -34,7 +30,6 @@ func GetKubernetesEventHandlers(informerName, providerName string, shouldObserve
return cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
if !shouldObserve(obj) {
- logNotObservedNamespace(obj, eventTypes.Add, informerName, providerName)
return
}
events.GetPubSubInstance().Publish(events.PubSubMessage{
@@ -49,7 +44,6 @@ func GetKubernetesEventHandlers(informerName, providerName string, shouldObserve
UpdateFunc: func(oldObj, newObj interface{}) {
if !shouldObserve(newObj) {
- logNotObservedNamespace(newObj, eventTypes.Update, informerName, providerName)
return
}
events.GetPubSubInstance().Publish(events.PubSubMessage{
@@ -63,7 +57,6 @@ func GetKubernetesEventHandlers(informerName, providerName string, shouldObserve
DeleteFunc: func(obj interface{}) {
if !shouldObserve(obj) {
- logNotObservedNamespace(obj, eventTypes.Delete, informerName, providerName)
return
}
events.GetPubSubInstance().Publish(events.PubSubMessage{
@@ -81,9 +74,3 @@ func GetKubernetesEventHandlers(informerName, providerName string, shouldObserve
func getNamespace(obj interface{}) string {
return reflect.ValueOf(obj).Elem().FieldByName("ObjectMeta").FieldByName("Namespace").String()
}
-
-func logNotObservedNamespace(obj interface{}, eventType a.AnnouncementType, informerName, providerName string) {
- if emitLogs {
- log.Debug().Msgf("Namespace %q is not observed by OSM; ignoring %s event; informer=%s; provider=%s", getNamespace(obj), eventType, informerName, providerName)
- }
-}
