This repository has been archived by the owner on Mar 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 102
/
event.go
134 lines (106 loc) · 3.84 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package v1
import (
"encoding/json"
"errors"
"fmt"
"time"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
)
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type EventInstanceList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []EventInstance `json:"items"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type EventInstance struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
// Type is a short, machine-readable string that describes the kind of Event that took place.
Type string `json:"type"`
// Severity indicates the severity of the event.
// +optional
Severity EventSeverity `json:"severity,omitempty"`
// Actor is the ID of the entity that generated the Event.
// This can be the name of a particular user or controller.
Actor string `json:"actor"`
// Source identifies the object the Event is regarding.
Source EventSource `json:"source"`
// Description is a human-readable description of the Event.
// +optional
Description string `json:"description,omitempty"`
// Observed represents the time the Event was first observed.
Observed MicroTime `json:"observed" wrangler:"type=string"`
// Details provides additional information about the cluster at the time the Event occurred.
//
// It's typically used to embed the subject resource, in its entirety, at the time the Event occurred,
// but can be used to hold any data related to the event.
//
// +optional
Details GenericMap `json:"details,omitempty"`
}
// GetObserved returns the time that the Event was first observed.
func (e EventInstance) GetObserved() MicroTime {
return e.Observed
}
// MicroTime represents a time with microsecond level precision.
//
// It extends metav1.MicroTime to allow unmarshaling from RFC3339.
type MicroTime metav1.MicroTime
// DeepCopyInto returns a deep-copy of the MicroTime value. The underlying time.Time
// type is effectively immutable in the time API, so it is safe to
// copy-by-assign, despite the presence of (unexported) Pointer fields.
func (t *MicroTime) DeepCopyInto(out *MicroTime) {
*out = *t
}
// UnmarshalJSON implements the json.Unmarshaller interface.
func (t *MicroTime) UnmarshalJSON(b []byte) error {
if len(b) == 4 && string(b) == "null" {
t.Time = time.Time{}
return nil
}
var str string
if err := json.Unmarshal(b, &str); err != nil {
return err
}
pt, err := time.Parse(metav1.RFC3339Micro, str)
if err != nil {
var sErr error
if pt, sErr = time.Parse(time.RFC3339, str); sErr != nil {
return errors.Join(err, sErr)
}
}
t.Time = pt.Local()
return nil
}
const (
// EventSeverityInfo indicates an event describes a system operating "as expected".
// It is the lowest severity level.
EventSeverityInfo EventSeverity = "info"
// EventSeverityWarn indicates an event describes a recoverable error.
EventSeverityWarn EventSeverity = "warn"
// EventSeverityCritical indicates an event describes an unrecoverable error.
// It is the highest severity level.
EventSeverityCritical EventSeverity = "critical"
)
// EventSeverity indicates the severity of an event.
type EventSeverity string
// EventSource identifies an object related to an Event.
//
// The referenced object may or may not exist.
//
// Note: corev1.ObjectReference was explicitly avoided because its use in new schemas is discouraged.
// See https://github.com/kubernetes/api/blob/cdff1d4efea5d7ddc52c4085f82748c5f3e5cc8e/core/v1/types.go#L5919
// for more details.
type EventSource struct {
// Kind is the source object kind.
Kind string `json:"kind"`
// Name is the name of the source object.
Name string `json:"name"`
// UID uniquely identifies the source object.
UID types.UID `json:"uuid"`
}
func (e EventSource) String() string {
return fmt.Sprintf("%s/%s", e.Kind, e.Name)
}