本文整理汇总了Golang中github.com/openshift/origin/pkg/cmd/server/api/latest.ReadAndResolveMasterConfig函数的典型用法代码示例。如果您正苦于以下问题:Golang ReadAndResolveMasterConfig函数的具体用法?Golang ReadAndResolveMasterConfig怎么用?Golang ReadAndResolveMasterConfig使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ReadAndResolveMasterConfig函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Check
func (d MasterConfigCheck) Check() types.DiagnosticResult {
r := types.NewDiagnosticResult(MasterConfigCheckName)
r.Debug("DH0001", fmt.Sprintf("Looking for master config file at '%s'", d.MasterConfigFile))
masterConfig, err := configapilatest.ReadAndResolveMasterConfig(d.MasterConfigFile)
if err != nil {
r.Error("DH0002", err, fmt.Sprintf("Could not read master config file '%s':\n(%T) %[2]v", d.MasterConfigFile, err))
return r
}
r.Info("DH0003", fmt.Sprintf("Found a master config file: %[1]s", d.MasterConfigFile))
results := configvalidation.ValidateMasterConfig(masterConfig, nil)
if len(results.Errors) > 0 {
errText := fmt.Sprintf("Validation of master config file '%s' failed:\n", d.MasterConfigFile)
for _, err := range results.Errors {
errText += fmt.Sprintf("%v\n", err)
}
r.Error("DH0004", nil, errText)
}
if len(results.Warnings) > 0 {
warnText := fmt.Sprintf("Validation of master config file '%s' warned:\n", d.MasterConfigFile)
for _, warn := range results.Warnings {
warnText += fmt.Sprintf("%v\n", warn)
}
r.Warn("DH0005", nil, warnText)
}
return r
}
示例2: CanRun
func (d *MasterNode) CanRun() (bool, error) {
if d.KubeClient == nil || d.OsClient == nil {
return false, errors.New("must have kube and os client")
}
if d.ServerUrl == "" {
return false, errors.New("must have a server URL")
}
// If there is a master config file available, we'll perform an additional
// check to see if an OVS network plugin is in use. If no master config,
// we assume this is the case for now and let the check run anyhow.
if len(d.MasterConfigFile) > 0 {
// Parse the master config and check the network plugin name:
masterCfg, masterErr := configapilatest.ReadAndResolveMasterConfig(d.MasterConfigFile)
if masterErr != nil {
return false, types.DiagnosticError{ID: "DClu3008",
LogMessage: fmt.Sprintf("Master config provided but unable to parse: %s", masterErr), Cause: masterErr}
}
if !sdnapi.IsOpenShiftNetworkPlugin(masterCfg.NetworkConfig.NetworkPluginName) {
return false, errors.New(fmt.Sprintf("Network plugin does not require master to also run node: %s", masterCfg.NetworkConfig.NetworkPluginName))
}
}
can, err := userCan(d.OsClient, authorizationapi.Action{
Verb: "list",
Group: kapi.GroupName,
Resource: "nodes",
})
if err != nil {
return false, types.DiagnosticError{ID: "DClu3000", LogMessage: fmt.Sprintf(clientErrorGettingNodes, err), Cause: err}
} else if !can {
return false, types.DiagnosticError{ID: "DClu3001", LogMessage: "Client does not have access to see node status", Cause: err}
}
return true, nil
}
示例3: OverwriteBootstrapPolicy
func (o OverwriteBootstrapPolicyOptions) OverwriteBootstrapPolicy() error {
masterConfig, err := configapilatest.ReadAndResolveMasterConfig(o.MasterConfigFile)
if err != nil {
return err
}
optsGetter := restoptions.NewConfigGetter(*masterConfig)
return OverwriteBootstrapPolicy(optsGetter, o.File, o.CreateBootstrapPolicyCommand, o.Force, o.Out)
}
示例4: OverwriteBootstrapPolicy
func (o OverwriteBootstrapPolicyOptions) OverwriteBootstrapPolicy() error {
masterConfig, err := configapilatest.ReadAndResolveMasterConfig(o.MasterConfigFile)
if err != nil {
return err
}
// this brings in etcd server client libraries
optsGetter := originrest.StorageOptions(*masterConfig)
return OverwriteBootstrapPolicy(optsGetter, o.File, o.CreateBootstrapPolicyCommand, o.Force, o.Out)
}
示例5: GetMasterConfig
func GetMasterConfig(r types.DiagnosticResult, masterConfigFile string) (*configapi.MasterConfig, error) {
if masterConfigLoaded { // no need to do this more than once
return masterConfig, masterConfigLoadError
}
r.Debug("DH0001", fmt.Sprintf("Looking for master config file at '%s'", masterConfigFile))
masterConfigLoaded = true
masterConfig, masterConfigLoadError = configapilatest.ReadAndResolveMasterConfig(masterConfigFile)
if masterConfigLoadError != nil {
r.Error("DH0002", masterConfigLoadError, fmt.Sprintf("Could not read master config file '%s':\n(%T) %[2]v", masterConfigFile, masterConfigLoadError))
} else {
r.Debug("DH0003", fmt.Sprintf("Found a master config file: %[1]s", masterConfigFile))
}
return masterConfig, masterConfigLoadError
}
示例6: Run
// Run runs the master config validation and returns the result of the validation as a boolean as well as any errors
// that occurred trying to validate the file
func (o *ValidateMasterConfigOptions) Run() (bool, error) {
masterConfig, err := configapilatest.ReadAndResolveMasterConfig(o.MasterConfigFile)
if err != nil {
return true, err
}
results := validation.ValidateMasterConfig(masterConfig)
writer := tabwriter.NewWriter(o.Out, minColumnWidth, tabWidth, padding, padchar, flags)
err = prettyPrintValidationResults(results, writer)
if err != nil {
return len(results.Errors) == 0, fmt.Errorf("could not print results: %v", err)
}
writer.Flush()
return len(results.Errors) == 0, nil
}
示例7: Check
func (d MasterConfigCheck) Check() types.DiagnosticResult {
r := types.NewDiagnosticResult(MasterConfigCheckName)
r.Debug("DH0001", fmt.Sprintf("Looking for master config file at '%s'", d.MasterConfigFile))
masterConfig, err := configapilatest.ReadAndResolveMasterConfig(d.MasterConfigFile)
if err != nil {
r.Error("DH0002", err, fmt.Sprintf("Could not read master config file '%s':\n(%T) %[2]v", d.MasterConfigFile, err))
return r
}
r.Info("DH0003", fmt.Sprintf("Found a master config file: %[1]s", d.MasterConfigFile))
for _, err := range configvalidation.ValidateMasterConfig(masterConfig).Errors {
r.Error("DH0004", err, fmt.Sprintf("Validation of master config file '%s' failed:\n(%T) %[2]v", d.MasterConfigFile, err))
}
return r
}
示例8: OverwriteBootstrapPolicy
func (o OverwriteBootstrapPolicyOptions) OverwriteBootstrapPolicy() error {
masterConfig, err := configapilatest.ReadAndResolveMasterConfig(o.MasterConfigFile)
if err != nil {
return err
}
// Connect and setup etcd interfaces
etcdClient, err := etcd.GetAndTestEtcdClient(masterConfig.EtcdClientInfo)
if err != nil {
return err
}
storage, err := newStorage(etcdClient, masterConfig.EtcdStorageConfig.OpenShiftStorageVersion, masterConfig.EtcdStorageConfig.OpenShiftStoragePrefix)
if err != nil {
return err
}
return OverwriteBootstrapPolicy(storage, o.File, o.CreateBootstrapPolicyCommand, o.Force, o.Out)
}
示例9: executeAllInOneCommandWithConfigs
func executeAllInOneCommandWithConfigs(args []string) (*MasterArgs, *configapi.MasterConfig, error, *NodeArgs, *configapi.NodeConfig, error) {
argsToUse := make([]string, 0, 4+len(args))
argsToUse = append(argsToUse, "start")
argsToUse = append(argsToUse, args...)
argsToUse = append(argsToUse, "--write-config="+getCleanAllInOneConfigDir())
argsToUse = append(argsToUse, "--create-certs=false")
root := &cobra.Command{
Use: "openshift",
Short: "test",
Long: "",
Run: func(c *cobra.Command, args []string) {
c.Help()
},
}
openshiftStartCommand, cfg := NewCommandStartAllInOne("openshift start", os.Stdout)
root.AddCommand(openshiftStartCommand)
root.SetArgs(argsToUse)
root.Execute()
masterCfg, masterErr := configapilatest.ReadAndResolveMasterConfig(path.Join(getAllInOneConfigDir(), "master", "master-config.yaml"))
var nodeCfg *configapi.NodeConfig
var nodeErr error
nodeConfigs, nodeErr := filepath.Glob(getNodeConfigGlob())
if nodeErr == nil {
if len(nodeConfigs) != 1 {
nodeErr = fmt.Errorf("found wrong number of node configs: %v", nodeConfigs)
} else {
nodeCfg, nodeErr = configapilatest.ReadAndResolveNodeConfig(nodeConfigs[0])
}
}
if nodeCfg == nil && nodeErr == nil {
nodeErr = errors.New("did not find node config")
}
return cfg.MasterOptions.MasterArgs, masterCfg, masterErr, cfg.NodeArgs, nodeCfg, nodeErr
}
示例10: RunEtcdServer
// RunEtcdServer takes the options and starts the etcd server
func (o *EtcdOptions) RunEtcdServer() error {
masterConfig, err := configapilatest.ReadAndResolveMasterConfig(o.ConfigFile)
if err != nil {
return err
}
validationResults := validation.ValidateMasterConfig(masterConfig, nil)
if len(validationResults.Warnings) != 0 {
for _, warning := range validationResults.Warnings {
glog.Warningf("%v", warning)
}
}
if len(validationResults.Errors) != 0 {
return kerrors.NewInvalid(configapi.Kind("MasterConfig"), o.ConfigFile, validationResults.Errors)
}
if masterConfig.EtcdConfig == nil {
return kerrors.NewInvalid(configapi.Kind("MasterConfig.EtcConfig"), o.ConfigFile, field.ErrorList{field.Required(field.NewPath("etcdConfig"), "")})
}
etcdserver.RunEtcd(masterConfig.EtcdConfig)
return nil
}
示例11: RunMaster
// RunMaster takes the options and:
// 1. Creates certs if needed
// 2. Reads fully specified master config OR builds a fully specified master config from the args
// 3. Writes the fully specified master config and exits if needed
// 4. Starts the master based on the fully specified config
func (o MasterOptions) RunMaster() error {
startUsingConfigFile := !o.IsWriteConfigOnly() && o.IsRunFromConfig()
if !startUsingConfigFile && o.CreateCertificates {
glog.V(2).Infof("Generating master configuration")
if err := o.CreateCerts(); err != nil {
return err
}
if err := o.CreateBootstrapPolicy(); err != nil {
return err
}
}
var masterConfig *configapi.MasterConfig
var err error
if startUsingConfigFile {
masterConfig, err = configapilatest.ReadAndResolveMasterConfig(o.ConfigFile)
} else {
masterConfig, err = o.MasterArgs.BuildSerializeableMasterConfig()
}
if err != nil {
return err
}
if o.IsWriteConfigOnly() {
// Resolve relative to CWD
cwd, err := os.Getwd()
if err != nil {
return err
}
if err := configapi.ResolveMasterConfigPaths(masterConfig, cwd); err != nil {
return err
}
// Relativize to config file dir
base, err := cmdutil.MakeAbs(filepath.Dir(o.MasterArgs.GetConfigFileToWrite()), cwd)
if err != nil {
return err
}
if err := configapi.RelativizeMasterConfigPaths(masterConfig, base); err != nil {
return err
}
content, err := configapilatest.WriteYAML(masterConfig)
if err != nil {
return err
}
if err := os.MkdirAll(path.Dir(o.MasterArgs.GetConfigFileToWrite()), os.FileMode(0755)); err != nil {
return err
}
if err := ioutil.WriteFile(o.MasterArgs.GetConfigFileToWrite(), content, 0644); err != nil {
return err
}
fmt.Fprintf(o.Output, "Wrote master config to: %s\n", o.MasterArgs.GetConfigFileToWrite())
return nil
}
if o.MasterArgs.OverrideConfig != nil {
if err := o.MasterArgs.OverrideConfig(masterConfig); err != nil {
return err
}
}
// Inject disabled feature flags based on distribution being used and
// regardless of configuration. They aren't written to config file to
// prevent upgrade path issues.
masterConfig.DisabledFeatures.Add(o.DisabledFeatures...)
validationResults := validation.ValidateMasterConfig(masterConfig, nil)
if len(validationResults.Warnings) != 0 {
for _, warning := range validationResults.Warnings {
glog.Warningf("%v", warning)
}
}
if len(validationResults.Errors) != 0 {
return kerrors.NewInvalid(configapi.Kind("MasterConfig"), o.ConfigFile, validationResults.Errors)
}
if !o.MasterArgs.StartControllers {
masterConfig.Controllers = configapi.ControllersDisabled
}
m := &Master{
config: masterConfig,
api: o.MasterArgs.StartAPI,
controllers: o.MasterArgs.StartControllers,
}
return m.Start()
}
示例12: RunMaster
// RunMaster takes the options and:
// 1. Creates certs if needed
// 2. Reads fully specified master config OR builds a fully specified master config from the args
// 3. Writes the fully specified master config and exits if needed
// 4. Starts the master based on the fully specified config
func (o MasterOptions) RunMaster() error {
startUsingConfigFile := !o.IsWriteConfigOnly() && o.IsRunFromConfig()
if !startUsingConfigFile && o.CreateCertificates {
glog.V(2).Infof("Generating master configuration")
if err := o.CreateCerts(); err != nil {
return err
}
if err := o.CreateBootstrapPolicy(); err != nil {
return err
}
}
var masterConfig *configapi.MasterConfig
var err error
if startUsingConfigFile {
masterConfig, err = configapilatest.ReadAndResolveMasterConfig(o.ConfigFile)
} else {
masterConfig, err = o.MasterArgs.BuildSerializeableMasterConfig()
}
if err != nil {
return err
}
if o.IsWriteConfigOnly() {
// Resolve relative to CWD
cwd, err := os.Getwd()
if err != nil {
return err
}
if err := configapi.ResolveMasterConfigPaths(masterConfig, cwd); err != nil {
return err
}
// Relativize to config file dir
base, err := cmdutil.MakeAbs(filepath.Dir(o.MasterArgs.GetConfigFileToWrite()), cwd)
if err != nil {
return err
}
if err := configapi.RelativizeMasterConfigPaths(masterConfig, base); err != nil {
return err
}
content, err := configapilatest.WriteYAML(masterConfig)
if err != nil {
return err
}
if err := os.MkdirAll(path.Dir(o.MasterArgs.GetConfigFileToWrite()), os.FileMode(0755)); err != nil {
return err
}
if err := ioutil.WriteFile(o.MasterArgs.GetConfigFileToWrite(), content, 0644); err != nil {
return err
}
fmt.Fprintf(o.Output, "Wrote master config to: %s\n", o.MasterArgs.GetConfigFileToWrite())
return nil
}
validationResults := validation.ValidateMasterConfig(masterConfig)
if len(validationResults.Warnings) != 0 {
for _, warning := range validationResults.Warnings {
glog.Warningf("%v", warning)
}
}
if len(validationResults.Errors) != 0 {
return kerrors.NewInvalid("MasterConfig", o.ConfigFile, validationResults.Errors)
}
if err := StartMaster(masterConfig); err != nil {
return err
}
return nil
}