Unverified Commit 403055cb authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #55393 from jamiehannaford/octavia

Automatic merge from submit-queue (batch tested with PRs 55868, 55393, 55152, 55849). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Adds Octavia v2 as LoadBalancer provider **What this PR does / why we need it**: Adds support for using Octavia as the OpenStack LB provider. **Which issue(s) this PR fixes**: Although some LB providers can be specified using the [lb-provider](https://github.com/kubernetes/kubernetes/pull/54176/files#diff-694c675fe77b09923cc453e7228f8fa8R85) JSON request field, other installations which use Octavia by default rely on it being discovered via the service catalog. When a user specifies the `load-balancer` service type, it will get back the root Octavia endpoint URL, which needs to have `v2.0` appended to it. To facilitate this change, gophercloud recently added the `NewLoadBalancerV2` helper in https://github.com/gophercloud/gophercloud/pull/591. **Release note**: ```release-note Octavia v2 now supported as a LB provider ``` /cc @xgerman
parents ff5cea4b 29855470
......@@ -74,11 +74,13 @@ func (d *MyDuration) UnmarshalText(text []byte) error {
type LoadBalancer struct {
network *gophercloud.ServiceClient
compute *gophercloud.ServiceClient
lb *gophercloud.ServiceClient
opts LoadBalancerOpts
}
type LoadBalancerOpts struct {
LBVersion string `gcfg:"lb-version"` // overrides autodetection. Only support v2.
UseOctavia bool `gcfg:"use-octavia"` // uses Octavia V2 service catalog endpoint
SubnetId string `gcfg:"subnet-id"` // overrides autodetection.
FloatingNetworkId string `gcfg:"floating-network-id"` // If specified, will create floating ip for loadbalancer, or do not create floating ip.
LBMethod string `gcfg:"lb-method"` // default to ROUND_ROBIN.
......@@ -507,6 +509,11 @@ func (os *OpenStack) LoadBalancer() (cloudprovider.LoadBalancer, bool) {
return nil, false
}
lb, err := os.NewLoadBalancerV2()
if err != nil {
return nil, false
}
// LBaaS v1 is deprecated in the OpenStack Liberty release.
// Currently kubernetes OpenStack cloud provider just support LBaaS v2.
lbVersion := os.lbOpts.LBVersion
......@@ -517,7 +524,7 @@ func (os *OpenStack) LoadBalancer() (cloudprovider.LoadBalancer, bool) {
glog.V(1).Info("Claiming to support LoadBalancer")
return &LbaasV2{LoadBalancer{network, compute, os.lbOpts}}, true
return &LbaasV2{LoadBalancer{network, compute, lb, os.lbOpts}}, true
}
func isNotFound(err error) bool {
......
......@@ -62,3 +62,21 @@ func (os *OpenStack) NewBlockStorageV2() (*gophercloud.ServiceClient, error) {
}
return storage, nil
}
func (os *OpenStack) NewLoadBalancerV2() (*gophercloud.ServiceClient, error) {
var lb *gophercloud.ServiceClient
var err error
if os.lbOpts.UseOctavia {
lb, err = openstack.NewLoadBalancerV2(os.provider, gophercloud.EndpointOpts{
Region: os.region,
})
} else {
lb, err = openstack.NewNetworkV2(os.provider, gophercloud.EndpointOpts{
Region: os.region,
})
}
if err != nil {
return nil, fmt.Errorf("failed to find load-balancer v2 endpoint for region %s: %v", os.region, err)
}
return lb, nil
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment