From 019e8f71b6a83eb548148f42a4a6ca4ff54c58e2 Mon Sep 17 00:00:00 2001 From: gkarthiks Date: Tue, 20 Jul 2021 18:02:35 +0530 Subject: [PATCH] refactor: normalizing URL string locally and move out from purell package The purell package at github.com/PuerkitoBio/purell is no longer maintained and in k/k repo under kubeadm package its been used for normalizing the URL. This commit removes the dependency on this package and creates a local function for normalizing the URL within the preflight package under cmd/kubeadm. Signed-off-by: gkarthiks chore: add new line at end of the file Signed-off-by: gkarthiks fix: remove unused mod from vendor modules file Signed-off-by: gkarthiks --- cmd/kubeadm/app/preflight/checks.go | 16 ++++++++++++++-- go.mod | 1 - vendor/modules.txt | 1 - 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/cmd/kubeadm/app/preflight/checks.go b/cmd/kubeadm/app/preflight/checks.go index e9fbfb721e7..b8bf15e747f 100644 --- a/cmd/kubeadm/app/preflight/checks.go +++ b/cmd/kubeadm/app/preflight/checks.go @@ -51,7 +51,6 @@ import ( utilsexec "k8s.io/utils/exec" utilsnet "k8s.io/utils/net" - "github.com/PuerkitoBio/purell" "github.com/pkg/errors" ) @@ -714,7 +713,7 @@ func (evc ExternalEtcdVersionCheck) Check() (warnings, errorList []error) { resp := etcdVersionResponse{} var err error versionURL := fmt.Sprintf("%s/%s", endpoint, "version") - if tmpVersionURL, err := purell.NormalizeURLString(versionURL, purell.FlagRemoveDuplicateSlashes); err != nil { + if tmpVersionURL, err := normalizeURLString(versionURL); err != nil { errorList = append(errorList, errors.Wrapf(err, "failed to normalize external etcd version url %s", versionURL)) continue } else { @@ -1119,3 +1118,16 @@ func setHasItemOrAll(s sets.String, item string) bool { } return false } + +// normalizeURLString returns the normalized string, or an error if it can't be parsed into an URL object. +// It takes an URL string as input. +func normalizeURLString(s string) (string, error) { + u, err := url.Parse(s) + if err != nil { + return "", err + } + if len(u.Path) > 0 { + u.Path = strings.ReplaceAll(u.Path, "//", "/") + } + return u.String(), nil +} diff --git a/go.mod b/go.mod index 61ec527819c..9455da32070 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,6 @@ require ( github.com/JeffAshton/win_pdh v0.0.0-20161109143554-76bb4ee9f0ab github.com/Microsoft/go-winio v0.4.15 github.com/Microsoft/hcsshim v0.8.10-0.20200715222032-5eafd1556990 - github.com/PuerkitoBio/purell v1.1.1 github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e github.com/auth0/go-jwt-middleware v1.0.1 // indirect github.com/aws/aws-sdk-go v1.38.49 diff --git a/vendor/modules.txt b/vendor/modules.txt index ad8d5b4699f..c4f3259f19e 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -81,7 +81,6 @@ github.com/Microsoft/hcsshim/osversion # github.com/NYTimes/gziphandler v1.1.1 => github.com/NYTimes/gziphandler v1.1.1 github.com/NYTimes/gziphandler # github.com/PuerkitoBio/purell v1.1.1 => github.com/PuerkitoBio/purell v1.1.1 -## explicit github.com/PuerkitoBio/purell # github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 => github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 github.com/PuerkitoBio/urlesc