本文整理匯總了Golang中github.com/openshift/origin/pkg/cmd/util/clientcmd.Factory.UpdateObjectEnvironment方法的典型用法代碼示例。如果您正苦於以下問題:Golang Factory.UpdateObjectEnvironment方法的具體用法?Golang Factory.UpdateObjectEnvironment怎麽用?Golang Factory.UpdateObjectEnvironment使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/openshift/origin/pkg/cmd/util/clientcmd.Factory
的用法示例。
在下文中一共展示了Factory.UpdateObjectEnvironment方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: RunEnv
//.........這裏部分代碼省略.........
for _, info := range infos {
ok, err := f.UpdatePodSpecForObject(info.Object, func(spec *kapi.PodSpec) error {
containers, _ := selectContainers(spec.Containers, containerMatch)
if len(containers) == 0 {
fmt.Fprintf(cmd.Out(), "warning: %s/%s does not have any containers matching %q\n", info.Mapping.Resource, info.Name, containerMatch)
return nil
}
for _, c := range containers {
if !overwrite {
if err := validateNoOverwrites(c.Env, env); err != nil {
errored = append(errored, info)
return err
}
}
c.Env = updateEnv(c.Env, env, remove)
if list {
fmt.Fprintf(out, "# %s %s, container %s\n", info.Mapping.Resource, info.Name, c.Name)
for _, env := range c.Env {
// if env.ValueFrom != nil && env.ValueFrom.FieldRef != nil {
// fmt.Fprintf(cmd.Out(), "%s= # calculated from pod %s %s\n", env.Name, env.ValueFrom.FieldRef.FieldPath, env.ValueFrom.FieldRef.APIVersion)
// continue
// }
fmt.Fprintf(out, "%s=%s\n", env.Name, env.Value)
}
}
}
return nil
})
if !ok {
// This is a fallback function for objects that don't have pod spec.
ok, err = f.UpdateObjectEnvironment(info.Object, func(vars *[]kapi.EnvVar) error {
if vars == nil {
return fmt.Errorf("no environment variables provided")
}
if !overwrite {
if err := validateNoOverwrites(*vars, env); err != nil {
errored = append(errored, info)
return err
}
}
*vars = updateEnv(*vars, env, remove)
if list {
fmt.Fprintf(out, "# %s %s\n", info.Mapping.Resource, info.Name)
for _, env := range *vars {
fmt.Fprintf(out, "%s=%s\n", env.Name, env.Value)
}
}
return nil
})
if !ok {
skipped++
continue
}
}
if err != nil {
fmt.Fprintf(cmd.Out(), "error: %s/%s %v\n", info.Mapping.Resource, info.Name, err)
continue
}
}
if one && skipped == len(infos) {
return fmt.Errorf("%s/%s is not a pod or does not have a pod template", infos[0].Mapping.Resource, infos[0].Name)
}
if len(errored) == len(infos) {