本文整理汇总了Golang中github.com/openshift/origin/pkg/client.SetOpenShiftDefaults函数的典型用法代码示例。如果您正苦于以下问题:Golang SetOpenShiftDefaults函数的具体用法?Golang SetOpenShiftDefaults怎么用?Golang SetOpenShiftDefaults使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SetOpenShiftDefaults函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: ClientConfigForVersion
// ClientConfigForVersion returns the correct config for a server
func (c *clientCache) ClientConfigForVersion(version *unversioned.GroupVersion) (*kclient.Config, error) {
if c.defaultConfig == nil {
config, err := c.loader.ClientConfig()
if err != nil {
return nil, err
}
c.defaultConfig = config
}
// TODO: have a better config copy method
cacheKey := ""
if version != nil {
cacheKey = version.String()
}
if config, ok := c.configs[cacheKey]; ok {
return config, nil
}
if c.negotiatingClient == nil {
// TODO: We want to reuse the upstream negotiation logic, which is coupled
// to a concrete kube Client. The negotiation will ultimately try and
// build an unversioned URL using the config prefix to ask for supported
// server versions. If we use the default kube client config, the prefix
// will be /api, while we need to use the OpenShift prefix to ask for the
// OpenShift server versions. For now, set OpenShift defaults on the
// config to ensure the right prefix gets used. The client cache and
// negotiation logic should be refactored upstream to support downstream
// reuse so that we don't need to do any of this cache or negotiation
// duplication.
negotiatingConfig := *c.defaultConfig
client.SetOpenShiftDefaults(&negotiatingConfig)
negotiatingClient, err := kclient.New(&negotiatingConfig)
if err != nil {
return nil, err
}
c.negotiatingClient = negotiatingClient
}
config := *c.defaultConfig
negotiatedVersion, err := negotiateVersion(c.negotiatingClient, &config, version, latest.Versions)
if err != nil {
return nil, err
}
config.GroupVersion = negotiatedVersion
client.SetOpenShiftDefaults(&config)
c.configs[cacheKey] = &config
// `version` does not necessarily equal `config.Version`. However, we know that we call this method again with
// `config.Version`, we should get the the config we've just built.
configCopy := config
c.configs[config.GroupVersion.String()] = &configCopy
return &config, nil
}
开发者ID:arilivigni,项目名称:origin,代码行数:52,代码来源:factory.go
示例2: TestClientConfigForVersion
func TestClientConfigForVersion(t *testing.T) {
called := 0
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
if req.URL.Path != "/oapi" {
t.Fatalf("Unexpected path called during negotiation: %s", req.URL.Path)
}
called++
w.Write([]byte(`{"versions":["v1"]}`))
}))
defer server.Close()
defaultConfig := &kclient.Config{Host: server.URL}
client.SetOpenShiftDefaults(defaultConfig)
clients := &clientCache{
clients: make(map[string]*client.Client),
configs: make(map[string]*kclient.Config),
defaultConfig: defaultConfig,
}
// First call, negotiate
called = 0
v1Config, err := clients.ClientConfigForVersion("v1")
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
if v1Config.Version != "v1" {
t.Fatalf("Expected v1, got %v", v1Config.Version)
}
if called != 1 {
t.Fatalf("Expected to be called 1 time during negotiation, was called %d times", called)
}
// Second call, cache
called = 0
v1Config, err = clients.ClientConfigForVersion("v1")
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
if v1Config.Version != "v1" {
t.Fatalf("Expected v1, got %v", v1Config.Version)
}
if called != 0 {
t.Fatalf("Expected not be called again getting a config from cache, was called %d additional times", called)
}
// Call for unsupported version, negotiate to supported version
called = 0
v1beta3Config, err := clients.ClientConfigForVersion("v1beta3")
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
if v1beta3Config.Version != "v1" {
t.Fatalf("Expected to negotiate v1 for v1beta3 config, got %v", v1beta3Config.Version)
}
if called != 1 {
t.Fatalf("Expected to be called once getting a config for a new version, was called %d times", called)
}
}
开发者ID:hloganathan,项目名称:origin,代码行数:59,代码来源:factory_test.go
示例3: ClientConfigForVersion
// ClientConfigForVersion returns the correct config for a server
func (c *clientCache) ClientConfigForVersion(version string) (*kclient.Config, error) {
if c.defaultConfig == nil {
config, err := c.loader.ClientConfig()
if err != nil {
return nil, err
}
c.defaultConfig = config
}
// TODO: have a better config copy method
if config, ok := c.configs[version]; ok {
return config, nil
}
if c.negotiatingClient == nil {
// TODO: We want to reuse the upstream negotiation logic, which is coupled
// to a concrete kube Client. The negotiation will ultimately try and
// build an unversioned URL using the config prefix to ask for supported
// server versions. If we use the default kube client config, the prefix
// will be /api, while we need to use the OpenShift prefix to ask for the
// OpenShift server versions. For now, set OpenShift defaults on the
// config to ensure the right prefix gets used. The client cache and
// negotiation logic should be refactored upstream to support downstream
// reuse so that we don't need to do any of this cache or negotiation
// duplication.
negotiatingConfig := *c.defaultConfig
client.SetOpenShiftDefaults(&negotiatingConfig)
negotiatingClient, err := kclient.New(&negotiatingConfig)
if err != nil {
return nil, err
}
c.negotiatingClient = negotiatingClient
}
config := *c.defaultConfig
negotiatedVersion, err := kclient.NegotiateVersion(c.negotiatingClient, &config, version, latest.Versions)
if err != nil {
return nil, err
}
config.Version = negotiatedVersion
client.SetOpenShiftDefaults(&config)
c.configs[version] = &config
return &config, nil
}
开发者ID:porcelli,项目名称:origin,代码行数:43,代码来源:factory.go
示例4: ClientConfigForVersion
// ClientConfigForVersion returns the correct config for a server
func (c *clientCache) ClientConfigForVersion(version string) (*kclient.Config, error) {
if c.defaultConfig == nil {
config, err := c.loader.ClientConfig()
if err != nil {
return nil, err
}
c.defaultConfig = config
}
// TODO: have a better config copy method
config := *c.defaultConfig
if len(version) != 0 {
config.Version = version
}
client.SetOpenShiftDefaults(&config)
return &config, nil
}
开发者ID:MarWestermann,项目名称:gofabric8,代码行数:18,代码来源:factory.go
示例5: NewFactory
//.........这里部分代码省略.........
gv := unversioned.GroupVersion{Group: group.Group.Name, Version: version.Version}
if !registered.IsRegisteredVersion(gv) {
registered.AddThirdPartyAPIGroupVersions(gv)
}
}
}
// construct unstructured mapper and typer
mapper := discovery.NewRESTMapper(groupResources, meta.InterfacesForUnstructured)
typer := discovery.NewUnstructuredObjectTyper(groupResources)
return NewShortcutExpander(cachedDiscoverClient, kubectl.ShortcutExpander{RESTMapper: mapper}), typer, nil
}
kClientForMapping := w.Factory.ClientForMapping
w.ClientForMapping = func(mapping *meta.RESTMapping) (resource.RESTClient, error) {
if latest.OriginKind(mapping.GroupVersionKind) {
mappingVersion := mapping.GroupVersionKind.GroupVersion()
client, err := clients.ClientForVersion(&mappingVersion)
if err != nil {
return nil, err
}
return client.RESTClient, nil
}
return kClientForMapping(mapping)
}
kUnstructuredClientForMapping := w.Factory.UnstructuredClientForMapping
w.UnstructuredClientForMapping = func(mapping *meta.RESTMapping) (resource.RESTClient, error) {
if latest.OriginKind(mapping.GroupVersionKind) {
cfg, err := clientConfig.ClientConfig()
if err != nil {
return nil, err
}
if err := client.SetOpenShiftDefaults(cfg); err != nil {
return nil, err
}
cfg.APIPath = "/apis"
if mapping.GroupVersionKind.Group == api.GroupName {
cfg.APIPath = "/oapi"
}
gv := mapping.GroupVersionKind.GroupVersion()
cfg.ContentConfig = dynamic.ContentConfig()
cfg.GroupVersion = &gv
return restclient.RESTClientFor(cfg)
}
return kUnstructuredClientForMapping(mapping)
}
// Save original Describer function
kDescriberFunc := w.Factory.Describer
w.Describer = func(mapping *meta.RESTMapping) (kubectl.Describer, error) {
if latest.OriginKind(mapping.GroupVersionKind) {
oClient, kClient, err := w.Clients()
if err != nil {
return nil, fmt.Errorf("unable to create client %s: %v", mapping.GroupVersionKind.Kind, err)
}
mappingVersion := mapping.GroupVersionKind.GroupVersion()
cfg, err := clients.ClientConfigForVersion(&mappingVersion)
if err != nil {
return nil, fmt.Errorf("unable to load a client %s: %v", mapping.GroupVersionKind.Kind, err)
}
describer, ok := describe.DescriberFor(mapping.GroupVersionKind.GroupKind(), oClient, kClient, cfg.Host)
if !ok {
return nil, fmt.Errorf("no description has been implemented for %q", mapping.GroupVersionKind.Kind)
开发者ID:juanluisvaladas,项目名称:origin,代码行数:67,代码来源:factory.go
示例6: Admit
func (a *jenkinsBootstrapper) Admit(attributes admission.Attributes) error {
if a.jenkinsConfig.AutoProvisionEnabled != nil && !*a.jenkinsConfig.AutoProvisionEnabled {
return nil
}
if len(attributes.GetSubresource()) != 0 {
return nil
}
if attributes.GetResource().GroupResource() != buildapi.Resource("buildconfigs") && attributes.GetResource().GroupResource() != buildapi.Resource("builds") {
return nil
}
if !needsJenkinsTemplate(attributes.GetObject()) {
return nil
}
namespace := attributes.GetNamespace()
svcName := a.jenkinsConfig.ServiceName
if len(svcName) == 0 {
return nil
}
// TODO pull this from a cache.
if _, err := a.serviceClient.Services(namespace).Get(svcName); !kapierrors.IsNotFound(err) {
// if it isn't a "not found" error, return the error. Either its nil and there's nothing to do or something went really wrong
return err
}
glog.V(3).Infof("Adding new jenkins service %q to the project %q", svcName, namespace)
jenkinsTemplate := jenkinscontroller.NewPipelineTemplate(namespace, a.jenkinsConfig, a.openshiftClient)
objects, errs := jenkinsTemplate.Process()
if len(errs) > 0 {
return kutilerrors.NewAggregate(errs)
}
if !jenkinsTemplate.HasJenkinsService(objects) {
return fmt.Errorf("template %s/%s does not contain required service %q", a.jenkinsConfig.TemplateNamespace, a.jenkinsConfig.TemplateName, a.jenkinsConfig.ServiceName)
}
impersonatingConfig := a.privilegedRESTClientConfig
oldWrapTransport := impersonatingConfig.WrapTransport
impersonatingConfig.WrapTransport = func(rt http.RoundTripper) http.RoundTripper {
return authenticationclient.NewImpersonatingRoundTripper(attributes.GetUserInfo(), oldWrapTransport(rt))
}
var bulkErr error
bulk := &cmd.Bulk{
Mapper: &resource.Mapper{
RESTMapper: registered.RESTMapper(),
ObjectTyper: kapi.Scheme,
ClientMapper: resource.ClientMapperFunc(func(mapping *meta.RESTMapping) (resource.RESTClient, error) {
// TODO this is a nasty copy&paste from pkg/cmd/util/clientcmd/factory_object_mapping.go#ClientForMapping
if latest.OriginKind(mapping.GroupVersionKind) {
if err := client.SetOpenShiftDefaults(&impersonatingConfig); err != nil {
return nil, err
}
impersonatingConfig.APIPath = "/apis"
if mapping.GroupVersionKind.Group == kapi.GroupName {
impersonatingConfig.APIPath = "/oapi"
}
gv := mapping.GroupVersionKind.GroupVersion()
impersonatingConfig.GroupVersion = &gv
return restclient.RESTClientFor(&impersonatingConfig)
}
// TODO and this from vendor/k8s.io/kubernetes/pkg/kubectl/cmd/util/factory_object_mapping.go#ClientForMapping
if err := kclient.SetKubernetesDefaults(&impersonatingConfig); err != nil {
return nil, err
}
gvk := mapping.GroupVersionKind
switch gvk.Group {
case kapi.GroupName:
impersonatingConfig.APIPath = "/api"
default:
impersonatingConfig.APIPath = "/apis"
}
gv := gvk.GroupVersion()
impersonatingConfig.GroupVersion = &gv
return restclient.RESTClientFor(&impersonatingConfig)
}),
},
Op: cmd.Create,
After: func(info *resource.Info, err error) bool {
if kapierrors.IsAlreadyExists(err) {
return false
}
if err != nil {
bulkErr = err
return true
}
return false
},
}
// we're intercepting the error we care about using After
bulk.Run(objects, namespace)
if bulkErr != nil {
return bulkErr
}
glog.V(1).Infof("Jenkins Pipeline service %q created", svcName)
return nil
//.........这里部分代码省略.........
开发者ID:xgwang-zte,项目名称:origin,代码行数:101,代码来源:admission.go
示例7: TestClientConfigForVersion
func TestClientConfigForVersion(t *testing.T) {
called := 0
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
if req.URL.Path != "/oapi" {
t.Errorf("Unexpected path called during negotiation: %s", req.URL.Path)
return
}
called++
w.Write([]byte(`{"versions":["v1"]}`))
}))
defer server.Close()
defaultConfig := &restclient.Config{Host: server.URL}
client.SetOpenShiftDefaults(defaultConfig)
clients := &clientCache{
clients: make(map[string]*client.Client),
configs: make(map[string]*restclient.Config),
defaultConfig: defaultConfig,
}
// First call, negotiate
called = 0
v1Config, err := clients.ClientConfigForVersion(nil)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
if v1Config.GroupVersion.String() != "v1" {
t.Fatalf("Expected v1, got %v", v1Config.GroupVersion.String())
}
if called != 1 {
t.Fatalf("Expected to be called 1 time during negotiation, was called %d times", called)
}
// Second call, cache
called = 0
v1Config, err = clients.ClientConfigForVersion(nil)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
if v1Config.GroupVersion.String() != "v1" {
t.Fatalf("Expected v1, got %v", v1Config.GroupVersion.String())
}
if called != 0 {
t.Fatalf("Expected not be called again getting a config from cache, was called %d additional times", called)
}
// Third call, cached under exactly matching version
called = 0
v1Config, err = clients.ClientConfigForVersion(&v1.SchemeGroupVersion)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
if v1Config.GroupVersion.String() != "v1" {
t.Fatalf("Expected v1, got %v", v1Config.GroupVersion.String())
}
if called != 0 {
t.Fatalf("Expected not be called again getting a config from cache, was called %d additional times", called)
}
// Call for removed version, return error
called = 0
if _, err := clients.ClientConfigForVersion(&unversioned.GroupVersion{Version: "v1beta3"}); err == nil {
t.Fatalf("Unexpected non-error: %v", err)
}
if called != 1 {
t.Fatalf("Expected to be called once getting a config for a new version, was called %d times", called)
}
}
开发者ID:legionus,项目名称:origin,代码行数:69,代码来源:factory_test.go
注:本文中的github.com/openshift/origin/pkg/client.SetOpenShiftDefaults函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论