/
kube_event_to_koki.go
69 lines (61 loc) · 1.9 KB
/
kube_event_to_koki.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package converters
import (
"k8s.io/api/core/v1"
"github.com/koki/short/types"
serrors "github.com/koki/structurederrors"
)
func Convert_Kube_Event_to_Koki(kube *v1.Event) (*types.EventWrapper, error) {
var err error
koki := &types.Event{}
koki.Name = kube.Name
koki.Namespace = kube.Namespace
koki.Version = kube.APIVersion
koki.Cluster = kube.ClusterName
koki.Labels = kube.Labels
koki.Annotations = kube.Annotations
involvedObject, err := convertTarget(&kube.InvolvedObject)
if err != nil {
return nil, serrors.ContextualizeErrorf(err, "event involved object")
}
koki.InvolvedObject = *involvedObject
koki.Reason = kube.Reason
koki.Message = kube.Message
koki.Host = kube.Source.Host
koki.Component = kube.Source.Component
koki.FirstTimestamp = kube.FirstTimestamp
koki.LastTimestamp = kube.LastTimestamp
koki.Count = kube.Count
koki.Type = kube.Type
koki.EventTime = kube.EventTime
if kube.Series != nil {
koki.SeriesCount = &kube.Series.Count
koki.LastObservedTime = &kube.Series.LastObservedTime
state, err := convertEventSeriesState(kube.Series.State)
if err != nil {
return nil, serrors.ContextualizeErrorf(err, "event series state")
}
koki.SeriesState = &state
}
koki.Action = kube.Action
koki.Related, err = convertTarget(kube.Related)
if err != nil {
return nil, serrors.ContextualizeErrorf(err, "event related obj")
}
koki.ReportingController = kube.ReportingController
koki.ReportingInstance = kube.ReportingInstance
return &types.EventWrapper{
Event: *koki,
}, nil
}
func convertEventSeriesState(kube v1.EventSeriesState) (types.EventSeriesState, error) {
switch kube {
case v1.EventSeriesStateOngoing:
return types.EventSeriesStateOngoing, nil
case v1.EventSeriesStateFinished:
return types.EventSeriesStateFinished, nil
case v1.EventSeriesStateUnknown:
return types.EventSeriesStateUnknown, nil
default:
return "", serrors.InvalidInstanceError(kube)
}
}