-
Notifications
You must be signed in to change notification settings - Fork 38.6k
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
[kubeadm/app/]switch to github.com/pkg/errors #70271
Conversation
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.
/lgtm
/kind cleanup
@yuexiao-wang thanks, might have been better to change all kubeadm packages in a single PR.
/ok-to-test |
/test pull-kubernetes-kubemark-e2e-gce-big |
/test pull-kubernetes-e2e-gce-100-performance |
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.
@yuexiao-wang thanks!
Only one nit and then ok for approval
cmd/kubeadm/app/cmd/upgrade/apply.go
Outdated
@@ -250,13 +251,13 @@ func EnforceVersionPolicies(flags *applyFlags, versionGetter upgrade.VersionGett | |||
if versionSkewErrs != nil { | |||
|
|||
if len(versionSkewErrs.Mandatory) > 0 { | |||
return fmt.Errorf("The --version argument is invalid due to these fatal errors:\n\n%v\nPlease fix the misalignments highlighted above and try upgrading again", kubeadmutil.FormatErrMsg(versionSkewErrs.Mandatory)) | |||
return fmt.Errorf("the --version argument is invalid due to these fatal errors:\n\n%v\nPlease fix the misalignments highlighted above and try upgrading again", kubeadmutil.FormatErrMsg(versionSkewErrs.Mandatory)) |
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.
Errors.new?
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.
Got it
cmd/kubeadm/app/cmd/upgrade/apply.go
Outdated
} | ||
|
||
if len(versionSkewErrs.Skippable) > 0 { | ||
// Return the error if the user hasn't specified the --force flag | ||
if !flags.force { | ||
return fmt.Errorf("The --version argument is invalid due to these errors:\n\n%v\nCan be bypassed if you pass the --force flag", kubeadmutil.FormatErrMsg(versionSkewErrs.Skippable)) | ||
return fmt.Errorf("the --version argument is invalid due to these errors:\n\n%v\nCan be bypassed if you pass the --force flag", kubeadmutil.FormatErrMsg(versionSkewErrs.Skippable)) |
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.
errors.Errorf
(Same applies to all fmt.Errorf remaining in the packages in scope)
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.
Thanks. Got it and I need to amend these applications to my PR.
There are so many fmt.Errorf in kubeadm packages. so I only switch to errors.Wrap and error.New in my PR.
@neolit123 Thanks for your review. |
@yuexiao-wang if you keep fixednthe number of packages in scope and change only the fmt.Errorf statement the size of the PR will remain acceptable, but I case thinks goes out of control you can always split the PR in two |
@fabriziopandini I find about 400 occurrences about fmt.Errorf in the rest of kubeadm package.
|
@yuexiao-wang
|
there is also https://godoc.org/github.com/pkg/errors#Wrapf if needed in places. |
@neolit123 i am puzzled about errors.Errorf and errors.Wrapf and do you any suggestion? thanks |
@fabriziopandini thanks. i will try it |
can be changed to:
so we should use Wrapf() too if needed.
does that make sense? |
9f65b1d
to
ad5efbd
Compare
CI will be green. |
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.
@yuexiao-wang thanks a lot for this big cleanup! awesome.
added some minor comments.
@kubernetes/sig-cluster-lifecycle-pr-reviews
ideally, we need more reviewers on this PR.
@@ -52,7 +54,7 @@ func CreatePKIAssets(cfg *kubeadmapi.InitConfiguration) error { | |||
} | |||
|
|||
if err := certTree.CreateTree(cfg); err != nil { | |||
return fmt.Errorf("Error creating PKI assets: %v", err) | |||
return errors.Wrap(err, "Error creating PKI assets") |
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.
please make this error string start with lowecase "error" instead of "Error"
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.
thanks
I will fix it and check all the cleanup in this PR again
@@ -38,12 +39,12 @@ import ( | |||
func NewCertificateAuthority(config *certutil.Config) (*x509.Certificate, *rsa.PrivateKey, error) { | |||
key, err := certutil.NewPrivateKey() | |||
if err != nil { | |||
return nil, nil, fmt.Errorf("unable to create private key [%v]", err) | |||
return nil, nil, errors.Wrap(err, "unable to create private key [%v]") |
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.
please remove [%v]
[1]
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.
got it
} | ||
|
||
cert, err := certutil.NewSelfSignedCACert(*config, key) | ||
if err != nil { | ||
return nil, nil, fmt.Errorf("unable to create self-signed certificate [%v]", err) | ||
return nil, nil, errors.Wrap(err, "unable to create self-signed certificate [%v]") |
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.
[1]
@@ -53,12 +54,12 @@ func NewCertificateAuthority(config *certutil.Config) (*x509.Certificate, *rsa.P | |||
func NewCertAndKey(caCert *x509.Certificate, caKey *rsa.PrivateKey, config *certutil.Config) (*x509.Certificate, *rsa.PrivateKey, error) { | |||
key, err := certutil.NewPrivateKey() | |||
if err != nil { | |||
return nil, nil, fmt.Errorf("unable to create private key [%v]", err) | |||
return nil, nil, errors.Wrap(err, "unable to create private key [%v]") |
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.
[1]
} | ||
|
||
cert, err := certutil.NewSignedCert(*config, key, caCert, caKey) | ||
if err != nil { | ||
return nil, nil, fmt.Errorf("unable to sign certificate [%v]", err) | ||
return nil, nil, errors.Wrap(err, "unable to sign certificate [%v]") |
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.
[1]
} | ||
|
||
certificatePath := pathForCert(pkiPath, name) | ||
if err := certutil.WriteCert(certificatePath, certutil.EncodeCertPEM(cert)); err != nil { | ||
return fmt.Errorf("unable to write certificate to file %q: [%v]", certificatePath, err) | ||
return errors.Errorf(certificatePath, err, "unable to write certificate to file %q: [%v]") |
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.
should be:
errors.Wrapf(err, "unable to write certificate to file %q", certificatePath)
also optionally you can change %q to %s if you want this to be consistent with the errors in the same file.
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.
got it.
@@ -52,32 +53,32 @@ func EnforceVersionPolicies(versionGetter VersionGetter, newK8sVersionStr string | |||
clusterVersionStr, clusterVersion, err := versionGetter.ClusterVersion() | |||
if err != nil { | |||
// This case can't be forced: kubeadm has to be able to lookup cluster version for upgrades to work | |||
skewErrors.Mandatory = append(skewErrors.Mandatory, fmt.Errorf("Unable to fetch cluster version: %v", err)) | |||
skewErrors.Mandatory = append(skewErrors.Mandatory, errors.Wrap(err, "Unable to fetch cluster version: %v")) |
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.
please remove : %v
at the end.
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.
ok
cmd/kubeadm/app/util/marshal.go
Outdated
continue | ||
} | ||
knownKinds[typeMetaInfo.Kind] = true | ||
|
||
// Build a GroupVersionKind object from the deserialized TypeMeta object | ||
gv, err := schema.ParseGroupVersion(typeMetaInfo.APIVersion) | ||
if err != nil { | ||
errs = append(errs, fmt.Errorf("unable to parse apiVersion: %v", err)) | ||
errs = append(errs, pkgerrors.Wrap(err, "unable to parse apiVersion: %v")) |
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.
release remove : %v
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.
got it
@@ -218,14 +220,14 @@ func (k *KernelValidator) getKernelConfigReader() (io.Reader, error) { | |||
// config module and check again. | |||
output, err := exec.Command(modprobeCmd, configsModule).CombinedOutput() | |||
if err != nil { | |||
return nil, fmt.Errorf("unable to load kernel module %q: output - %q, err - %v", | |||
configsModule, output, err) | |||
return nil, pkgerrors.Wrapf(err, "unable to load kernel module %q: output - %q, 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.
lets change the end to output: %q, 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.
i want to change it to unable to load kernel module: %q, output: %q, err
895f95e
to
1a7536f
Compare
/retest |
I update the PR and split to two PR, which is convenient to review |
1a7536f
to
a2fc632
Compare
@yuexiao-wang if this is ready I will try to get this merged today, otherwise please let me known |
@fabriziopandini I think it will be ready after CI is green. |
826e0ae
to
c0a9b4d
Compare
Signed-off-by: yuexiao-wang <wang.yuexiao@zte.com.cn>
@yuexiao-wang if you need help feel free to contact me on slack. |
@fabriziopandini Thanks. I have run hack/verify-gofmt.sh and hack/update-gofmt.sh before submit my PR everytime. There are no errors happen in local, which wrong args is exist in code, but it only failed in master. I don't know why |
@yuexiao-wang In that case I suggest to rebase your PR |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: fabriziopandini, yuexiao-wang The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Signed-off-by: yuexiao-wang wang.yuexiao@zte.com.cn
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
switch to github.com/pkg/errors the packages as follows:
cmd/kubeadm/app/cmd/upgrade
cmd/kubeadm/app/cmd/util
cmd/kubeadm/app/discovery
cmd/kubeadm/app/discovery/file
cmd/kubeadm/app/phases/addons/dns
cmd/kubeadm/app/phases/addons/proxy
cmd/kubeadm/app/phases/bootstraptoken/clusterinfo/
cmd/kubeadm/app/phases/etcd
Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when PR gets merged):Fixes # Fixes # kubernetes/kubeadm#1183
Special notes for your reviewer:
@fabriziopandini @neolit123
Does this PR introduce a user-facing change?: