-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Retry to download maxmind DB if it fails #7242
Changes from 1 commit
1698bb8
9a5a1bd
bffb372
6094cc8
cbfc5ef
da2fb28
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 | ||
---|---|---|---|---|
|
@@ -19,21 +19,23 @@ package main | |||
import ( | ||||
"flag" | ||||
"fmt" | ||||
"net" | ||||
"net/url" | ||||
"os" | ||||
"syscall" | ||||
"time" | ||||
|
||||
"github.com/spf13/pflag" | ||||
|
||||
apiv1 "k8s.io/api/core/v1" | ||||
"k8s.io/klog/v2" | ||||
|
||||
"k8s.io/apimachinery/pkg/util/wait" | ||||
"k8s.io/ingress-nginx/internal/ingress/annotations/class" | ||||
"k8s.io/ingress-nginx/internal/ingress/annotations/parser" | ||||
"k8s.io/ingress-nginx/internal/ingress/controller" | ||||
ngx_config "k8s.io/ingress-nginx/internal/ingress/controller/config" | ||||
"k8s.io/ingress-nginx/internal/ingress/status" | ||||
ing_net "k8s.io/ingress-nginx/internal/net" | ||||
"k8s.io/ingress-nginx/internal/nginx" | ||||
klog "k8s.io/klog/v2" | ||||
) | ||||
|
||||
func parseFlags() (bool, *controller.Configuration, error) { | ||||
|
@@ -179,6 +181,7 @@ Takes the form "<host>:port". If not provided, no admission controller is starte | |||
flags.StringVar(&nginx.MaxmindLicenseKey, "maxmind-license-key", "", `Maxmind license key to download GeoLite2 Databases. | ||||
https://blog.maxmind.com/2019/12/18/significant-changes-to-accessing-and-using-geolite2-databases`) | ||||
flags.StringVar(&nginx.MaxmindEditionIDs, "maxmind-edition-ids", "GeoLite2-City,GeoLite2-ASN", `Maxmind edition ids to download GeoLite2 Databases.`) | ||||
flags.DurationVar(&nginx.MaxmindRetriesTimeout, "maxmind-retries-timeout", time.Second*0, "Maxmind downloading delay between 1st and 2nd attempt (5 attempts in total), 0s - do not retry to download if something went wrong.") | ||||
|
||||
flag.Set("logtostderr", "true") | ||||
|
||||
|
@@ -303,16 +306,51 @@ https://blog.maxmind.com/2019/12/18/significant-changes-to-accessing-and-using-g | |||
config.RootCAFile = *rootCAFile | ||||
} | ||||
|
||||
var err error | ||||
if (nginx.MaxmindLicenseKey != "" || nginx.MaxmindMirror != "") && nginx.MaxmindEditionIDs != "" { | ||||
if err := nginx.ValidateGeoLite2DBEditions(); err != nil { | ||||
if err = nginx.ValidateGeoLite2DBEditions(); err != nil { | ||||
return false, nil, err | ||||
} | ||||
klog.InfoS("downloading maxmind GeoIP2 databases") | ||||
if err := nginx.DownloadGeoLite2DB(); err != nil { | ||||
klog.InfoS("trying to download maxmind GeoIP2 databases...") | ||||
defaultRetry := wait.Backoff{ | ||||
Steps: 5, | ||||
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. Suggestion: Let's make this configurable as well? 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, see arg |
||||
Duration: nginx.MaxmindRetriesTimeout, | ||||
Factor: 1.5, | ||||
Jitter: 0.1, | ||||
} | ||||
if nginx.MaxmindRetriesTimeout == time.Duration(0) { | ||||
defaultRetry.Steps = 1 | ||||
} | ||||
|
||||
var lastErr error | ||||
retries := 0 | ||||
|
||||
err = wait.ExponentialBackoff(defaultRetry, func() (bool, error) { | ||||
err := nginx.DownloadGeoLite2DB() | ||||
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 if we move all of this to DownloadGeoLite2DB instead of adding to this main function in flags. ingress-nginx/internal/nginx/maxmind.go Line 63 in b1c8e30
Also, I would like to keep here simple, if possible. I do not opose myself of changing DownloadGeoLite2DB signature to pass the delay and retries as arguments, but infact we should deal an error as an error and not rely too much on the syscall in this case :) If we have an error and the error happens here, we should just return to the caller function an error downloading the database, and parse this on the inner functions IMO 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. Moved all the download retry logic into DownloadGeoLite2DB func |
||||
lastErr = err | ||||
if err == nil { | ||||
return true, nil | ||||
} | ||||
|
||||
if e, ok := err.(*url.Error); ok { | ||||
if e, ok := e.Err.(*net.OpError); ok { | ||||
if e, ok := e.Err.(*os.SyscallError); ok { | ||||
if e.Err == syscall.ECONNREFUSED { | ||||
retries++ | ||||
klog.InfoS("download failed on attempt " + fmt.Sprint(retries)) | ||||
return false, nil | ||||
} | ||||
} | ||||
} | ||||
} | ||||
return true, nil | ||||
}) | ||||
err = lastErr | ||||
if err != nil { | ||||
klog.ErrorS(err, "unexpected error downloading GeoIP2 database") | ||||
} | ||||
config.MaxmindEditionFiles = nginx.MaxmindEditionFiles | ||||
} | ||||
|
||||
return false, config, nil | ||||
return false, config, 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.
Do we need this change? :)
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.
Reverted