Skip to content
This repository was archived by the owner on Mar 22, 2018. It is now read-only.

Commit 6d95e2e

Browse files
committed
Merge branch 'fix-flocker-swallowed-error' into fix-storageos-swallowed-err
2 parents bc68861 + cd79a8e commit 6d95e2e

2 files changed

Lines changed: 64 additions & 20 deletions

File tree

pkg/cloudprovider/providers/openstack/openstack_loadbalancer.go

Lines changed: 64 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ const (
6868
errorStatus = "ERROR"
6969

7070
ServiceAnnotationLoadBalancerFloatingNetworkId = "loadbalancer.openstack.org/floating-network-id"
71+
72+
// ServiceAnnotationLoadBalancerInternal is the annotation used on the service
73+
// to indicate that we want an internal loadbalancer service.
74+
// If the value of ServiceAnnotationLoadBalancerInternal is false, it indicates that we want an external loadbalancer service. Default to true.
75+
ServiceAnnotationLoadBalancerInternal = "service.beta.kubernetes.io/openstack-internal-load-balancer"
7176
)
7277

7378
// LoadBalancer implementation for LBaaS v1
@@ -501,15 +506,15 @@ func createNodeSecurityGroup(client *gophercloud.ServiceClient, nodeSecurityGrou
501506
return nil
502507
}
503508

