Retry to download maxmind DB if it fails (#7242)
* Retry to download maxmind DB if it fails. Signed-off-by: Sergey Shakuto <sshakuto@infoblox.com> * Add retries count arg, move retry logic into DownloadGeoLite2DB function Signed-off-by: Sergey Shakuto <sshakuto@infoblox.com> * Reorder parameters in DownloadGeoLite2DB Signed-off-by: Sergey Shakuto <sshakuto@infoblox.com> * Remove hardcoded value Signed-off-by: Sergey Shakuto <sshakuto@infoblox.com>
This commit is contained in:
parent
1cfbacc237
commit
b0ae678ce6
6 changed files with 96 additions and 35 deletions
|
|
@ -23,10 +23,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
|
||||
apiv1 "k8s.io/api/core/v1"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
"k8s.io/ingress-nginx/internal/ingress/annotations/class"
|
||||
"k8s.io/ingress-nginx/internal/ingress/annotations/parser"
|
||||
"k8s.io/ingress-nginx/internal/ingress/controller"
|
||||
|
|
@ -34,6 +31,7 @@ import (
|
|||
"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) {
|
||||
|
|
@ -182,6 +180,8 @@ 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.IntVar(&nginx.MaxmindRetriesCount, "maxmind-retries-count", 1, "Number of attempts to download the GeoIP DB.")
|
||||
flags.DurationVar(&nginx.MaxmindRetriesTimeout, "maxmind-retries-timeout", time.Second*0, "Maxmind downloading delay between 1st and 2nd attempt, 0s - do not retry to download if something went wrong.")
|
||||
|
||||
flag.Set("logtostderr", "true")
|
||||
|
||||
|
|
@ -307,16 +307,17 @@ 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 {
|
||||
if err = nginx.DownloadGeoLite2DB(nginx.MaxmindRetriesCount, nginx.MaxmindRetriesTimeout); err != nil {
|
||||
klog.ErrorS(err, "unexpected error downloading GeoIP2 database")
|
||||
}
|
||||
config.MaxmindEditionFiles = nginx.MaxmindEditionFiles
|
||||
}
|
||||
|
||||
return false, config, nil
|
||||
return false, config, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -105,3 +105,16 @@ func TestMaxmindMirror(t *testing.T) {
|
|||
t.Fatalf("Expected an error parsing flags but none returned")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMaxmindRetryDownload(t *testing.T) {
|
||||
resetForTesting(func() { t.Fatal("Parsing failed") })
|
||||
|
||||
oldArgs := os.Args
|
||||
defer func() { os.Args = oldArgs }()
|
||||
os.Args = []string{"cmd", "--publish-service", "namespace/test", "--http-port", "0", "--https-port", "0", "--maxmind-mirror", "http://127.0.0.1", "--maxmind-license-key", "0000000", "--maxmind-edition-ids", "GeoLite2-City", "--maxmind-retries-timeout", "1s", "--maxmind-retries-count", "3"}
|
||||
|
||||
_, _, err := parseFlags()
|
||||
if err == nil {
|
||||
t.Fatalf("Expected an error parsing flags but none returned")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue