本文整理汇总了Golang中github.com/openshift/origin/pkg/cmd/server/api/latest.WriteYAML函数的典型用法代码示例。如果您正苦于以下问题:Golang WriteYAML函数的具体用法?Golang WriteYAML怎么用?Golang WriteYAML使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了WriteYAML函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: updateConfig
func (h *Helper) updateConfig(configDir, hostDir, serverIP, metricsHost string) error {
masterConfig := filepath.Join(configDir, "master", "master-config.yaml")
glog.V(1).Infof("Reading master config from %s", masterConfig)
cfg, err := configapilatest.ReadMasterConfig(masterConfig)
if err != nil {
glog.V(1).Infof("Could not read master config: %v", err)
return err
}
if len(h.routingSuffix) > 0 {
cfg.RoutingConfig.Subdomain = h.routingSuffix
} else {
cfg.RoutingConfig.Subdomain = fmt.Sprintf("%s.xip.io", serverIP)
}
if len(metricsHost) > 0 && cfg.AssetConfig != nil {
cfg.AssetConfig.MetricsPublicURL = fmt.Sprintf("https://%s/hawkular/metrics", metricsHost)
}
cfgBytes, err := configapilatest.WriteYAML(cfg)
if err != nil {
return err
}
err = ioutil.WriteFile(masterConfig, cfgBytes, 0644)
if err != nil {
return err
}
return h.hostHelper.CopyMasterConfigToHost(masterConfig, hostDir)
}
开发者ID:ncdc,项目名称:origin,代码行数:29,代码来源:helper.go
示例2: updateConfig
func (h *Helper) updateConfig(configDir, hostDir, routerIP, metricsHost, loggingHost string) error {
cfg, configPath, err := h.GetConfig(configDir)
if err != nil {
return err
}
if len(h.routingSuffix) > 0 {
cfg.RoutingConfig.Subdomain = h.routingSuffix
} else {
cfg.RoutingConfig.Subdomain = fmt.Sprintf("%s.xip.io", routerIP)
}
if len(metricsHost) > 0 && cfg.AssetConfig != nil {
cfg.AssetConfig.MetricsPublicURL = fmt.Sprintf("https://%s/hawkular/metrics", metricsHost)
}
if len(loggingHost) > 0 && cfg.AssetConfig != nil {
cfg.AssetConfig.LoggingPublicURL = fmt.Sprintf("https://%s", loggingHost)
}
cfgBytes, err := configapilatest.WriteYAML(cfg)
if err != nil {
return err
}
err = ioutil.WriteFile(configPath, cfgBytes, 0644)
if err != nil {
return err
}
return h.hostHelper.CopyMasterConfigToHost(configPath, hostDir)
}
开发者ID:mffiedler,项目名称:origin,代码行数:31,代码来源:helper.go
示例3: TestGetValidSessionSecretsFile
func TestGetValidSessionSecretsFile(t *testing.T) {
tmpfile, err := ioutil.TempFile("", "valid.yaml")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
defer os.Remove(tmpfile.Name())
secrets := &api.SessionSecrets{
Secrets: []api.SessionSecret{
{Authentication: "a1", Encryption: "e1"},
{Authentication: "a2", Encryption: "e2"},
},
}
expectedSecrets := []string{"a1", "e1", "a2", "e2"}
yaml, err := latest.WriteYAML(secrets)
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
ioutil.WriteFile(tmpfile.Name(), []byte(yaml), os.FileMode(0600))
readSecrets, err := getSessionSecrets(tmpfile.Name())
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
if !reflect.DeepEqual(readSecrets, expectedSecrets) {
t.Errorf("Unexpected %v, got %v", expectedSecrets, readSecrets)
}
}
开发者ID:RomainVabre,项目名称:origin,代码行数:29,代码来源:auth_config_test.go
示例4: setupAdmissionPluginTestConfig
func setupAdmissionPluginTestConfig(t *testing.T, value string) string {
configFile, err := ioutil.TempFile("", "admission-config")
if err != nil {
t.Fatalf("error creating temp file: %v", err)
}
configFile.Close()
configObj := &TestPluginConfig{
Data: value,
}
configContent, err := configapilatest.WriteYAML(configObj)
if err != nil {
t.Fatalf("error writing config: %v", err)
}
ioutil.WriteFile(configFile.Name(), configContent, 0644)
return configFile.Name()
}
开发者ID:LalatenduMohanty,项目名称:origin,代码行数:16,代码来源:admissionconfig_test.go
示例5: GetPluginConfig
func GetPluginConfig(cfg configapi.AdmissionPluginConfig) (string, error) {
obj := cfg.Configuration.Object
if obj == nil {
return cfg.Location, nil
}
configFile, err := ioutil.TempFile("", "admission-plugin-config")
if err != nil {
return "", err
}
if err = configFile.Close(); err != nil {
return "", err
}
content, err := latest.WriteYAML(obj)
if err != nil {
return "", err
}
if err = ioutil.WriteFile(configFile.Name(), content, 0644); err != nil {
return "", err
}
return configFile.Name(), nil
}
开发者ID:abhat,项目名称:origin,代码行数:22,代码来源:config.go
示例6: TestGetEmptySessionSecretsFile
func TestGetEmptySessionSecretsFile(t *testing.T) {
tmpfile, err := ioutil.TempFile("", "empty.yaml")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
defer os.Remove(tmpfile.Name())
secrets := &api.SessionSecrets{
Secrets: []api.SessionSecret{},
}
yaml, err := latest.WriteYAML(secrets)
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
ioutil.WriteFile(tmpfile.Name(), []byte(yaml), os.FileMode(0600))
_, err = getSessionSecrets(tmpfile.Name())
if err == nil {
t.Errorf("Expected error, got none")
}
}
开发者ID:RomainVabre,项目名称:origin,代码行数:22,代码来源:auth_config_test.go
示例7: 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()
}
开发者ID:sgallagher,项目名称:origin,代码行数:97,代码来源:start_master.go
示例8: MakeNodeConfig
func (o CreateNodeConfigOptions) MakeNodeConfig(serverCertFile, serverKeyFile, nodeClientCAFile, kubeConfigFile, nodeConfigFile string) error {
config := &configapi.NodeConfig{
NodeName: o.NodeName,
ServingInfo: configapi.ServingInfo{
BindAddress: net.JoinHostPort(o.ListenAddr.Host, strconv.Itoa(ports.KubeletPort)),
},
VolumeDirectory: o.VolumeDir,
AllowDisabledDocker: o.AllowDisabledDocker,
ImageConfig: configapi.ImageConfig{
Format: o.ImageTemplate.Format,
Latest: o.ImageTemplate.Latest,
},
DNSDomain: o.DNSDomain,
DNSIP: o.DNSIP,
MasterKubeConfig: kubeConfigFile,
NetworkConfig: configapi.NodeNetworkConfig{
NetworkPluginName: o.NetworkPluginName,
},
}
if o.UseTLS() {
config.ServingInfo.ServerCert = configapi.CertInfo{
CertFile: serverCertFile,
KeyFile: serverKeyFile,
}
config.ServingInfo.ClientCA = nodeClientCAFile
}
// Resolve relative to CWD
cwd, err := os.Getwd()
if err != nil {
return err
}
if err := configapi.ResolveNodeConfigPaths(config, cwd); err != nil {
return err
}
// Relativize to config file dir
base, err := cmdutil.MakeAbs(o.NodeConfigDir, cwd)
if err != nil {
return err
}
if err := configapi.RelativizeNodeConfigPaths(config, base); err != nil {
return err
}
// Roundtrip the config to v1 and back to ensure proper defaults are set.
ext, err := configapi.Scheme.ConvertToVersion(config, latestconfigapi.Version)
if err != nil {
return err
}
internal, err := configapi.Scheme.ConvertToVersion(ext, configapi.SchemeGroupVersion)
if err != nil {
return err
}
content, err := latestconfigapi.WriteYAML(internal)
if err != nil {
return err
}
if err := ioutil.WriteFile(nodeConfigFile, content, 0644); err != nil {
return err
}
return nil
}
开发者ID:legionus,项目名称:origin,代码行数:72,代码来源:create_nodeconfig.go
示例9: 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
}
开发者ID:brandon-adams,项目名称:origin,代码行数:81,代码来源:start_master.go
示例10: TestConfigReader
func TestConfigReader(t *testing.T) {
initialConfig := testConfig(10, 20, 30)
serializedConfig, serializationErr := configapilatest.WriteYAML(initialConfig)
if serializationErr != nil {
t.Fatalf("WriteYAML: config serialize failed: %v", serializationErr)
}
tests := []struct {
name string
config io.Reader
expectErr bool
expectNil bool
expectInvalid bool
expectedConfig *api.ClusterResourceOverrideConfig
}{
{
name: "process nil config",
config: nil,
expectNil: true,
}, {
name: "deserialize initialConfig yaml",
config: bytes.NewReader(serializedConfig),
expectedConfig: initialConfig,
}, {
name: "completely broken config",
config: bytes.NewReader([]byte("asdfasdfasdF")),
expectErr: true,
}, {
name: "deserialize yamlConfig",
config: bytes.NewReader([]byte(yamlConfig)),
expectedConfig: deserializedYamlConfig,
}, {
name: "choke on out-of-bounds ratio",
config: bytes.NewReader([]byte(invalidConfig)),
expectInvalid: true,
}, {
name: "complain about no settings",
config: bytes.NewReader([]byte(invalidConfig2)),
expectInvalid: true,
},
}
for _, test := range tests {
config, err := ReadConfig(test.config)
if test.expectErr && err == nil {
t.Errorf("%s: expected error", test.name)
} else if !test.expectErr && err != nil {
t.Errorf("%s: expected no error, saw %v", test.name, err)
}
if err == nil {
if test.expectNil && config != nil {
t.Errorf("%s: expected nil config, but saw: %v", test.name, config)
} else if !test.expectNil && config == nil {
t.Errorf("%s: expected config, but got nil", test.name)
}
}
if config != nil {
if test.expectedConfig != nil && *test.expectedConfig != *config {
t.Errorf("%s: expected %v from reader, but got %v", test.name, test.expectErr, config)
}
if err := validation.Validate(config); test.expectInvalid && len(err) == 0 {
t.Errorf("%s: expected validation to fail, but it passed", test.name)
} else if !test.expectInvalid && len(err) > 0 {
t.Errorf("%s: expected validation to pass, but it failed with %v", test.name, err)
}
}
}
}
开发者ID:vikaslaad,项目名称:origin,代码行数:67,代码来源:admission_test.go
示例11: TestOAuthLDAP
//.........这里部分代码省略.........
EncryptedFile: bindPasswordFile.Name(),
GenKeyFile: bindPasswordKeyFile.Name(),
}
if err := encryptOpts.Encrypt(); err != nil {
t.Fatalf("unexpected error: %v", err)
}
masterOptions.OAuthConfig.IdentityProviders[0] = configapi.IdentityProvider{
Name: providerName,
UseAsChallenger: true,
UseAsLogin: true,
MappingMethod: "claim",
Provider: &configapi.LDAPPasswordIdentityProvider{
URL: fmt.Sprintf("ldap://%s/%s?%s?%s?%s", ldapAddress, searchDN, searchAttr, searchScope, searchFilter),
BindDN: bindDN,
BindPassword: configapi.StringSource{
StringSourceSpec: configapi.StringSourceSpec{
File: bindPasswordFile.Name(),
KeyFile: bindPasswordKeyFile.Name(),
},
},
Insecure: true,
CA: "",
Attributes: configapi.LDAPAttributeMapping{
ID: []string{idAttr1, idAttr2},
PreferredUsername: []string{loginAttr1, loginAttr2},
Name: []string{nameAttr1, nameAttr2},
Email: []string{emailAttr1, emailAttr2},
},
},
}
// serialize to YAML to make sure a complex StringSource survives a round-trip
serializedOptions, err := configapilatest.WriteYAML(masterOptions)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
// read back in
deserializedObject, err := configapilatest.ReadYAML(bytes.NewBuffer(serializedOptions))
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
// assert type and proceed, using the deserialized version as our config
if deserializedOptions, ok := deserializedObject.(*configapi.MasterConfig); !ok {
t.Fatalf("unexpected object: %v", deserializedObject)
} else {
masterOptions = deserializedOptions
}
clusterAdminKubeConfig, err := testserver.StartConfiguredMaster(masterOptions)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
clusterAdminClientConfig, err := testutil.GetClusterAdminClientConfig(clusterAdminKubeConfig)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
clusterAdminClient, err := testutil.GetClusterAdminClient(clusterAdminKubeConfig)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
// Use the server and CA info
anonConfig := restclient.Config{}
anonConfig.Host = clusterAdminClientConfig.Host
开发者ID:Xmagicer,项目名称:origin,代码行数:67,代码来源:oauth_ldap_test.go
示例12: TestLimitRequestAdmission
func TestLimitRequestAdmission(t *testing.T) {
tests := []struct {
name string
config *api.ClusterResourceOverrideConfig
object runtime.Object
expectedMemRequest resource.Quantity
expectedCpuLimit resource.Quantity
expectedCpuRequest resource.Quantity
namespace *kapi.Namespace
}{
{
name: "this thing even runs",
config: testConfig(100, 50, 50),
object: testPod("0", "0", "0", "0"),
expectedMemRequest: resource.MustParse("0"),
expectedCpuLimit: resource.MustParse("0"),
expectedCpuRequest: resource.MustParse("0"),
namespace: fakeNamespace(true),
},
{
name: "nil config",
config: nil,
object: testPod("1", "1", "1", "1"),
expectedMemRequest: resource.MustParse("1"),
expectedCpuLimit: resource.MustParse("1"),
expectedCpuRequest: resource.MustParse("1"),
namespace: fakeNamespace(true),
},
{
name: "all values are adjusted",
config: testConfig(100, 50, 50),
object: testPod("1Gi", "0", "2000m", "0"),
expectedMemRequest: resource.MustParse("512Mi"),
expectedCpuLimit: resource.MustParse("1"),
expectedCpuRequest: resource.MustParse("500m"),
namespace: fakeNamespace(true),
},
{
name: "just requests are adjusted",
config: testConfig(0, 50, 50),
object: testPod("10Mi", "0", "50m", "0"),
expectedMemRequest: resource.MustParse("5Mi"),
expectedCpuLimit: resource.MustParse("50m"),
expectedCpuRequest: resource.MustParse("25m"),
namespace: fakeNamespace(true),
},
{
name: "project annotation disables overrides",
config: testConfig(0, 50, 50),
object: testPod("10Mi", "0", "50m", "0"),
expectedMemRequest: resource.MustParse("0"),
expectedCpuLimit: resource.MustParse("50m"),
expectedCpuRequest: resource.MustParse("0"),
namespace: fakeNamespace(false),
},
{
name: "large values don't overflow",
config: testConfig(100, 50, 50),
object: testPod("1Ti", "0", "0", "0"),
expectedMemRequest: resource.MustParse("512Gi"),
expectedCpuLimit: resource.MustParse("1024"),
expectedCpuRequest: resource.MustParse("512"),
namespace: fakeNamespace(true),
},
{
name: "little values don't get lost",
config: testConfig(500, 10, 10),
object: testPod("1.024Mi", "0", "0", "0"),
expectedMemRequest: resource.MustParse(".0001Gi"),
expectedCpuLimit: resource.MustParse("5m"),
expectedCpuRequest: resource.MustParse(".5m"),
namespace: fakeNamespace(true),
},
}
for _, test := range tests {
var reader io.Reader
if test.config != nil { // we would get nil with the plugin un-configured
config, err := configapilatest.WriteYAML(test.config)
if err != nil {
t.Fatalf("unexpected: %v", err)
}
reader = bytes.NewReader(config)
}
c, err := newClusterResourceOverride(fake.NewSimpleClientset(), reader)
if err != nil {
t.Errorf("%s: config de/serialize failed: %v", test.name, err)
continue
}
c.(*clusterResourceOverridePlugin).SetProjectCache(fakeProjectCache(test.namespace))
attrs := admission.NewAttributesRecord(test.object, unversioned.GroupKind{}, test.namespace.Name, "name", kapi.Resource("pods"), "", admission.Create, fakeUser())
if err := c.Admit(attrs); err != nil {
t.Errorf("%s: admission controller should not return error", test.name)
}
// if it's a pod, test that the resources are as expected
pod, ok := test.object.(*kapi.Pod)
if !ok {
continue
}
resources := pod.Spec.Containers[0].Resources // only test one container
//.........这里部分代码省略.........
开发者ID:richm,项目名称:origin,代码行数:101,代码来源:admission_test.go
注:本文中的github.com/openshift/origin/pkg/cmd/server/api/latest.WriteYAML函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论