Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[occm] add tag on floating ip create #2577

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
20 changes: 20 additions & 0 deletions pkg/openstack/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/loadbalancers"
v2monitors "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/monitors"
v2pools "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools"
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/attributestags"
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips"
"github.com/gophercloud/gophercloud/openstack/networking/v2/subnets"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -571,6 +572,7 @@ func (lbaas *LbaasV2) createFloatingIP(msg string, floatIPOpts floatingips.Creat
if mc.ObserveRequest(err) != nil {
return floatIP, fmt.Errorf("error creating LB floatingip: %v", err)
}

return floatIP, err
}

Expand Down Expand Up @@ -735,6 +737,24 @@ func (lbaas *LbaasV2) ensureFloatingIP(clusterName string, service *corev1.Servi
}

if floatIP != nil {
tags, err := attributestags.List(lbaas.network, "floatingips", floatIP.ID).Extract()
if err != nil {
klog.V(3).Infof("Cannot get floatIP tags for floating %s", floatIP.ID)
return floatIP.FloatingIP, nil
}
found := false
for _, tag := range tags {
if tag == svcConf.lbName {
found = true
}
}
if !found {
err = attributestags.Add(lbaas.network, "floatingips", floatIP.ID, svcConf.lbName).ExtractErr()
if err != nil {
klog.V(3).Infof("Cannot update floatIP tag %s for floating %s", svcConf.lbName, floatIP.ID)
}
}

return floatIP.FloatingIP, nil
}

Expand Down