-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pull event-object handling into a separate file.
- Loading branch information
1 parent
c99d78a
commit 88f64b9
Showing
3 changed files
with
43 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Package common provides cache.TransformFunc's for /v1 Event objects | ||
package common | ||
|
||
import ( | ||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
"k8s.io/client-go/tools/cache" | ||
) | ||
|
||
type EventFields struct { | ||
DF *DefaultFields | ||
} | ||
|
||
// GetEventTransform produces the transformation func for events | ||
func (e *EventFields) GetEventTransform() cache.TransformFunc { | ||
return e.transformEventObject | ||
} | ||
|
||
// transformEventObjects does special-case handling on event objects | ||
func (e *EventFields) transformEventObject(obj any) (any, error) { | ||
raw, isSignal, err := getUnstructured(obj) | ||
if isSignal { | ||
return obj, nil | ||
} | ||
if err != nil { | ||
return nil, err | ||
} | ||
raw = fixTypeField(raw) | ||
return e.DF.transformCommon(raw) | ||
} | ||
|
||
// updateTypeField replaces the _type field with the contents of the field named "type", if it exists | ||
func fixTypeField(raw *unstructured.Unstructured) *unstructured.Unstructured { | ||
currentTypeValue, ok := raw.Object["type"] | ||
if ok { | ||
raw.Object["_type"] = currentTypeValue | ||
} | ||
return raw | ||
} |
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