-
Notifications
You must be signed in to change notification settings - Fork 303
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
Bugfix: Delete unused GCE load-balancer resources on ingress spec change #894
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,8 @@ import ( | |
"net/http" | ||
|
||
"google.golang.org/api/compute/v1" | ||
"k8s.io/ingress-gce/pkg/annotations" | ||
"k8s.io/ingress-gce/pkg/flags" | ||
"k8s.io/ingress-gce/pkg/utils" | ||
"k8s.io/ingress-gce/pkg/utils/namer" | ||
"k8s.io/klog" | ||
|
@@ -31,26 +33,33 @@ func (l *L7) checkStaticIP() (err error) { | |
if l.fw == nil || l.fw.IPAddress == "" { | ||
return fmt.Errorf("will not create static IP without a forwarding rule") | ||
} | ||
managedStaticIPName := l.namer.ForwardingRule(namer.HTTPProtocol) | ||
// Don't manage staticIPs if the user has specified an IP. | ||
if address, manageStaticIP := l.getEffectiveIP(); !manageStaticIP { | ||
klog.V(3).Infof("Not managing user specified static IP %v", address) | ||
if flags.F.EnableDeleteUnusedFrontends { | ||
// Delete ingress controller managed static ip if exists. | ||
if ip, ok := l.ingress.Annotations[annotations.StaticIPKey]; ok && ip == managedStaticIPName { | ||
return l.deleteStaticIP() | ||
} | ||
} | ||
return nil | ||
} | ||
staticIPName := l.namer.ForwardingRule(namer.HTTPProtocol) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What was the motivation for changing the name of this var? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had to move this line to the top of the loop. At that point, we are still nor sure if this is the static IP name. getEffectiveIP may return a different name for static IP. |
||
ip, _ := l.cloud.GetGlobalAddress(staticIPName) | ||
|
||
ip, _ := l.cloud.GetGlobalAddress(managedStaticIPName) | ||
if ip == nil { | ||
klog.V(3).Infof("Creating static ip %v", staticIPName) | ||
err = l.cloud.ReserveGlobalAddress(&compute.Address{Name: staticIPName, Address: l.fw.IPAddress}) | ||
klog.V(3).Infof("Creating static ip %v", managedStaticIPName) | ||
err = l.cloud.ReserveGlobalAddress(&compute.Address{Name: managedStaticIPName, Address: l.fw.IPAddress}) | ||
if err != nil { | ||
if utils.IsHTTPErrorCode(err, http.StatusConflict) || | ||
utils.IsHTTPErrorCode(err, http.StatusBadRequest) { | ||
klog.V(3).Infof("IP %v(%v) is already reserved, assuming it is OK to use.", | ||
l.fw.IPAddress, staticIPName) | ||
l.fw.IPAddress, managedStaticIPName) | ||
return nil | ||
} | ||
return err | ||
} | ||
ip, err = l.cloud.GetGlobalAddress(staticIPName) | ||
ip, err = l.cloud.GetGlobalAddress(managedStaticIPName) | ||
if err != nil { | ||
return err | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does StatusPrefix need to be exported anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are couple of other places where this is referenced.
ingress-gce/pkg/loadbalancers/l7.go
Line 378 in ba81191