本文整理汇总了Golang中github.com/openshift/origin/pkg/template/api.Template.ObjectLabels方法的典型用法代码示例。如果您正苦于以下问题:Golang Template.ObjectLabels方法的具体用法?Golang Template.ObjectLabels怎么用?Golang Template.ObjectLabels使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/openshift/origin/pkg/template/api.Template
的用法示例。
在下文中一共展示了Template.ObjectLabels方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: autoConvert_v1_Template_To_api_Template
func autoConvert_v1_Template_To_api_Template(in *Template, out *template_api.Template, s conversion.Scope) error {
if err := api.Convert_unversioned_TypeMeta_To_unversioned_TypeMeta(&in.TypeMeta, &out.TypeMeta, s); err != nil {
return err
}
if err := api_v1.Convert_v1_ObjectMeta_To_api_ObjectMeta(&in.ObjectMeta, &out.ObjectMeta, s); err != nil {
return err
}
out.Message = in.Message
if in.Objects != nil {
in, out := &in.Objects, &out.Objects
*out = make([]runtime.Object, len(*in))
for i := range *in {
if err := runtime.Convert_runtime_RawExtension_To_runtime_Object(&(*in)[i], &(*out)[i], s); err != nil {
return err
}
}
} else {
out.Objects = nil
}
if in.Parameters != nil {
in, out := &in.Parameters, &out.Parameters
*out = make([]template_api.Parameter, len(*in))
for i := range *in {
if err := Convert_v1_Parameter_To_api_Parameter(&(*in)[i], &(*out)[i], s); err != nil {
return err
}
}
} else {
out.Parameters = nil
}
out.ObjectLabels = in.ObjectLabels
return nil
}
示例2: TestEvaluateLabels
//.........这里部分代码省略.........
}
]
}`,
Output: `{
"kind":"Template","apiVersion":"v1","metadata":{"creationTimestamp":null},
"objects":[
{
"apiVersion":"v1","kind":"Service","metadata":{
"labels":{"key1":"v1","key2":"v2","key3":"v3"}}
}
],
"labels":{"key3":"v3"}
}`,
Labels: map[string]string{"key3": "v3"},
},
"when the root object has labels and metadata": {
Input: `{
"kind":"Template", "apiVersion":"v1",
"objects": [
{
"kind": "Service", "apiVersion": "v1",
"metadata": {},
"labels": {
"key1": "v1",
"key2": "v2"
}
}
]
}`,
Output: `{
"kind":"Template","apiVersion":"v1","metadata":{"creationTimestamp":null},
"objects":[
{
"apiVersion":"v1","kind":"Service",
"labels":{"key1":"v1","key2":"v2"},
"metadata":{"labels":{"key3":"v3"}}
}
],
"labels":{"key3":"v3"}
}`,
Labels: map[string]string{"key3": "v3"},
},
"overwrites label": {
Input: `{
"kind":"Template", "apiVersion":"v1",
"objects": [
{
"kind": "Service", "apiVersion": "v1",
"metadata": {"labels": {"key1": "v1", "key2": "v2"} }
}
]
}`,
Output: `{
"kind":"Template","apiVersion":"v1","metadata":{"creationTimestamp":null},
"objects":[
{
"apiVersion":"v1","kind":"Service","metadata":{
"labels":{"key1":"v1","key2":"v3"}}
}
],
"labels":{"key2":"v3"}
}`,
Labels: map[string]string{"key2": "v3"},
},
}
for k, testCase := range testCases {
var template api.Template
if err := runtime.DecodeInto(kapi.Codecs.UniversalDecoder(), []byte(testCase.Input), &template); err != nil {
t.Errorf("%s: unexpected error: %v", k, err)
continue
}
generators := map[string]generator.Generator{
"expression": generator.NewExpressionValueGenerator(rand.New(rand.NewSource(1337))),
}
processor := NewProcessor(generators)
template.ObjectLabels = testCase.Labels
// Transform the template config into the result config
errs := processor.Process(&template)
if len(errs) > 0 {
t.Errorf("%s: unexpected error: %v", k, errs)
continue
}
result, err := runtime.Encode(kapi.Codecs.LegacyCodec(v1.SchemeGroupVersion), &template)
if err != nil {
t.Errorf("%s: unexpected error: %v", k, err)
continue
}
expect := testCase.Output
expect = trailingWhitespace.ReplaceAllString(expect, "")
stringResult := strings.TrimSpace(string(result))
if expect != stringResult {
t.Errorf("%s: unexpected output: %s", k, diff.StringDiff(expect, stringResult))
continue
}
}
}