// BeforeCreate ensures that common operations for all resources are performed on creation. It only returns // errors that can be converted to api.Status. It invokes PrepareForCreate, then GenerateName, then Validate. // It returns nil if the object should be created. func BeforeCreate(strategy RESTCreateStrategy, ctx api.Context, obj runtime.Object) error { objectMeta, kind, kerr := objectMetaAndKind(strategy, obj) if kerr != nil { return kerr } if strategy.NamespaceScoped() { if !api.ValidNamespace(ctx, objectMeta) { return errors.NewBadRequest("the namespace of the provided object does not match the namespace sent on the request") } } else { objectMeta.Namespace = api.NamespaceNone } objectMeta.DeletionTimestamp = nil objectMeta.DeletionGracePeriodSeconds = nil strategy.PrepareForCreate(obj) api.FillObjectMetaSystemFields(ctx, objectMeta) api.GenerateName(strategy, objectMeta) if errs := strategy.Validate(ctx, obj); len(errs) > 0 { return errors.NewInvalid(kind, objectMeta.Name, errs) } // Custom validation (including name validation) passed // Now run common validation on object meta // Do this *after* custom validation so that specific error messages are shown whenever possible if errs := validation.ValidateObjectMeta(objectMeta, strategy.NamespaceScoped(), validation.ValidatePathSegmentName); len(errs) > 0 { return errors.NewInvalid(kind, objectMeta.Name, errs) } strategy.Canonicalize(obj) return nil }
func ValidateJob(job *extensions.Job) validation.ErrorList { allErrs := validation.ErrorList{} // Jobs and rcs have the same name validation allErrs = append(allErrs, apivalidation.ValidateObjectMeta(&job.ObjectMeta, true, apivalidation.ValidateReplicationControllerName).Prefix("metadata")...) allErrs = append(allErrs, ValidateJobSpec(&job.Spec).Prefix("spec")...) return allErrs }
func ValidateScale(scale *extensions.Scale) validation.ErrorList { allErrs := validation.ErrorList{} allErrs = append(allErrs, apivalidation.ValidateObjectMeta(&scale.ObjectMeta, true, apivalidation.NameIsDNSSubdomain).Prefix("metadata")...) if scale.Spec.Replicas < 0 { allErrs = append(allErrs, validation.NewInvalidError("spec.replicas", scale.Spec.Replicas, "must be non-negative")) } return allErrs }
func ValidateThirdPartyResource(obj *extensions.ThirdPartyResource) validation.ErrorList { allErrs := validation.ErrorList{} allErrs = append(allErrs, apivalidation.ValidateObjectMeta(&obj.ObjectMeta, true, ValidateThirdPartyResourceName).Prefix("metadata")...) versions := sets.String{} for ix := range obj.Versions { version := &obj.Versions[ix] if len(version.Name) == 0 { allErrs = append(allErrs, validation.NewInvalidError("name", version, "name can not be empty")) } if versions.Has(version.Name) { allErrs = append(allErrs, validation.NewDuplicateError("version", version)) } versions.Insert(version.Name) } return allErrs }
func ValidateHorizontalPodAutoscaler(autoscaler *extensions.HorizontalPodAutoscaler) validation.ErrorList { allErrs := validation.ErrorList{} allErrs = append(allErrs, apivalidation.ValidateObjectMeta(&autoscaler.ObjectMeta, true, ValidateHorizontalPodAutoscalerName).Prefix("metadata")...) allErrs = append(allErrs, validateHorizontalPodAutoscalerSpec(autoscaler.Spec)...) return allErrs }
// ValidateIngress tests if required fields in the Ingress are set. func ValidateIngress(ingress *extensions.Ingress) validation.ErrorList { allErrs := validation.ErrorList{} allErrs = append(allErrs, apivalidation.ValidateObjectMeta(&ingress.ObjectMeta, true, ValidateIngressName).Prefix("metadata")...) allErrs = append(allErrs, ValidateIngressSpec(&ingress.Spec).Prefix("spec")...) return allErrs }
func ValidateDeployment(obj *extensions.Deployment) validation.ErrorList { allErrs := validation.ErrorList{} allErrs = append(allErrs, apivalidation.ValidateObjectMeta(&obj.ObjectMeta, true, ValidateDeploymentName).Prefix("metadata")...) allErrs = append(allErrs, ValidateDeploymentSpec(&obj.Spec).Prefix("spec")...) return allErrs }
// ValidateDaemonSet tests if required fields in the DaemonSet are set. func ValidateDaemonSet(controller *extensions.DaemonSet) validation.ErrorList { allErrs := validation.ErrorList{} allErrs = append(allErrs, apivalidation.ValidateObjectMeta(&controller.ObjectMeta, true, ValidateDaemonSetName).Prefix("metadata")...) allErrs = append(allErrs, ValidateDaemonSetSpec(&controller.Spec).Prefix("spec")...) return allErrs }