/
event.go
104 lines (84 loc) · 2.39 KB
/
event.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package model
import (
"time"
corev1 "k8s.io/api/core/v1"
"k8s.io/utils/pointer"
)
// An Event pertaining to a Kubernetes resource.
type Event struct {
// An opaque identifier that is unique across all types.
ID ReferenceID `json:"id"`
// The underlying Kubernetes API version of this resource.
APIVersion string `json:"apiVersion"`
// The underlying Kubernetes API kind of this resource.
Kind string `json:"kind"`
// Metadata that is common to all Kubernetes API resources.
Metadata *ObjectMeta `json:"metadata"`
// The type of event.
Type *EventType `json:"type"`
// The reason the event was emitted.
Reason *string `json:"reason"`
// Details about the event, if any.
Message *string `json:"message"`
// The source of the event - e.g. a controller.
Source *EventSource `json:"source"`
// The number of times this event has occurred.
Count *int `json:"count"`
// The time at which this event was first recorded.
FirstTime *time.Time `json:"firstTime"`
// The time at which this event was most recently recorded.
LastTime *time.Time `json:"lastTime"`
// An unstructured JSON representation of the event.
Unstructured []byte `json:"raw"`
InvolvedObjectRef corev1.ObjectReference
}
// IsNode indicates that an Event satisfies the GraphQL node interface.
func (Event) IsNode() {}
// GetEventType from the supplied Kubernetes event type.
func GetEventType(in string) *EventType {
switch in {
case "Warning":
t := EventTypeWarning
return &t
case "Normal":
t := EventTypeNormal
return &t
default:
return nil
}
}
// GetEvent from the supplied Kubernetes event.
func GetEvent(e *corev1.Event) Event {
out := Event{
ID: ReferenceID{
APIVersion: e.APIVersion,
Kind: e.Kind,
Namespace: e.GetNamespace(),
Name: e.GetName(),
},
APIVersion: e.APIVersion,
Kind: e.Kind,
Metadata: GetObjectMeta(e),
Type: GetEventType(e.Type),
Unstructured: unstruct(e),
InvolvedObjectRef: e.InvolvedObject,
}
if e.Reason != "" {
out.Reason = pointer.StringPtr(e.Reason)
}
if e.Message != "" {
out.Message = pointer.StringPtr(e.Message)
}
if e.Count != 0 {
c := int(e.Count)
out.Count = &c
}
if e.Source.Component != "" {
out.Source = &EventSource{Component: pointer.StringPtr(e.Source.Component)}
}
ft := e.FirstTimestamp.Time
out.FirstTime = &ft
lt := e.LastTimestamp.Time
out.LastTime = <
return out
}