本文整理汇总了Golang中k8s/io/kubernetes/pkg/util/fielderrors.ValidationErrorList.Prefix方法的典型用法代码示例。如果您正苦于以下问题:Golang ValidationErrorList.Prefix方法的具体用法?Golang ValidationErrorList.Prefix怎么用?Golang ValidationErrorList.Prefix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类k8s/io/kubernetes/pkg/util/fielderrors.ValidationErrorList
的用法示例。
在下文中一共展示了ValidationErrorList.Prefix方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Process
// Process transforms Template object into List object. It generates
// Parameter values using the defined set of generators first, and then it
// substitutes all Parameter expression occurrences with their corresponding
// values (currently in the containers' Environment variables only).
func (p *Processor) Process(template *api.Template) fielderrors.ValidationErrorList {
templateErrors := fielderrors.ValidationErrorList{}
if err := p.GenerateParameterValues(template); err != nil {
return append(templateErrors.Prefix("Template"), fielderrors.NewFieldInvalid("parameters", err, "failure to generate parameter value"))
}
for i, item := range template.Objects {
if obj, ok := item.(*runtime.Unknown); ok {
// TODO: use runtime.DecodeList when it returns ValidationErrorList
obj, err := runtime.UnstructuredJSONScheme.Decode(obj.RawJSON)
if err != nil {
util.ReportError(&templateErrors, i, *fielderrors.NewFieldInvalid("objects", err, "unable to handle object"))
continue
}
item = obj
}
newItem, err := p.SubstituteParameters(template.Parameters, item)
if err != nil {
util.ReportError(&templateErrors, i, *fielderrors.NewFieldInvalid("parameters", template.Parameters, err.Error()))
}
stripNamespace(newItem)
if err := util.AddObjectLabels(newItem, template.ObjectLabels); err != nil {
util.ReportError(&templateErrors, i, *fielderrors.NewFieldInvalid("labels", err, "label could not be applied"))
}
template.Objects[i] = newItem
}
return templateErrors
}
示例2: Process
// Process transforms Template object into List object. It generates
// Parameter values using the defined set of generators first, and then it
// substitutes all Parameter expression occurrences with their corresponding
// values (currently in the containers' Environment variables only).
func (p *Processor) Process(template *api.Template) fielderrors.ValidationErrorList {
templateErrors := fielderrors.ValidationErrorList{}
if err, badParam := p.GenerateParameterValues(template); err != nil {
return append(templateErrors.Prefix("Template"), fielderrors.NewFieldInvalid("parameters", *badParam, err.Error()))
}
for i, item := range template.Objects {
if obj, ok := item.(*runtime.Unknown); ok {
// TODO: use runtime.DecodeList when it returns ValidationErrorList
decodedObj, err := runtime.UnstructuredJSONScheme.Decode(obj.RawJSON)
if err != nil {
util.ReportError(&templateErrors, i, *fielderrors.NewFieldInvalid("objects", obj, "unable to handle object"))
continue
}
item = decodedObj
}
newItem, err := p.SubstituteParameters(template.Parameters, item)
if err != nil {
util.ReportError(&templateErrors, i, *fielderrors.NewFieldInvalid("parameters", template.Parameters, err.Error()))
}
// If an object definition's metadata includes a namespace field, the field will be stripped out of
// the definition during template instantiation. This is necessary because all objects created during
// instantiation are placed into the target namespace, so it would be invalid for the object to declare
//a different namespace.
stripNamespace(newItem)
if err := util.AddObjectLabels(newItem, template.ObjectLabels); err != nil {
util.ReportError(&templateErrors, i, *fielderrors.NewFieldInvalid("labels", err, "label could not be applied"))
}
template.Objects[i] = newItem
}
return templateErrors
}
示例3: ValidateImageStreamImport
func ValidateImageStreamImport(isi *api.ImageStreamImport) fielderrors.ValidationErrorList {
errs := fielderrors.ValidationErrorList{}
for i, spec := range isi.Spec.Images {
from := spec.From
switch from.Kind {
case "DockerImage":
if spec.To != nil && len(spec.To.Name) == 0 {
errs = append(errs, fielderrors.ValidationErrorList{fielderrors.NewFieldInvalid("to.name", spec.To.Name, "the name of the target tag must be specified")}.PrefixIndex(i)...)
}
if len(spec.From.Name) == 0 {
errs = append(errs, fielderrors.ValidationErrorList{fielderrors.NewFieldRequired("from.name")}.PrefixIndex(i)...)
} else {
if _, err := api.ParseDockerImageReference(spec.From.Name); err != nil {
errs = append(errs, fielderrors.ValidationErrorList{fielderrors.NewFieldInvalid("from.name", spec.From.Name, err.Error())}.PrefixIndex(i)...)
}
}
default:
errs = append(errs, fielderrors.ValidationErrorList{fielderrors.NewFieldInvalid("from.kind", from.Kind, "only DockerImage is supported")}.PrefixIndex(i)...)
}
}
errs = errs.Prefix("spec.images")
if spec := isi.Spec.Repository; spec != nil {
from := spec.From
switch from.Kind {
case "DockerImage":
if len(spec.From.Name) == 0 {
errs = append(errs, fielderrors.NewFieldRequired("spec.repository.from.name"))
} else {
if _, err := api.ParseDockerImageReference(spec.From.Name); err != nil {
errs = append(errs, fielderrors.NewFieldInvalid("spec.repository.from.name", spec.From.Name, err.Error()))
}
}
default:
errs = append(errs, fielderrors.NewFieldInvalid("spec.repository.from.kind", from.Kind, "only DockerImage is supported"))
}
}
if len(isi.Spec.Images) == 0 && isi.Spec.Repository == nil {
errs = append(errs, fielderrors.NewFieldInvalid("spec.images", nil, "you must specify at least one image or a repository import"))
}
errs = append(errs, validation.ValidateObjectMeta(&isi.ObjectMeta, true, ValidateImageStreamName).Prefix("metadata")...)
return errs
}