2014-11-14 04:20:42 +00:00
|
|
|
/*
|
2016-06-03 00:25:58 +00:00
|
|
|
Copyright 2014 The Kubernetes Authors.
|
2014-11-14 04:20:42 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package validation
|
|
|
|
|
|
|
|
import (
|
2015-08-05 22:03:47 +00:00
|
|
|
"k8s.io/kubernetes/pkg/api"
|
2015-09-10 22:48:28 +00:00
|
|
|
"k8s.io/kubernetes/pkg/util/validation"
|
2015-11-06 23:30:52 +00:00
|
|
|
"k8s.io/kubernetes/pkg/util/validation/field"
|
2014-11-14 04:20:42 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// ValidateEvent makes sure that the event makes sense.
|
2015-11-06 23:30:52 +00:00
|
|
|
func ValidateEvent(event *api.Event) field.ErrorList {
|
|
|
|
allErrs := field.ErrorList{}
|
2016-06-15 12:42:24 +00:00
|
|
|
// There is no namespace required for node or persistent volume.
|
2015-12-09 20:41:58 +00:00
|
|
|
// However, older client code accidentally sets event.Namespace
|
|
|
|
// to api.NamespaceDefault, so we accept that too, but "" is preferred.
|
2016-06-15 12:42:24 +00:00
|
|
|
if (event.InvolvedObject.Kind == "Node" || event.InvolvedObject.Kind == "PersistentVolume") &&
|
2015-12-09 20:41:58 +00:00
|
|
|
event.Namespace != api.NamespaceDefault &&
|
2015-11-26 07:54:42 +00:00
|
|
|
event.Namespace != "" {
|
2015-12-09 20:08:14 +00:00
|
|
|
allErrs = append(allErrs, field.Invalid(field.NewPath("involvedObject", "namespace"), event.InvolvedObject.Namespace, "not allowed for node"))
|
2015-11-26 07:54:42 +00:00
|
|
|
}
|
2015-03-26 23:30:23 +00:00
|
|
|
if event.InvolvedObject.Kind != "Node" &&
|
2016-06-15 12:42:24 +00:00
|
|
|
event.InvolvedObject.Kind != "PersistentVolume" &&
|
2015-03-26 23:30:23 +00:00
|
|
|
event.Namespace != event.InvolvedObject.Namespace {
|
2015-11-10 20:59:41 +00:00
|
|
|
allErrs = append(allErrs, field.Invalid(field.NewPath("involvedObject", "namespace"), event.InvolvedObject.Namespace, "does not match involvedObject"))
|
2014-11-14 04:20:42 +00:00
|
|
|
}
|
2015-12-17 05:58:09 +00:00
|
|
|
for _, msg := range validation.IsDNS1123Subdomain(event.Namespace) {
|
|
|
|
allErrs = append(allErrs, field.Invalid(field.NewPath("namespace"), event.Namespace, msg))
|
2014-11-14 04:20:42 +00:00
|
|
|
}
|
|
|
|
return allErrs
|
|
|
|
}
|