Skip to content

Commit

Permalink
Merge pull request #1245 from spencerhance/cp-1227-release-1-10
Browse files Browse the repository at this point in the history
Cherry-pick #1227 [Update ensureRedirectUrlMap() logic] into release-1.10
  • Loading branch information
k8s-ci-robot committed Sep 1, 2020
2 parents 2331ffa + f06e228 commit 0453ab5
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions pkg/loadbalancers/url_maps.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

apiv1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/ingress-gce/pkg/annotations"
"k8s.io/ingress-gce/pkg/composite"
"k8s.io/ingress-gce/pkg/events"
"k8s.io/ingress-gce/pkg/flags"
Expand Down Expand Up @@ -91,20 +92,29 @@ func (l *L7) ensureRedirectURLMap() error {
name, namerSupported := l.namer.RedirectUrlMap()
expectedMap := t.ToRedirectUrlMap(env, l.Versions().UrlMap)

key, err := l.CreateKey(name)
if err != nil {
return err
// Cannot enable for internal ingress
if expectedMap != nil && isL7ILB {
return fmt.Errorf("error: cannot enable HTTPS Redirects with L7 ILB")
}

// TODO(shance): Remove this get unless the ingress status has the redirectUrlMap
currentMap, err := composite.GetUrlMap(l.cloud, key, l.Versions().UrlMap)
if utils.IgnoreHTTPNotFound(err) != nil {
// Cannot enable on older naming schemes
if !namerSupported {
if expectedMap != nil {
return fmt.Errorf("error: cannot enable HTTPS Redirects with the V1 Ingress naming scheme. Please recreate your ingress to use the newest naming scheme.")
}
return nil
}

key, err := l.CreateKey(name)
if err != nil {
return err
}

// Do not expect to have a RedirectUrlMap
if expectedMap == nil {
if currentMap == nil {
// Check if we need to GC
status, ok := l.ingress.Annotations[annotations.RedirectUrlMapKey]
if !ok || status == "" {
return nil
} else {
if err := composite.DeleteUrlMap(l.cloud, key, l.Versions().UrlMap); err != nil {
Expand All @@ -114,13 +124,9 @@ func (l *L7) ensureRedirectURLMap() error {
return nil
}

// Cannot enable for internal ingress
if isL7ILB {
return fmt.Errorf("error: cannot enable HTTPS Redirects with L7 ILB")
}

if !namerSupported {
return fmt.Errorf("error: cannot enable HTTPS Redirects with the V1 Ingress naming scheme. Please recreate your ingress to use the newest naming scheme.")
currentMap, err := composite.GetUrlMap(l.cloud, key, l.Versions().UrlMap)
if utils.IgnoreHTTPNotFound(err) != nil {
return err
}

if currentMap == nil {
Expand All @@ -135,7 +141,6 @@ func (l *L7) ensureRedirectURLMap() error {
}

l.redirectUm = expectedMap

return nil
}

Expand Down

0 comments on commit 0453ab5

Please sign in to comment.