-
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
Implement support for HTTPS Redirects #1206
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ import ( | |
"k8s.io/apimachinery/pkg/util/sets" | ||
"k8s.io/ingress-gce/pkg/composite" | ||
"k8s.io/ingress-gce/pkg/events" | ||
"k8s.io/ingress-gce/pkg/flags" | ||
"k8s.io/ingress-gce/pkg/translator" | ||
"k8s.io/ingress-gce/pkg/utils" | ||
"k8s.io/klog" | ||
|
@@ -80,6 +81,74 @@ func (l *L7) ensureComputeURLMap() error { | |
return nil | ||
} | ||
|
||
func (l *L7) ensureRedirectURLMap() error { | ||
feConfig := l.runtimeInfo.FrontendConfig | ||
isL7ILB := flags.F.EnableL7Ilb && utils.IsGCEL7ILBIngress(&l.ingress) | ||
|
||
t := translator.NewTranslator(isL7ILB, l.namer) | ||
env := &translator.Env{FrontendConfig: feConfig, Ing: &l.ingress} | ||
|
||
name, namerSupported := l.namer.RedirectUrlMap() | ||
expectedMap := t.ToRedirectUrlMap(env, l.Versions().UrlMap) | ||
|
||
key, err := l.CreateKey(name) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// TODO(shance): Remove this get unless the ingress status has the redirectUrlMap | ||
currentMap, err := composite.GetUrlMap(l.cloud, key, l.Versions().UrlMap) | ||
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. Might worth avoiding this GET call every time an irrelevant ingress was synced. One idea is to check if the the ingress status annotation has the redirectUrlMap 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. Done |
||
if utils.IgnoreHTTPNotFound(err) != nil { | ||
return err | ||
} | ||
|
||
// Do not expect to have a RedirectUrlMap | ||
if expectedMap == nil { | ||
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. add a comment here to say "do not expect to have a RedirectUrlMap" 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. Done |
||
if currentMap == nil { | ||
return nil | ||
} else { | ||
if err := composite.DeleteUrlMap(l.cloud, key, l.Versions().UrlMap); err != nil { | ||
return err | ||
} | ||
} | ||
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.") | ||
} | ||
|
||
if currentMap == nil { | ||
if err := composite.CreateUrlMap(l.cloud, key, expectedMap); err != nil { | ||
return err | ||
} | ||
} else if compareRedirectUrlMaps(expectedMap, currentMap) { | ||
expectedMap.Fingerprint = currentMap.Fingerprint | ||
if err := composite.UpdateUrlMap(l.cloud, key, expectedMap); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
l.redirectUm = expectedMap | ||
|
||
return nil | ||
} | ||
|
||
// compareRedirectUrlMaps() compares the fields specified on the url map by the frontendconfig and returns true | ||
// if there's a diff, false otherwise | ||
func compareRedirectUrlMaps(a, b *composite.UrlMap) bool { | ||
if a.DefaultUrlRedirect.HttpsRedirect != b.DefaultUrlRedirect.HttpsRedirect || | ||
a.DefaultUrlRedirect.RedirectResponseCode != b.DefaultUrlRedirect.RedirectResponseCode { | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
// getBackendNames returns the names of backends in this L7 urlmap. | ||
func getBackendNames(computeURLMap *composite.UrlMap) ([]string, error) { | ||
beNames := sets.NewString() | ||
|
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.
Why didn't this code written as follow with less branches?