本文整理汇总了Golang中github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider.TCPLoadBalancer.CreateTCPLoadBalancer方法的典型用法代码示例。如果您正苦于以下问题:Golang TCPLoadBalancer.CreateTCPLoadBalancer方法的具体用法?Golang TCPLoadBalancer.CreateTCPLoadBalancer怎么用?Golang TCPLoadBalancer.CreateTCPLoadBalancer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider.TCPLoadBalancer
的用法示例。
在下文中一共展示了TCPLoadBalancer.CreateTCPLoadBalancer方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Create
func (sr *ServiceRegistryStorage) Create(obj interface{}) (<-chan interface{}, error) {
srv := obj.(api.Service)
if srv.ID == "" {
return nil, fmt.Errorf("ID should not be empty: %#v", srv)
}
return apiserver.MakeAsync(func() (interface{}, error) {
// TODO: Consider moving this to a rectification loop, so that we make/remove external load balancers
// correctly no matter what http operations happen.
if srv.CreateExternalLoadBalancer {
var balancer cloudprovider.TCPLoadBalancer
var ok bool
if sr.cloud != nil {
balancer, ok = sr.cloud.TCPLoadBalancer()
}
if ok && balancer != nil {
hosts, err := sr.machines.List()
if err != nil {
return nil, err
}
err = balancer.CreateTCPLoadBalancer(srv.ID, "us-central1", srv.Port, hosts)
if err != nil {
return nil, err
}
} else {
return nil, fmt.Errorf("requested an external service, but no cloud provider supplied.")
}
}
// TODO actually wait for the object to be fully created here.
err := sr.registry.CreateService(srv)
if err != nil {
return nil, err
}
return sr.registry.GetService(srv.ID)
}), nil
}
示例2: Create
func (sr *ServiceRegistryStorage) Create(obj interface{}) (<-chan interface{}, error) {
srv := obj.(api.Service)
if errs := api.ValidateService(&srv); len(errs) > 0 {
return nil, fmt.Errorf("Validation errors: %v", errs)
}
return apiserver.MakeAsync(func() (interface{}, error) {
// TODO: Consider moving this to a rectification loop, so that we make/remove external load balancers
// correctly no matter what http operations happen.
if srv.CreateExternalLoadBalancer {
var balancer cloudprovider.TCPLoadBalancer
var zones cloudprovider.Zones
var ok bool
if sr.cloud != nil {
balancer, ok = sr.cloud.TCPLoadBalancer()
if ok {
zones, ok = sr.cloud.Zones()
}
}
if ok && balancer != nil && zones != nil {
hosts, err := sr.machines.List()
if err != nil {
return nil, err
}
zone, err := zones.GetZone()
if err != nil {
return nil, err
}
err = balancer.CreateTCPLoadBalancer(srv.ID, zone, srv.Port, hosts)
if err != nil {
return nil, err
}
} else {
return nil, fmt.Errorf("requested an external service, but no cloud provider supplied.")
}
}
// TODO actually wait for the object to be fully created here.
err := sr.registry.CreateService(srv)
if err != nil {
return nil, err
}
return sr.registry.GetService(srv.ID)
}), nil
}
示例3: Create
func (sr *ServiceRegistryStorage) Create(obj interface{}) (<-chan interface{}, error) {
srv := obj.(api.Service)
if srv.CreateExternalLoadBalancer {
var balancer cloudprovider.TCPLoadBalancer
var ok bool
if sr.cloud != nil {
balancer, ok = sr.cloud.TCPLoadBalancer()
}
if ok && balancer != nil {
err := balancer.CreateTCPLoadBalancer(srv.ID, "us-central1", srv.Port, sr.hosts)
if err != nil {
return nil, err
}
} else {
return nil, fmt.Errorf("requested an external service, but no cloud provider supplied.")
}
}
// TODO actually wait for the object to be fully created here.
return apiserver.MakeAsync(func() interface{} { return obj }), sr.registry.CreateService(srv)
}
示例4: Create
func (sr *ServiceRegistryStorage) Create(obj interface{}) error {
srv := obj.(api.Service)
if srv.CreateExternalLoadBalancer {
var balancer cloudprovider.TCPLoadBalancer
if sr.cloud != nil {
var err error
balancer, err = sr.cloud.TCPLoadBalancer()
if err != nil {
return err
}
}
if balancer != nil {
err := balancer.CreateTCPLoadBalancer(srv.ID, "us-central1", srv.Port, sr.hosts)
if err != nil {
return err
}
} else {
return fmt.Errorf("requested an external service, but no cloud provider supplied.")
}
}
return sr.registry.CreateService(srv)
}