diff --git a/pkg/api/errors/errors.go b/pkg/api/errors/errors.go index d0b4d53ca04..70c43b40c9b 100644 --- a/pkg/api/errors/errors.go +++ b/pkg/api/errors/errors.go @@ -90,11 +90,6 @@ func (list errorListInternal) Error() string { return strings.Join(sl, "; ") } -// Deprecated, will be removed soon. -func (list *ErrorList) Append(errs ...error) { - *list = append(*list, errs...) -} - // ToError converts an ErrorList into a "normal" error, or nil if the list is empty. func (list ErrorList) ToError() error { if len(list) == 0 { diff --git a/pkg/api/validation.go b/pkg/api/validation.go index e4d10b9a3dc..7038fa71ba2 100644 --- a/pkg/api/validation.go +++ b/pkg/api/validation.go @@ -37,14 +37,14 @@ func validateVolumes(volumes []Volume) (util.StringSet, errs.ErrorList) { el = validateSource(vol.Source) } if !util.IsDNSLabel(vol.Name) { - el.Append(errs.NewInvalid("Volume.Name", vol.Name)) + el = append(el, errs.NewInvalid("Volume.Name", vol.Name)) } else if allNames.Has(vol.Name) { - el.Append(errs.NewDuplicate("Volume.Name", vol.Name)) + el = append(el, errs.NewDuplicate("Volume.Name", vol.Name)) } if len(el) == 0 { allNames.Insert(vol.Name) } else { - allErrs.Append(el...) + allErrs = append(allErrs, el...) } } return allNames, allErrs @@ -55,14 +55,14 @@ func validateSource(source *VolumeSource) errs.ErrorList { allErrs := errs.ErrorList{} if source.HostDirectory != nil { numVolumes++ - allErrs.Append(validateHostDir(source.HostDirectory)...) + allErrs = append(allErrs, validateHostDir(source.HostDirectory)...) } if source.EmptyDirectory != nil { numVolumes++ //EmptyDirs have nothing to validate } if numVolumes != 1 { - allErrs.Append(errs.NewInvalid("Volume.Source", source)) + allErrs = append(allErrs, errs.NewInvalid("Volume.Source", source)) } return allErrs } @@ -70,7 +70,7 @@ func validateSource(source *VolumeSource) errs.ErrorList { func validateHostDir(hostDir *HostDirectory) errs.ErrorList { allErrs := errs.ErrorList{} if hostDir.Path == "" { - allErrs.Append(errs.NewNotFound("HostDir.Path", hostDir.Path)) + allErrs = append(allErrs, errs.NewNotFound("HostDir.Path", hostDir.Path)) } return allErrs } @@ -85,25 +85,25 @@ func validatePorts(ports []Port) errs.ErrorList { port := &ports[i] // so we can set default values if len(port.Name) > 0 { if len(port.Name) > 63 || !util.IsDNSLabel(port.Name) { - allErrs.Append(errs.NewInvalid("Port.Name", port.Name)) + allErrs = append(allErrs, errs.NewInvalid("Port.Name", port.Name)) } else if allNames.Has(port.Name) { - allErrs.Append(errs.NewDuplicate("Port.name", port.Name)) + allErrs = append(allErrs, errs.NewDuplicate("Port.name", port.Name)) } else { allNames.Insert(port.Name) } } if !util.IsValidPortNum(port.ContainerPort) { - allErrs.Append(errs.NewInvalid("Port.ContainerPort", port.ContainerPort)) + allErrs = append(allErrs, errs.NewInvalid("Port.ContainerPort", port.ContainerPort)) } if port.HostPort == 0 { port.HostPort = port.ContainerPort } else if !util.IsValidPortNum(port.HostPort) { - allErrs.Append(errs.NewInvalid("Port.HostPort", port.HostPort)) + allErrs = append(allErrs, errs.NewInvalid("Port.HostPort", port.HostPort)) } if len(port.Protocol) == 0 { port.Protocol = "TCP" } else if !supportedPortProtocols.Has(strings.ToUpper(port.Protocol)) { - allErrs.Append(errs.NewNotSupported("Port.Protocol", port.Protocol)) + allErrs = append(allErrs, errs.NewNotSupported("Port.Protocol", port.Protocol)) } } return allErrs @@ -115,10 +115,10 @@ func validateEnv(vars []EnvVar) errs.ErrorList { for i := range vars { ev := &vars[i] // so we can set default values if len(ev.Name) == 0 { - allErrs.Append(errs.NewInvalid("EnvVar.Name", ev.Name)) + allErrs = append(allErrs, errs.NewInvalid("EnvVar.Name", ev.Name)) } if !util.IsCIdentifier(ev.Name) { - allErrs.Append(errs.NewInvalid("EnvVar.Name", ev.Name)) + allErrs = append(allErrs, errs.NewInvalid("EnvVar.Name", ev.Name)) } } return allErrs @@ -130,14 +130,14 @@ func validateVolumeMounts(mounts []VolumeMount, volumes util.StringSet) errs.Err for i := range mounts { mnt := &mounts[i] // so we can set default values if len(mnt.Name) == 0 { - allErrs.Append(errs.NewInvalid("VolumeMount.Name", mnt.Name)) + allErrs = append(allErrs, errs.NewInvalid("VolumeMount.Name", mnt.Name)) } else if !volumes.Has(mnt.Name) { - allErrs.Append(errs.NewNotFound("VolumeMount.Name", mnt.Name)) + allErrs = append(allErrs, errs.NewNotFound("VolumeMount.Name", mnt.Name)) } if len(mnt.MountPath) == 0 { // Backwards compat. if len(mnt.Path) == 0 { - allErrs.Append(errs.NewInvalid("VolumeMount.MountPath", mnt.MountPath)) + allErrs = append(allErrs, errs.NewInvalid("VolumeMount.MountPath", mnt.MountPath)) } else { glog.Warning("DEPRECATED: VolumeMount.Path has been replaced by VolumeMount.MountPath") mnt.MountPath = mnt.Path @@ -161,7 +161,7 @@ func AccumulateUniquePorts(containers []Container, accumulator map[int]bool, ext for pi := range ctr.Ports { port := extract(&ctr.Ports[pi]) if accumulator[port] { - allErrs.Append(errs.NewDuplicate("Port", port)) + allErrs = append(allErrs, errs.NewDuplicate("Port", port)) } else { accumulator[port] = true } @@ -183,25 +183,25 @@ func validateContainers(containers []Container, volumes util.StringSet) errs.Err for i := range containers { ctr := &containers[i] // so we can set default values if !util.IsDNSLabel(ctr.Name) { - allErrs.Append(errs.NewInvalid("Container.Name", ctr.Name)) + allErrs = append(allErrs, errs.NewInvalid("Container.Name", ctr.Name)) } else if allNames.Has(ctr.Name) { - allErrs.Append(errs.NewDuplicate("Container.Name", ctr.Name)) + allErrs = append(allErrs, errs.NewDuplicate("Container.Name", ctr.Name)) } else { allNames.Insert(ctr.Name) } if len(ctr.Image) == 0 { - allErrs.Append(errs.NewInvalid("Container.Image", ctr.Name)) + allErrs = append(allErrs, errs.NewInvalid("Container.Image", ctr.Name)) } - allErrs.Append(validatePorts(ctr.Ports)...) - allErrs.Append(validateEnv(ctr.Env)...) - allErrs.Append(validateVolumeMounts(ctr.VolumeMounts, volumes)...) + allErrs = append(allErrs, validatePorts(ctr.Ports)...) + allErrs = append(allErrs, validateEnv(ctr.Env)...) + allErrs = append(allErrs, validateVolumeMounts(ctr.VolumeMounts, volumes)...) } // Check for colliding ports across all containers. // TODO(thockin): This really is dependent on the network config of the host (IP per pod?) // and the config of the new manifest. But we have not specced that out yet, so we'll just // make some assumptions for now. As of now, pods share a network namespace, which means that // every Port.HostPort across the whole pod must be unique. - allErrs.Append(checkHostPortConflicts(containers)...) + allErrs = append(allErrs, checkHostPortConflicts(containers)...) return allErrs } @@ -216,15 +216,15 @@ func ValidateManifest(manifest *ContainerManifest) []error { allErrs := errs.ErrorList{} if len(manifest.Version) == 0 { - allErrs.Append(errs.NewInvalid("ContainerManifest.Version", manifest.Version)) + allErrs = append(allErrs, errs.NewInvalid("ContainerManifest.Version", manifest.Version)) } else if !supportedManifestVersions.Has(strings.ToLower(manifest.Version)) { - allErrs.Append(errs.NewNotSupported("ContainerManifest.Version", manifest.Version)) + allErrs = append(allErrs, errs.NewNotSupported("ContainerManifest.Version", manifest.Version)) } allVolumes, errs := validateVolumes(manifest.Volumes) if len(errs) != 0 { - allErrs.Append(errs...) + allErrs = append(allErrs, errs...) } - allErrs.Append(validateContainers(manifest.Containers, allVolumes)...) + allErrs = append(allErrs, validateContainers(manifest.Containers, allVolumes)...) return []error(allErrs) } @@ -235,7 +235,7 @@ func ValidatePodState(podState *PodState) []error { } else if podState.RestartPolicy.Type != RestartAlways && podState.RestartPolicy.Type != RestartOnFailure && podState.RestartPolicy.Type != RestartNever { - allErrs.Append(errs.NewNotSupported("PodState.RestartPolicy.Type", podState.RestartPolicy.Type)) + allErrs = append(allErrs, errs.NewNotSupported("PodState.RestartPolicy.Type", podState.RestartPolicy.Type)) } return []error(allErrs) @@ -245,9 +245,9 @@ func ValidatePodState(podState *PodState) []error { func ValidatePod(pod *Pod) []error { allErrs := errs.ErrorList{} if pod.ID == "" { - allErrs.Append(errs.NewInvalid("Pod.ID", pod.ID)) + allErrs = append(allErrs, errs.NewInvalid("Pod.ID", pod.ID)) } - allErrs.Append(ValidatePodState(&pod.DesiredState)...) + allErrs = append(allErrs, ValidatePodState(&pod.DesiredState)...) return []error(allErrs) } @@ -255,12 +255,12 @@ func ValidatePod(pod *Pod) []error { func ValidateService(service *Service) []error { allErrs := errs.ErrorList{} if service.ID == "" { - allErrs.Append(errs.NewInvalid("Service.ID", service.ID)) + allErrs = append(allErrs, errs.NewInvalid("Service.ID", service.ID)) } else if !util.IsDNS952Label(service.ID) { - allErrs.Append(errs.NewInvalid("Service.ID", service.ID)) + allErrs = append(allErrs, errs.NewInvalid("Service.ID", service.ID)) } if labels.Set(service.Selector).AsSelector().Empty() { - allErrs.Append(errs.NewInvalid("Service.Selector", service.Selector)) + allErrs = append(allErrs, errs.NewInvalid("Service.Selector", service.Selector)) } return []error(allErrs) }