504-
func (lbaas *LbaasV2) createLoadBalancer(service *v1.Service, name string) (*loadbalancers.LoadBalancer, error) {
509+
func (lbaas *LbaasV2) createLoadBalancer(service *v1.Service, name string, internalAnnotation bool) (*loadbalancers.LoadBalancer, error) {
505510
createOpts := loadbalancers.CreateOpts{
506511
Name: name,
507512
Description: fmt.Sprintf("Kubernetes external service %s", name),
508513
VipSubnetID: lbaas.opts.SubnetId,
509514
}
510515

511516
loadBalancerIP := service.Spec.LoadBalancerIP
512-
if loadBalancerIP != "" {
517+
if loadBalancerIP != "" && internalAnnotation {
513518
createOpts.VipAddress = loadBalancerIP
514519
}
515520

@@ -626,6 +631,24 @@ func (lbaas *LbaasV2) EnsureLoadBalancer(clusterName string, apiService *v1.Serv
626631
floatingPool := getStringFromServiceAnnotation(apiService, ServiceAnnotationLoadBalancerFloatingNetworkId, lbaas.opts.FloatingNetworkId)
627632
glog.V(4).Infof("EnsureLoadBalancer using floatingPool: %v", floatingPool)
628633

634+
var internalAnnotation bool
635+
internal := getStringFromServiceAnnotation(apiService, ServiceAnnotationLoadBalancerInternal, "true")
636+
switch internal {
637+
case "true":
638+
glog.V(4).Infof("Ensure an internal loadbalancer service.")
639+
internalAnnotation = true
640+
case "false":
641+
if len(floatingPool) != 0 {
642+
glog.V(4).Infof("Ensure an external loadbalancer service.")
643+
internalAnnotation = false
644+
} else {
645+
return nil, fmt.Errorf("floating-network-id or loadbalancer.openstack.org/floating-network-id should be specified when service.beta.kubernetes.io/openstack-internal-load-balancer is false")
646+
}
647+
default:
648+
return nil, fmt.Errorf("unknow service.beta.kubernetes.io/openstack-internal-load-balancer annotation: %v, specify \"true\" or \"false\".",
649+
internal)
650+
}
651+
629652
// Check for TCP protocol on each port
630653
// TODO: Convert all error messages to use an event recorder
631654
for _, port := range ports {
@@ -661,7 +684,7 @@ func (lbaas *LbaasV2) EnsureLoadBalancer(clusterName string, apiService *v1.Serv
661684
return nil, fmt.Errorf("Error getting loadbalancer %s: %v", name, err)
662685
}
663686
glog.V(2).Infof("Creating loadbalancer %s", name)
664-
loadbalancer, err = lbaas.createLoadBalancer(apiService, name)
687+
loadbalancer, err = lbaas.createLoadBalancer(apiService, name, internalAnnotation)
665688
if err != nil {
666689
// Unknown error, retry later
667690
return nil, fmt.Errorf("Error creating loadbalancer %s: %v", name, err)
@@ -855,12 +878,18 @@ func (lbaas *LbaasV2) EnsureLoadBalancer(clusterName string, apiService *v1.Serv
855878
if err != nil && err != ErrNotFound {
856879
return nil, fmt.Errorf("Error getting floating ip for port %s: %v", portID, err)
857880
}
858-
if floatIP == nil && floatingPool != "" {
881+
if floatIP == nil && floatingPool != "" && !internalAnnotation {
859882
glog.V(4).Infof("Creating floating ip for loadbalancer %s port %s", loadbalancer.ID, portID)
860883
floatIPOpts := floatingips.CreateOpts{
861884
FloatingNetworkID: floatingPool,
862885
PortID: portID,
863886
}
887+
888+
loadBalancerIP := apiService.Spec.LoadBalancerIP
889+
if loadBalancerIP != "" {
890+
floatIPOpts.FloatingIP = loadBalancerIP
891+
}
892+
864893
floatIP, err = floatingips.Create(lbaas.network, floatIPOpts).Extract()
865894
if err != nil {
866895
return nil, fmt.Errorf("Error creating LB floatingip %+v: %v", floatIPOpts, err)
@@ -1283,6 +1312,27 @@ func (lb *LbaasV1) EnsureLoadBalancer(clusterName string, apiService *v1.Service
12831312
lb.opts.SubnetId = subnetID
12841313
}
12851314

1315+
floatingPool := getStringFromServiceAnnotation(apiService, ServiceAnnotationLoadBalancerFloatingNetworkId, lb.opts.FloatingNetworkId)
1316+
glog.V(4).Infof("EnsureLoadBalancer using floatingPool: %v", floatingPool)
1317+
1318+
var internalAnnotation bool
1319+
internal := getStringFromServiceAnnotation(apiService, ServiceAnnotationLoadBalancerInternal, "true")
1320+
switch internal {
1321+
case "true":
1322+
glog.V(4).Infof("Ensure an internal loadbalancer service.")
1323+
internalAnnotation = true
1324+
case "false":
1325+
if len(floatingPool) != 0 {
1326+
glog.V(4).Infof("Ensure an external loadbalancer service.")
1327+
internalAnnotation = false
1328+
} else {
1329+
return nil, fmt.Errorf("floating-network-id or loadbalancer.openstack.org/floating-network-id should be specified when service.beta.kubernetes.io/openstack-internal-load-balancer is false")
1330+
}
1331+
default:
1332+
return nil, fmt.Errorf("unknow service.beta.kubernetes.io/openstack-internal-load-balancer annotation: %v, specify \"true\" or \"false\".",
1333+
internal)
1334+
}
1335+
12861336
ports := apiService.Spec.Ports
12871337
if len(ports) > 1 {
12881338
return nil, fmt.Errorf("multiple ports are not supported in openstack v1 load balancers")
@@ -1393,7 +1443,7 @@ func (lb *LbaasV1) EnsureLoadBalancer(clusterName string, apiService *v1.Service
13931443
}
13941444

13951445
loadBalancerIP := apiService.Spec.LoadBalancerIP
1396-
if loadBalancerIP != "" {
1446+
if loadBalancerIP != "" && internalAnnotation {
13971447
createOpts.Address = loadBalancerIP
13981448
}
13991449

@@ -1406,11 +1456,17 @@ func (lb *LbaasV1) EnsureLoadBalancer(clusterName string, apiService *v1.Service
14061456

14071457
status.Ingress = []v1.LoadBalancerIngress{{IP: vip.Address}}
14081458

1409-
if lb.opts.FloatingNetworkId != "" {
1459+
if floatingPool != "" && !internalAnnotation {
14101460
floatIPOpts := floatingips.CreateOpts{
1411-
FloatingNetworkID: lb.opts.FloatingNetworkId,
1461+
FloatingNetworkID: floatingPool,
14121462
PortID: vip.PortID,
14131463
}
1464+
1465+
loadBalancerIP := apiService.Spec.LoadBalancerIP
1466+
if loadBalancerIP != "" {
1467+
floatIPOpts.FloatingIP = loadBalancerIP
1468+
}
1469+
14141470
floatIP, err := floatingips.Create(lb.network, floatIPOpts).Extract()
14151471
if err != nil {
14161472
return nil, fmt.Errorf("Error creating floatingip for openstack load balancer %s: %v", name, err)
@@ -1494,7 +1550,7 @@ func (lb *LbaasV1) EnsureLoadBalancerDeleted(clusterName string, service *v1.Ser
14941550
return err
14951551
}
14961552

1497-
if lb.opts.FloatingNetworkId != "" && vip != nil {
1553+
if vip != nil && vip.PortID != "" {
14981554
floatingIP, err := getFloatingIPByPortID(lb.network, vip.PortID)
14991555
if err != nil && !isNotFound(err) {
15001556
return err

pkg/volume/cinder/cinder.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -275,13 +275,6 @@ type cinderVolume struct {
275275
volume.MetricsNil
276276
}
277277

278-
func detachDiskLogError(cd *cinderVolume) {
279-
err := cd.manager.DetachDisk(&cinderVolumeUnmounter{cd})
280-
if err != nil {
281-
glog.Warningf("Failed to detach disk: %v (%v)", cd, err)
282-
}
283-
}
284-
285278
func (b *cinderVolumeMounter) GetAttributes() volume.Attributes {
286279
return volume.Attributes{
287280
ReadOnly: b.readOnly,
@@ -308,7 +301,6 @@ func (b *cinderVolumeMounter) SetUpAt(dir string, fsGroup *int64) error {
308301
b.plugin.volumeLocks.LockKey(b.pdName)
309302
defer b.plugin.volumeLocks.UnlockKey(b.pdName)
310303

311-
// TODO: handle failed mounts here.
312304
notmnt, err := b.mounter.IsLikelyNotMountPoint(dir)
313305
if err != nil && !os.IsNotExist(err) {
314306
glog.Errorf("Cannot validate mount point: %s %v", dir, err)
@@ -326,9 +318,7 @@ func (b *cinderVolumeMounter) SetUpAt(dir string, fsGroup *int64) error {
326318
}
327319

328320
if err := os.MkdirAll(dir, 0750); err != nil {
329-
// TODO: we should really eject the attach/detach out into its own control loop.
330321
glog.V(4).Infof("Could not create directory %s: %v", dir, err)
331-
detachDiskLogError(b.cinderVolume)
332322
return err
333323
}
334324

@@ -359,8 +349,6 @@ func (b *cinderVolumeMounter) SetUpAt(dir string, fsGroup *int64) error {
359349
}
360350
}
361351
os.Remove(dir)
362-
// TODO: we should really eject the attach/detach out into its own control loop.
363-
detachDiskLogError(b.cinderVolume)
364352
glog.Errorf("Failed to mount %s: %v", dir, err)
365353
return err
366354
}

0 commit comments

Comments
 (0)