2014-11-13 23:20:42 -05:00
|
|
|
/*
|
2015-05-01 12:19:44 -04:00
|
|
|
Copyright 2014 The Kubernetes Authors All rights reserved.
|
2014-11-13 23:20:42 -05: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 18:03:47 -04:00
|
|
|
"k8s.io/kubernetes/pkg/api"
|
2015-09-10 18:48:28 -04:00
|
|
|
"k8s.io/kubernetes/pkg/util/validation"
|
2015-11-06 18:30:52 -05:00
|
|
|
"k8s.io/kubernetes/pkg/util/validation/field"
|
2014-11-13 23:20:42 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// ValidateEvent makes sure that the event makes sense.
|
2015-11-06 18:30:52 -05:00
|
|
|
func ValidateEvent(event *api.Event) field.ErrorList {
|
|
|
|
|
allErrs := field.ErrorList{}
|
2015-11-26 02:54:42 -05:00
|
|
|
// There is no namespace required for node.
|
2015-12-09 15:41:58 -05:00
|
|
|
// However, older client code accidentally sets event.Namespace
|
|
|
|
|
// to api.NamespaceDefault, so we accept that too, but "" is preferred.
|
2015-11-26 02:54:42 -05:00
|
|
|
if event.InvolvedObject.Kind == "Node" &&
|
2015-12-09 15:41:58 -05:00
|
|
|
event.Namespace != api.NamespaceDefault &&
|
2015-11-26 02:54:42 -05:00
|
|
|
event.Namespace != "" {
|
2015-12-09 15:08:14 -05:00
|
|
|
allErrs = append(allErrs, field.Invalid(field.NewPath("involvedObject", "namespace"), event.InvolvedObject.Namespace, "not allowed for node"))
|
2015-11-26 02:54:42 -05:00
|
|
|
}
|
2015-03-26 19:30:23 -04:00
|
|
|
if event.InvolvedObject.Kind != "Node" &&
|
|
|
|
|
event.Namespace != event.InvolvedObject.Namespace {
|
2015-11-10 15:59:41 -05:00
|
|
|
allErrs = append(allErrs, field.Invalid(field.NewPath("involvedObject", "namespace"), event.InvolvedObject.Namespace, "does not match involvedObject"))
|
2014-11-13 23:20:42 -05:00
|
|
|
}
|
2015-09-10 18:48:28 -04:00
|
|
|
if !validation.IsDNS1123Subdomain(event.Namespace) {
|
2015-11-10 15:59:41 -05:00
|
|
|
allErrs = append(allErrs, field.Invalid(field.NewPath("namespace"), event.Namespace, ""))
|
2014-11-13 23:20:42 -05:00
|
|
|
}
|
|
|
|
|
return allErrs
|
|
|
|
|
}
|