Skip to content
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

Move error variables out of utils package #5356

Closed
killianmuldoon opened this issue Sep 29, 2021 · 15 comments
Closed

Move error variables out of utils package #5356

killianmuldoon opened this issue Sep 29, 2021 · 15 comments
Labels
kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale.

Comments

@killianmuldoon
Copy link
Contributor

killianmuldoon commented Sep 29, 2021

Detailed Description

There are a few errors defined in the top level utils package that are better placed in the top level errors package. These errors should be deprecated and recreated in the errors package. The util errors should then be removed in a coming release.

Examples:

ErrNoCluster = fmt.Errorf("no %q label present", clusterv1.ClusterLabelName)

ErrUnstructuredFieldNotFound = fmt.Errorf("field not found")

/kind cleanup

@killianmuldoon
Copy link
Contributor Author

/kind cleanup

@k8s-ci-robot k8s-ci-robot added the kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. label Sep 29, 2021
@vincepri
Copy link
Member

These seems only used or returned within that package, should we consider instead moving the functions using them to a different package instead?

@vincepri
Copy link
Member

/milestone Next

@k8s-ci-robot k8s-ci-robot added this to the Next milestone Sep 30, 2021
@killianmuldoon
Copy link
Contributor Author

These do seem to be used - ErrNoCluster in kubeadmconfig_controller.go and ErrUnstructuredFieldNotFound in cluster_controller_phases.go. If they were just used in package I'd say keep them, but it looks like they're being used as importable error messages which says to me they belong in errors.

@vincepri
Copy link
Member

Are they used for error checking outside of util?

@killianmuldoon
Copy link
Contributor Author

killianmuldoon commented Sep 30, 2021

if errors.Cause(err) == util.ErrNoCluster {

if err := util.UnstructuredUnmarshalField(infraConfig, &cluster.Status.FailureDomains, "status", "failureDomains"); err != nil && err != util.ErrUnstructuredFieldNotFound {

@DiptoChakrabarty
Copy link
Member

hey can I try this issue out , I am new here , this is my approach
move these errors in util package

cluster-api/util/util.go

Lines 56 to 62 in 573f005

// ErrNoCluster is returned when the cluster
// label could not be found on the object passed in.
ErrNoCluster = fmt.Errorf("no %q label present", clusterv1.ClusterLabelName)
// ErrUnstructuredFieldNotFound determines that a field
// in an unstructured object could not be found.
ErrUnstructuredFieldNotFound = fmt.Errorf("field not found")

to the error package here -> https://github.com/kubernetes-sigs/cluster-api/blob/58905fb5140a7844c3e24aa70d255fb8f9d0c491/errors/consts.go

then replace the util.ErrNoCluster and similar errors with the errors package ones

does this sound appropriate

@killianmuldoon
Copy link
Contributor Author

killianmuldoon commented Oct 12, 2021

@DiptoChakrabarty That sounds right - it's important to not remove the original variables from the utils package and instead add a deprecation message so we can remove the errors with the next breaking changes to Cluster API. So:

  1. Add a deprecation message to the errors we'd like to move. (example of an existing deprecation message:

    // Deprecated: This field has no function and is going to be removed in a next release.

  2. Add new errors (with an appropriate error type) to the errors package.

  3. Replace the errors as used in the rest of the code with the new version from the errors package.

@DiptoChakrabarty
Copy link
Member

DiptoChakrabarty commented Oct 12, 2021

Hey I have done just like that with a bit of changes since importing the clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" causes an import cycle

and I noticed that the error names are defined here https://github.com/kubernetes-sigs/cluster-api/blob/main/errors/consts.go

and the errors are configured here https://github.com/kubernetes-sigs/cluster-api/blob/main/errors/clusters.go so I made particular functions for these two util errors

@killianmuldoon
Copy link
Contributor Author

#5419 (comment)

There's a couple of problems with this approach as it looks out of the scope of the current errors package. Currently the errors package covers mostly status conditions whereas these are closer to client errors.

Should we expand the overall usage of the errors package to include client errors like ClusterNotFound? These are commonly used and compared errors across the code base, but there's unwanted constraints we could possibly introduce by trying to implement them all in one format.

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jan 31, 2022
@vincepri
Copy link
Member

@killianmuldoon @DiptoChakrabarty Is it ok to close this issue and the related PR based on #5419 (comment)?

@killianmuldoon
Copy link
Contributor Author

I'm fine with that given there's no agreed way to move those errors right now.

@vincepri
Copy link
Member

👍
/close

@k8s-ci-robot
Copy link
Contributor

@vincepri: Closing this issue.

In response to this:

👍
/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants