Skip to content

Commit

Permalink
Added conditional to struct cast.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daimanta committed Aug 19, 2024
1 parent 7b44edd commit d93dbc5
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion eventsources/sources/resource/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"encoding/json"
"fmt"
"os"
"reflect"
"regexp"
"strings"
"time"
Expand Down Expand Up @@ -287,7 +288,15 @@ func passFilters(event *InformerEvent, filter *v1alpha1.ResourceFilter, startTim
if filter == nil {
return true
}
uObj := event.Obj.(*unstructured.Unstructured)

var uObj *unstructured.Unstructured
if castEventObject, ok := event.Obj.(*unstructured.Unstructured); ok {
uObj = castEventObject
} else {
log.Infof("event object is not of type '*unstructured.Unstructured' but of type '%s'\n", reflect.TypeOf(event.Obj).Name())
return false
}

if len(filter.Prefix) > 0 && !strings.HasPrefix(uObj.GetName(), filter.Prefix) {
log.Infof("resource name does not match prefix. resource-name: %s, prefix: %s\n", uObj.GetName(), filter.Prefix)
return false
Expand Down

0 comments on commit d93dbc5

Please sign in to comment.