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

Standardize more package import aliases #2529

Merged
merged 1 commit into from
Aug 4, 2022

Conversation

mboersma
Copy link
Contributor

@mboersma mboersma commented Aug 2, 2022

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

Standardizes several popular import aliases by adding them to the importas linter configuration. This is an area of code where creativity is ultimately unhelpful. The CAPI sections were copied from CAPI's golangci config.

Which issue(s) this PR fixes:

Refs #2289

Special notes for your reviewer:

TODOs:

  • squashed commits
  • includes documentation
  • adds unit tests

Release note:

NONE

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Aug 2, 2022
@mboersma mboersma requested a review from invidian August 2, 2022 19:49
@@ -24,7 +24,7 @@ import (
"github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2021-05-01/containerservice"
"github.com/google/go-cmp/cmp"
"github.com/pkg/errors"
infrav1alpha4 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was a misleading alias.

Copy link
Member

@invidian invidian left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @mboersma! I left some thoughts in the comments.

alias: clusterv1
# CAPI exp
- pkg: sigs.k8s.io/cluster-api/exp/api/v1alpha3
alias: expv1alpha3
Copy link
Member

Choose a reason for hiding this comment

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

Maybe it should be expclusterv1alpha3 to be consistent with the above?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The CAPI rules for importas were copied from CAPI's golangci-lint configuration. I think we should just use them as-is to make it easier to move between codebases. I notice that's what CAPA did as well.

Copy link
Member

Choose a reason for hiding this comment

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

Well, some say you should always question things and there is always room for the improvement... 😄 But perhaps less optimal consistency is better than better inconsistency, so I guess that's OK. Thanks for explaining! Feel free to mark as resolved.

- pkg: sigs.k8s.io/cluster-api-provider-azure/exp/api/v1alpha3
alias: infrav1alpha3exp
- pkg: sigs.k8s.io/cluster-api-provider-azure/exp/api/v1alpha4
alias: infrav1alpha4exp
Copy link
Member

Choose a reason for hiding this comment

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

It's expv1alpha4 with exp prefix, but infrav1alpha4exp with exp suffix, maybe we can make it more consistent?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we could--I chose the infrav1exp pattern for CAPZ imports because it was already the most-used, so that minimized the churn in the codebase. But infraexpv1 and infraexpv1alpha4 are arguably more consistent with CAPI's imports.

@@ -72,6 +72,34 @@ linters-settings:
# Controller Runtime
- pkg: sigs.k8s.io/controller-runtime
alias: ctrl
# CAPI
- pkg: sigs.k8s.io/cluster-api/api/v1alpha3
Copy link
Member

Choose a reason for hiding this comment

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

I wonder, if source file imports only single package named v1alpha3, will the linter still require an alias?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will, because we have no-unaliased: true set in .golangci.yml.

Copy link
Member

Choose a reason for hiding this comment

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

All good if that's deliberate. I think I like it this way, similar to , ending the last entry in the lists. It won't make you change unrelated stuff when you add new import. Feel free to mark as resolved.

@mboersma
Copy link
Contributor Author

mboersma commented Aug 2, 2022

@invidian I noticed that this only really fixes half of the problem, since there are still randomly-named imports of these packages in conversion.go and related files. We completely ignore those files in linting, but that's overkill as far as I can tell; I have a PR ready to follow this one that enables linting and standardizes those imports as well.

When we're all happy with the naming here, I'll update that branch and put a followup PR out.

Copy link
Contributor

@jackfrancis jackfrancis left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 4, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jackfrancis

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 4, 2022
@k8s-ci-robot
Copy link
Contributor

@mboersma: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-cluster-api-provider-azure-e2e 9428cc0 link unknown /test pull-cluster-api-provider-azure-e2e

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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. I understand the commands that are listed here.

@k8s-ci-robot k8s-ci-robot merged commit e5a03e7 into kubernetes-sigs:main Aug 4, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.5 milestone Aug 4, 2022
@mboersma mboersma deleted the importas branch August 4, 2022 15:22
@jackfrancis
Copy link
Contributor

/cherry-pick release-1.4

@k8s-infra-cherrypick-robot

@jackfrancis: #2529 failed to apply on top of branch "release-1.4":

Applying: Standardize more package import aliases
Using index info to reconstruct a base tree...
M	.golangci.yml
M	azure/scope/machinepool.go
M	azure/scope/machinepoolmachine.go
M	azure/scope/machinepoolmachine_test.go
Falling back to patching base and 3-way merge...
Auto-merging azure/scope/machinepoolmachine_test.go
CONFLICT (content): Merge conflict in azure/scope/machinepoolmachine_test.go
Auto-merging azure/scope/machinepoolmachine.go
Auto-merging azure/scope/machinepool.go
Auto-merging .golangci.yml
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 Standardize more package import aliases
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

In response to this:

/cherry-pick release-1.4

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
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants