本文整理匯總了Golang中github.com/openshift/origin/pkg/util.AddObjectLabels函數的典型用法代碼示例。如果您正苦於以下問題:Golang AddObjectLabels函數的具體用法?Golang AddObjectLabels怎麽用?Golang AddObjectLabels使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了AddObjectLabels函數的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: setLabels
func setLabels(labels map[string]string, result *newcmd.AppResult) error {
for _, object := range result.List.Items {
err := util.AddObjectLabels(object, labels)
if err != nil {
return err
}
}
return nil
}
示例4: setLabels
func setLabels(labels map[string]string, result *newcmd.AppResult) error {
if len(labels) == 0 {
if len(result.Name) > 0 {
labels = map[string]string{"app": result.Name}
}
}
for _, object := range result.List.Items {
err := util.AddObjectLabels(object, labels)
if err != nil {
return err
}
}
return nil
}
示例5: 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) field.ErrorList {
templateErrors := field.ErrorList{}
if fieldError := p.GenerateParameterValues(template); fieldError != nil {
return append(templateErrors, fieldError)
}
// Place parameters into a map for efficient lookup
paramMap := make(map[string]api.Parameter)
for _, param := range template.Parameters {
paramMap[param.Name] = param
}
// Perform parameter substitution on the template's user message. This can be used to
// instruct a user on next steps for the template.
template.Message = p.EvaluateParameterSubstitution(paramMap, template.Message)
itemPath := field.NewPath("item")
for i, item := range template.Objects {
idxPath := itemPath.Index(i)
if obj, ok := item.(*runtime.Unknown); ok {
// TODO: use runtime.DecodeList when it returns ValidationErrorList
decodedObj, err := runtime.Decode(runtime.UnstructuredJSONScheme, obj.Raw)
if err != nil {
templateErrors = append(templateErrors, field.Invalid(idxPath.Child("objects"), obj, fmt.Sprintf("unable to handle object: %v", err)))
continue
}
item = decodedObj
}
newItem, err := p.SubstituteParameters(paramMap, item)
if err != nil {
templateErrors = append(templateErrors, field.Invalid(idxPath.Child("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 {
templateErrors = append(templateErrors, field.Invalid(idxPath.Child("labels"),
template.ObjectLabels, fmt.Sprintf("label could not be applied: %v", err)))
}
template.Objects[i] = newItem
}
return templateErrors
}
示例6: setLabels
func setLabels(c *cobra.Command, result *newcmd.AppResult) error {
label := cmdutil.GetFlagString(c, "labels")
if len(label) != 0 {
lbl, err := ctl.ParseLabels(label)
if err != nil {
return err
}
for _, object := range result.List.Items {
err = util.AddObjectLabels(object, lbl)
if err != nil {
return err
}
}
}
return nil
}