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 <github.gkarthiks@gmail.com>

chore: add new line at end of the file

Signed-off-by: gkarthiks <github.gkarthiks@gmail.com>

fix: remove unused mod from vendor modules file

Signed-off-by: gkarthiks <github.gkarthiks@gmail.com>
This commit is contained in:
gkarthiks 2021-07-20 18:02:35 +05:30
parent 59c0523bca
commit 019e8f71b6
3 changed files with 14 additions and 4 deletions

View File

@ -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
}

1
go.mod
View File

@ -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

1
vendor/modules.txt vendored
View File

@ -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