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

Cherrypick #994[Use Static IP to create forwarding rule when available] into release 1.8 #999

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions pkg/loadbalancers/forwarding_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package loadbalancers

import (
"fmt"

"k8s.io/ingress-gce/pkg/annotations"
"k8s.io/ingress-gce/pkg/composite"
"k8s.io/ingress-gce/pkg/flags"
"k8s.io/ingress-gce/pkg/utils"
Expand Down Expand Up @@ -75,6 +77,22 @@ func (l *L7) checkForwardingRule(name, proxyLink, ip, portRange string) (fw *com
fw = nil
}
if fw == nil {
// This is a special case where exactly one of http or https forwarding rule
// existed before and the existing forwarding rule uses ingress managed static ip address.
// In this case, the forwarding rule needs to be created with the same static ip.
// Note that this is not needed when user specifies a static IP.
if ip == "" {
managedStaticIPName := l.namer.ForwardingRule(namer.HTTPProtocol)
// Get static IP address if ingress has static IP annotation.
// Note that this Static IP annotation is applied by ingress controller.
if currentIPName, exists := l.ingress.Annotations[annotations.StaticIPKey]; exists && currentIPName == managedStaticIPName {
currentIP, _ := l.cloud.GetGlobalAddress(managedStaticIPName)
if currentIP != nil {
klog.V(3).Infof("Ingress managed static IP %s(%s) exists, using it to create forwarding rule %s", currentIPName, currentIP.Address, name)
ip = currentIP.Address
}
}
}
klog.V(3).Infof("Creating forwarding rule for proxy %q and ip %v:%v", proxyLink, ip, portRange)
description, err := l.description()
if err != nil {
Expand Down