Skip to content

Commit 75612c1

Browse files
committed
Promote new Event API to v1
1 parent 1cbda24 commit 75612c1

File tree

23 files changed

+1458
-41
lines changed

23 files changed

+1458
-41
lines changed

cmd/kube-apiserver/app/aggregator.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ var apiVersionPriorities = map[schema.GroupVersion]priority{
252252
{Group: "extensions", Version: "v1beta1"}: {group: 17900, version: 1},
253253
// to my knowledge, nothing below here collides
254254
{Group: "apps", Version: "v1"}: {group: 17800, version: 15},
255+
{Group: "events.k8s.io", Version: "v1"}: {group: 17750, version: 15},
255256
{Group: "events.k8s.io", Version: "v1beta1"}: {group: 17750, version: 5},
256257
{Group: "authentication.k8s.io", Version: "v1"}: {group: 17700, version: 15},
257258
{Group: "authentication.k8s.io", Version: "v1beta1"}: {group: 17700, version: 9},

hack/.golint_failures

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pkg/apis/core/v1/helper/qos
2828
pkg/apis/core/validation
2929
pkg/apis/discovery/v1alpha1
3030
pkg/apis/discovery/v1beta1
31+
pkg/apis/events/v1
3132
pkg/apis/events/v1beta1
3233
pkg/apis/extensions/v1beta1
3334
pkg/apis/flowcontrol/v1alpha1
@@ -228,6 +229,7 @@ staging/src/k8s.io/api/certificates/v1beta1
228229
staging/src/k8s.io/api/coordination/v1
229230
staging/src/k8s.io/api/coordination/v1beta1
230231
staging/src/k8s.io/api/core/v1
232+
staging/src/k8s.io/api/events/v1
231233
staging/src/k8s.io/api/events/v1beta1
232234
staging/src/k8s.io/api/extensions/v1beta1
233235
staging/src/k8s.io/api/imagepolicy/v1alpha1

hack/.import-aliases

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"k8s.io/api/core/v1": "v1",
2020
"k8s.io/api/discovery/v1alpha1": "discoveryv1alpha1",
2121
"k8s.io/api/discovery/v1beta1": "discoveryv1beta1",
22+
"k8s.io/api/events/v1": "eventsv1",
2223
"k8s.io/api/events/v1beta1": "eventsv1beta1",
2324
"k8s.io/api/extensions/v1beta1": "extensionsv1beta1",
2425
"k8s.io/api/imagepolicy/v1alpha1": "imagepolicyv1alpha1",

hack/lib/init.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ coordination.k8s.io/v1 \
8787
discovery.k8s.io/v1alpha1 \
8888
discovery.k8s.io/v1beta1 \
8989
extensions/v1beta1 \
90+
events.k8s.io/v1 \
9091
events.k8s.io/v1beta1 \
9192
imagepolicy.k8s.io/v1alpha1 \
9293
networking.k8s.io/v1 \

pkg/apis/core/validation/events.go

Lines changed: 87 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,14 @@ package validation
1818

1919
import (
2020
"fmt"
21+
"reflect"
2122
"time"
2223

24+
"k8s.io/api/core/v1"
25+
eventsv1beta1 "k8s.io/api/events/v1beta1"
26+
apimachineryvalidation "k8s.io/apimachinery/pkg/api/validation"
2327
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
28+
"k8s.io/apimachinery/pkg/runtime/schema"
2429
"k8s.io/apimachinery/pkg/util/validation"
2530
"k8s.io/apimachinery/pkg/util/validation/field"
2631
"k8s.io/kubernetes/pkg/apis/core"
@@ -33,8 +38,88 @@ const (
3338
NoteLengthLimit = 1024
3439
)
3540

36-
// ValidateEvent makes sure that the event makes sense.
37-
func ValidateEvent(event *core.Event) field.ErrorList {
41+
func ValidateEventCreate(event *core.Event, requestVersion schema.GroupVersion) field.ErrorList {
42+
// Make sure events always pass legacy validation.
43+
allErrs := legacyValidateEvent(event)
44+
if requestVersion == v1.SchemeGroupVersion || requestVersion == eventsv1beta1.SchemeGroupVersion {
45+
// No further validation for backwards compatibility.
46+
return allErrs
47+
}
48+
49+
// Strict validation applies to creation via events.k8s.io/v1 API and newer.
50+
allErrs = append(allErrs, ValidateObjectMeta(&event.ObjectMeta, true, apimachineryvalidation.NameIsDNSSubdomain, field.NewPath("metadata"))...)
51+
allErrs = append(allErrs, validateV1EventSeries(event)...)
52+
zeroTime := time.Time{}
53+
if event.EventTime.Time == zeroTime {
54+
allErrs = append(allErrs, field.Required(field.NewPath("eventTime"), ""))
55+
}
56+
if event.Type != v1.EventTypeNormal && event.Type != v1.EventTypeWarning {
57+
allErrs = append(allErrs, field.Invalid(field.NewPath("type"), "", fmt.Sprintf("has invalid value: %v", event.Type)))
58+
}
59+
if event.FirstTimestamp.Time != zeroTime {
60+
allErrs = append(allErrs, field.Invalid(field.NewPath("firstTimestamp"), "", "needs to be unset"))
61+
}
62+
if event.LastTimestamp.Time != zeroTime {
63+
allErrs = append(allErrs, field.Invalid(field.NewPath("lastTimestamp"), "", "needs to be unset"))
64+
}
65+
if event.Count != 0 {
66+
allErrs = append(allErrs, field.Invalid(field.NewPath("count"), "", "needs to be unset"))
67+
}
68+
if event.Source.Component != "" || event.Source.Host != "" {
69+
allErrs = append(allErrs, field.Invalid(field.NewPath("source"), "", "needs to be unset"))
70+
}
71+
return allErrs
72+
}
73+
74+
func ValidateEventUpdate(newEvent, oldEvent *core.Event, requestVersion schema.GroupVersion) field.ErrorList {
75+
// Make sure the new event always passes legacy validation.
76+
allErrs := legacyValidateEvent(newEvent)
77+
if requestVersion == v1.SchemeGroupVersion || requestVersion == eventsv1beta1.SchemeGroupVersion {
78+
// No further validation for backwards compatibility.
79+
return allErrs
80+
}
81+
82+
// Strict validation applies to update via events.k8s.io/v1 API and newer.
83+
allErrs = append(allErrs, ValidateObjectMetaUpdate(&newEvent.ObjectMeta, &oldEvent.ObjectMeta, field.NewPath("metadata"))...)
84+
// if the series was modified, validate the new data
85+
if !reflect.DeepEqual(newEvent.Series, oldEvent.Series) {
86+
allErrs = append(allErrs, validateV1EventSeries(newEvent)...)
87+
}
88+
89+
allErrs = append(allErrs, ValidateImmutableField(newEvent.InvolvedObject, oldEvent.InvolvedObject, field.NewPath("involvedObject"))...)
90+
allErrs = append(allErrs, ValidateImmutableField(newEvent.Reason, oldEvent.Reason, field.NewPath("reason"))...)
91+
allErrs = append(allErrs, ValidateImmutableField(newEvent.Message, oldEvent.Message, field.NewPath("message"))...)
92+
allErrs = append(allErrs, ValidateImmutableField(newEvent.Source, oldEvent.Source, field.NewPath("source"))...)
93+
allErrs = append(allErrs, ValidateImmutableField(newEvent.FirstTimestamp, oldEvent.FirstTimestamp, field.NewPath("firstTimestamp"))...)
94+
allErrs = append(allErrs, ValidateImmutableField(newEvent.LastTimestamp, oldEvent.LastTimestamp, field.NewPath("lastTimestamp"))...)
95+
allErrs = append(allErrs, ValidateImmutableField(newEvent.Count, oldEvent.Count, field.NewPath("count"))...)
96+
allErrs = append(allErrs, ValidateImmutableField(newEvent.Reason, oldEvent.Reason, field.NewPath("reason"))...)
97+
allErrs = append(allErrs, ValidateImmutableField(newEvent.Type, oldEvent.Type, field.NewPath("type"))...)
98+
allErrs = append(allErrs, ValidateImmutableField(newEvent.EventTime, oldEvent.EventTime, field.NewPath("eventTime"))...)
99+
allErrs = append(allErrs, ValidateImmutableField(newEvent.Action, oldEvent.Action, field.NewPath("action"))...)
100+
allErrs = append(allErrs, ValidateImmutableField(newEvent.Related, oldEvent.Related, field.NewPath("related"))...)
101+
allErrs = append(allErrs, ValidateImmutableField(newEvent.ReportingController, oldEvent.ReportingController, field.NewPath("reportingController"))...)
102+
allErrs = append(allErrs, ValidateImmutableField(newEvent.ReportingInstance, oldEvent.ReportingInstance, field.NewPath("reportingInstance"))...)
103+
104+
return allErrs
105+
}
106+
107+
func validateV1EventSeries(event *core.Event) field.ErrorList {
108+
allErrs := field.ErrorList{}
109+
zeroTime := time.Time{}
110+
if event.Series != nil {
111+
if event.Series.Count < 2 {
112+
allErrs = append(allErrs, field.Invalid(field.NewPath("series.count"), "", fmt.Sprintf("should be at least 2")))
113+
}
114+
if event.Series.LastObservedTime.Time == zeroTime {
115+
allErrs = append(allErrs, field.Required(field.NewPath("series.lastObservedTime"), ""))
116+
}
117+
}
118+
return allErrs
119+
}
120+
121+
// legacyValidateEvent makes sure that the event makes sense.
122+
func legacyValidateEvent(event *core.Event) field.ErrorList {
38123
allErrs := field.ErrorList{}
39124
// Because go
40125
zeroTime := time.Time{}

0 commit comments

Comments
 (0)