本文整理汇总了Golang中github.com/openshift/origin/pkg/cmd/cli/config.RelativizeClientConfigPaths函数的典型用法代码示例。如果您正苦于以下问题:Golang RelativizeClientConfigPaths函数的具体用法?Golang RelativizeClientConfigPaths怎么用?Golang RelativizeClientConfigPaths使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RelativizeClientConfigPaths函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: SaveConfig
// Save all the information present in this helper to a config file. An explicit config
// file path can be provided, if not use the established conventions about config
// loading rules. Will create a new config file if one can't be found at all. Will only
// succeed if all required info is present.
func (o *LoginOptions) SaveConfig() (bool, error) {
if len(o.Username) == 0 {
return false, fmt.Errorf("Insufficient data to merge configuration.")
}
globalExistedBefore := true
if _, err := os.Stat(o.PathOptions.GlobalFile); os.IsNotExist(err) {
globalExistedBefore = false
}
newConfig, err := config.CreateConfig(o.Project, o.Config)
if err != nil {
return false, err
}
cwd, err := os.Getwd()
if err != nil {
return false, err
}
baseDir, err := cmdutil.MakeAbs(filepath.Dir(o.PathOptions.GetDefaultFilename()), cwd)
if err != nil {
return false, err
}
if err := config.RelativizeClientConfigPaths(newConfig, baseDir); err != nil {
return false, err
}
configToWrite, err := config.MergeConfig(*o.StartingKubeConfig, *newConfig)
if err != nil {
return false, err
}
if err := kclientcmd.ModifyConfig(o.PathOptions, *configToWrite, true); err != nil {
if !os.IsPermission(err) {
return false, err
}
out := &bytes.Buffer{}
cmderr.PrintError(errors.ErrKubeConfigNotWriteable(o.PathOptions.GetDefaultFilename(), o.PathOptions.IsExplicitFile(), err), out)
return false, fmt.Errorf("%v", out)
}
created := false
if _, err := os.Stat(o.PathOptions.GlobalFile); err == nil {
created = created || !globalExistedBefore
}
return created, nil
}
示例2: SaveConfig
// Save all the information present in this helper to a config file. An explicit config
// file path can be provided, if not use the established conventions about config
// loading rules. Will create a new config file if one can't be found at all. Will only
// succeed if all required info is present.
func (o *LoginOptions) SaveConfig() (bool, error) {
if len(o.Username) == 0 {
return false, fmt.Errorf("Insufficient data to merge configuration.")
}
globalExistedBefore := true
if _, err := os.Stat(o.PathOptions.GlobalFile); os.IsNotExist(err) {
globalExistedBefore = false
}
newConfig, err := config.CreateConfig(o.Project, o.Config)
if err != nil {
return false, err
}
cwd, err := os.Getwd()
if err != nil {
return false, err
}
baseDir, err := cmdutil.MakeAbs(filepath.Dir(o.PathOptions.GetDefaultFilename()), cwd)
if err != nil {
return false, err
}
if err := config.RelativizeClientConfigPaths(newConfig, baseDir); err != nil {
return false, err
}
configToWrite, err := config.MergeConfig(*o.StartingKubeConfig, *newConfig)
if err != nil {
return false, err
}
if err := kubecmdconfig.ModifyConfig(o.PathOptions, *configToWrite); err != nil {
return false, err
}
created := false
if _, err := os.Stat(o.PathOptions.GlobalFile); err == nil {
created = created || !globalExistedBefore
}
return created, nil
}