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

Commit fc99c7a

Browse files
author
Kubernetes Submit Queue
authored
Merge pull request #49697 from zetaab/mfloating
Automatic merge from submit-queue (batch tested with PRs 47416, 47408, 49697, 49860, 50162) add possibility to use multiple floatingip pools in openstack loadbalancer **What this PR does / why we need it**: Currently only one floating pool is supported in kubernetes openstack cloud provider. It is quite big issue for us, because we want run only single kubernetes cluster, but we want that external and internal services can be used. It means that we need possibility to create services with internal and external pools. **Which issue this PR fixes**: fixes #49147 **Special notes for your reviewer**: service labels is not maybe correct place to define this floatingpool id. However, I did not find any better place easily. I do not want start modifying service api structure. **Release note**: ```release-note Add possibility to use multiple floatingip pools in openstack loadbalancer ``` Example how it works: ``` cat /etc/kubernetes/cloud-config [Global] auth-url=https://xxxx username=xxxx password=xxxx region=yyy tenant-id=b23efb65b1d44b5abd561511f40c565d domain-name=foobar [LoadBalancer] lb-version=v2 subnet-id=aed26269-cd01-4d4e-b0d8-9ec726c4c2ba lb-method=ROUND_ROBIN floating-network-id=56e523e7-76cb-477f-80e4-2dc8cf32e3b4 create-monitor=yes monitor-delay=10s monitor-timeout=2000s monitor-max-retries=3 ``` ``` apiVersion: apps/v1beta1 kind: Deployment metadata: name: nginx-deployment spec: replicas: 1 template: metadata: labels: run: web spec: containers: - name: nginx image: nginx ports: - containerPort: 80 --- apiVersion: v1 kind: Service metadata: labels: run: web-ext name: web-ext namespace: default spec: selector: run: web ports: - port: 80 name: https protocol: TCP targetPort: 80 type: LoadBalancer --- apiVersion: v1 kind: Service metadata: labels: run: web-int floatingPool: a2a84887-4915-42bf-aaff-2b76688a4ec7 name: web-int namespace: default spec: selector: run: web ports: - port: 80 name: https protocol: TCP targetPort: 80 type: LoadBalancer ``` ``` % kubectl create -f example.yaml deployment "nginx-deployment" created service "web-ext" created service "web-int" created % kubectl get svc -o wide NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR kubernetes 10.254.0.1 <none> 443/TCP 2m <none> web-ext 10.254.23.153 192.168.1.57,193.xx.xxx.xxx 80:30151/TCP 52s run=web web-int 10.254.128.141 192.168.1.58,10.222.130.80 80:32431/TCP 52s run=web ``` cc @anguslees @k8s-sig-openstack-feature-requests @dims
2 parents 33ba8aa + 87c8bf8 commit fc99c7a

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

pkg/cloudprovider/providers/openstack/openstack_loadbalancer.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ const (
6666

6767
activeStatus = "ACTIVE"
6868
errorStatus = "ERROR"
69+
70+
ServiceAnnotationLoadBalancerFloatingNetworkId = "loadbalancer.openstack.org/floating-network-id"
6971
)
7072

7173
// LoadBalancer implementation for LBaaS v1
@@ -581,6 +583,21 @@ func nodeAddressForLB(node *v1.Node) (string, error) {
581583
return addrs[0].Address, nil
582584
}
583585

586+
//getStringFromServiceAnnotation searches a given v1.Service for a specific annotationKey and either returns the annotation's value or a specified defaultSetting
587+
func getStringFromServiceAnnotation(service *v1.Service, annotationKey string, defaultSetting string) string {
588+
glog.V(4).Infof("getStringFromServiceAnnotation(%v, %v, %v)", service, annotationKey, defaultSetting)
589+
if annotationValue, ok := service.Annotations[annotationKey]; ok {
590+
//if there is an annotation for this setting, set the "setting" var to it
591+
// annotationValue can be empty, it is working as designed
592+
// it makes possible for instance provisioning loadbalancer without floatingip
593+
glog.V(4).Infof("Found a Service Annotation: %v = %v", annotationKey, annotationValue)
594+
return annotationValue
595+
}
596+
//if there is no annotation, set "settings" var to the value from cloud config
597+
glog.V(4).Infof("Could not find a Service Annotation; falling back on cloud-config setting: %v = %v", annotationKey, defaultSetting)
598+
return defaultSetting
599+
}
600+
584601
// TODO: This code currently ignores 'region' and always creates a
585602
// loadbalancer in only the current OpenStack region. We should take
586603
// a list of regions (from config) and query/create loadbalancers in
@@ -598,6 +615,9 @@ func (lbaas *LbaasV2) EnsureLoadBalancer(clusterName string, apiService *v1.Serv
598615
return nil, fmt.Errorf("no ports provided to openstack load balancer")
599616
}
600617

618+
floatingPool := getStringFromServiceAnnotation(apiService, ServiceAnnotationLoadBalancerFloatingNetworkId, lbaas.opts.FloatingNetworkId)
619+
glog.V(4).Infof("EnsureLoadBalancer using floatingPool: %v", floatingPool)
620+
601621
// Check for TCP protocol on each port
602622
// TODO: Convert all error messages to use an event recorder
603623
for _, port := range ports {
@@ -827,10 +847,10 @@ func (lbaas *LbaasV2) EnsureLoadBalancer(clusterName string, apiService *v1.Serv
827847
if err != nil && err != ErrNotFound {
828848
return nil, fmt.Errorf("Error getting floating ip for port %s: %v", portID, err)
829849
}
830-
if floatIP == nil && lbaas.opts.FloatingNetworkId != "" {
850+
if floatIP == nil && floatingPool != "" {
831851
glog.V(4).Infof("Creating floating ip for loadbalancer %s port %s", loadbalancer.ID, portID)
832852
floatIPOpts := floatingips.CreateOpts{
833-
FloatingNetworkID: lbaas.opts.FloatingNetworkId,
853+
FloatingNetworkID: floatingPool,
834854
PortID: portID,
835855
}
836856
floatIP, err = floatingips.Create(lbaas.network, floatIPOpts).Extract()

0 commit comments

Comments
 (0)