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

🐛 Use ptr instead of own implementation #10276

Merged
merged 2 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions errors/pointer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
limitations under the License.
*/

// Deprecated: errors returns pointer of type received as input, but it can be satisfied by using ptr package.

Check failure on line 17 in errors/pointer.go

View workflow job for this annotation

GitHub Actions / lint

package-comments: package comment should be of the form "Package errors ..." (revive)

Check warning on line 17 in errors/pointer.go

View workflow job for this annotation

GitHub Actions / lint

package-comments: package comment should be of the form "Package errors ..." (revive)
// It keeps these functions for backward compatibility.
//
// cluster-api no longer uses this package, and it will be removed in the future, so please use the ptr package instead.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Deprecated: errors returns pointer of type received as input, but it can be satisfied by using ptr package.
// It keeps these functions for backward compatibility.
//
// cluster-api no longer uses this package, and it will be removed in the future, so please use the ptr package instead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't deprecate the package as there are other functions in it which are not deprecated.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I narrowed the deprecated scope, thanks.

package errors

// MachineStatusErrorPtr converts a MachineStatusError to a pointer.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a deprecation message to each of the individual functions.

The usual form is:

// Deprecated: This function is deprecated and will be removed in an upcoming release of Cluster API.

Expand Down
2 changes: 1 addition & 1 deletion exp/internal/controllers/machinepool_controller_phases.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/controllers/external"
capierrors "sigs.k8s.io/cluster-api/errors"

Check failure on line 41 in exp/internal/controllers/machinepool_controller_phases.go

View workflow job for this annotation

GitHub Actions / lint

SA1019: "sigs.k8s.io/cluster-api/errors" is deprecated: errors returns pointer of type received as input, but it can be satisfied by using ptr package. It keeps these functions for backward compatibility. (staticcheck)
expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1"
utilexp "sigs.k8s.io/cluster-api/exp/util"
"sigs.k8s.io/cluster-api/internal/util/ssa"
Expand Down Expand Up @@ -252,7 +252,7 @@
if mp.Status.InfrastructureReady {
// Infra object went missing after the machine pool was up and running
log.Error(err, "infrastructure reference has been deleted after being ready, setting failure state")
mp.Status.FailureReason = capierrors.MachinePoolStatusErrorPtr(capierrors.InvalidConfigurationMachinePoolError)
mp.Status.FailureReason = ptr.To(capierrors.InvalidConfigurationMachinePoolError)
mp.Status.FailureMessage = ptr.To(fmt.Sprintf("MachinePool infrastructure resource %v with name %q has been deleted after being ready",
mp.Spec.Template.Spec.InfrastructureRef.GroupVersionKind(), mp.Spec.Template.Spec.InfrastructureRef.Name))
}
Expand Down
2 changes: 1 addition & 1 deletion internal/controllers/machine/machine_controller_phases.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/controllers/external"
capierrors "sigs.k8s.io/cluster-api/errors"

Check failure on line 38 in internal/controllers/machine/machine_controller_phases.go

View workflow job for this annotation

GitHub Actions / lint

SA1019: "sigs.k8s.io/cluster-api/errors" is deprecated: errors returns pointer of type received as input, but it can be satisfied by using ptr package. It keeps these functions for backward compatibility. (staticcheck)
"sigs.k8s.io/cluster-api/util"
"sigs.k8s.io/cluster-api/util/annotations"
"sigs.k8s.io/cluster-api/util/conditions"
Expand Down Expand Up @@ -254,7 +254,7 @@
// Infra object went missing after the machine was up and running
if m.Status.InfrastructureReady {
log.Error(err, "Machine infrastructure reference has been deleted after being ready, setting failure state")
m.Status.FailureReason = capierrors.MachineStatusErrorPtr(capierrors.InvalidConfigurationMachineError)
m.Status.FailureReason = ptr.To(capierrors.InvalidConfigurationMachineError)
m.Status.FailureMessage = ptr.To(fmt.Sprintf("Machine infrastructure resource %v with name %q has been deleted after being ready",
m.Spec.InfrastructureRef.GroupVersionKind(), m.Spec.InfrastructureRef.Name))
return ctrl.Result{}, errors.Errorf("could not find %v %q for Machine %q in namespace %q, requeuing", m.Spec.InfrastructureRef.GroupVersionKind().String(), m.Spec.InfrastructureRef.Name, m.Name, m.Namespace)
Expand Down
Loading