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

feat: Add golangci-lint linters - imports #1337

Conversation

mateusoliveira43
Copy link
Contributor

@mateusoliveira43 mateusoliveira43 commented Feb 19, 2024

Add more linting checks to project with golangci-lint. This PR fixes issues related to imports in the code.

.golangci.yaml is similar to the one proposed at vmware-tanzu/velero#7194

Test

Run golangci-lint with new make lint and make lint-fix commands.

TODO

All go files changes where related to imports errors (with the help of make lint-fix command). There are still a lot of issues to be resolved in the code, but they will be fixed by categories in follow up PRs.

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 19, 2024
@mateusoliveira43
Copy link
Contributor Author

/test unit-test


.PHONY: golangci-lint
golangci-lint: ## Download golangci-lint locally if necessary.
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/[email protected])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

latest version that works with go 1.20

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 20, 2024
Copy link
Contributor

@shawn-hurley shawn-hurley left a comment

Choose a reason for hiding this comment

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

LGTM, I think this is an excellent start to standardizing imports!

@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 22, 2024
@mateusoliveira43 mateusoliveira43 changed the title feat: Add golangci-lint feat: Add golangci-lint linters - imports Feb 22, 2024
@weshayutin
Copy link
Contributor

@mateusoliveira43 thanks for pushing this forward and taking small steps ++

Copy link
Member

@shubham-pampattiwar shubham-pampattiwar left a comment

Choose a reason for hiding this comment

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

changes look sane to me, VISIACK

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 24, 2024
Signed-off-by: Mateus Oliveira <[email protected]>
Signed-off-by: Mateus Oliveira <[email protected]>
Signed-off-by: Mateus Oliveira <[email protected]>
Signed-off-by: Mateus Oliveira <[email protected]>
Signed-off-by: Mateus Oliveira <[email protected]>
Signed-off-by: Mateus Oliveira <[email protected]>
Signed-off-by: Mateus Oliveira <[email protected]>
Signed-off-by: Mateus Oliveira <[email protected]>
Signed-off-by: Mateus Oliveira <[email protected]>
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 26, 2024
@mateusoliveira43
Copy link
Contributor Author

/retest

2 similar comments
@mateusoliveira43
Copy link
Contributor Author

/retest

@mateusoliveira43
Copy link
Contributor Author

/retest

@weshayutin
Copy link
Contributor

whayutin@thinkdoe:~/OPENSHIFT/git/OADP/oadp-operator$ make lint
/home/whayutin/OPENSHIFT/git/OADP/oadp-operator/bin/golangci-lint run
controllers/registry.go:12: File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(github.com/openshift/oadp-operator) (gci)
	"k8s.io/apimachinery/pkg/labels"
controllers/registry.go:17: File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(github.com/openshift/oadp-operator) (gci)
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
make: *** [Makefile:542: lint] Error 1
whayutin@thinkdoe:~/OPENSHIFT/git/OADP/oadp-operator$ git status
On branch feat/enforce-linter-rules
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   controllers/registry.go

no changes added to commit (use "git add" and/or "git commit -a")
whayutin@thinkdoe:~/OPENSHIFT/git/OADP/oadp-operator$ make lint-fix
/home/whayutin/OPENSHIFT/git/OADP/oadp-operator/bin/golangci-lint run --fix
whayutin@thinkdoe:~/OPENSHIFT/git/OADP/oadp-operator$ git status
On branch feat/enforce-linter-rules
nothing to commit, working tree clean
whayutin@thinkdoe:~/OPENSHIFT/git/OADP/oadp-operator$ make lint
/home/whayutin/OPENSHIFT/git/OADP/oadp-operator/bin/golangci-lint run

Looks good to me, however to be perfectly honest, I'm not sure where the lint logs are in prow. Looked in unit and didn't see it.

@weshayutin
Copy link
Contributor

/LGTM

@mateusoliveira43
Copy link
Contributor Author

@weshayutin in unit-test (the line /go/src/github.com/openshift/oadp-operator/bin/golangci-lint run, it would print more things, if there were errors)

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Feb 28, 2024
Copy link

openshift-ci bot commented Feb 28, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mateusoliveira43, shubham-pampattiwar

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:
  • OWNERS [mateusoliveira43,shubham-pampattiwar]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot
Copy link

/retest-required

Remaining retests: 0 against base HEAD 5966523 and 2 for PR HEAD bc5e142 in total

@mateusoliveira43
Copy link
Contributor Author

/retest

1 similar comment
@mateusoliveira43
Copy link
Contributor Author

/retest

@mateusoliveira43
Copy link
Contributor Author

/override ci/prow/4.12-e2e-test-aws

Copy link

openshift-ci bot commented Feb 29, 2024

@mateusoliveira43: Overrode contexts on behalf of mateusoliveira43: ci/prow/4.12-e2e-test-aws

In response to this:

/override ci/prow/4.12-e2e-test-aws

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.

Copy link

openshift-ci bot commented Feb 29, 2024

@mateusoliveira43: all tests passed!

Full PR test history. Your PR dashboard.

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.

@openshift-merge-bot openshift-merge-bot bot merged commit 76f0049 into openshift:master Feb 29, 2024
16 checks passed
@mateusoliveira43
Copy link
Contributor Author

will open cherry-pick PR once there are no oadp-1.3 PRs open

@mateusoliveira43
Copy link
Contributor Author

/cherry-pick oadp-1.3

@openshift-cherrypick-robot
Copy link
Contributor

@mateusoliveira43: #1337 failed to apply on top of branch "oadp-1.3":

Applying: feat: Add golangci-lint
Using index info to reconstruct a base tree...
M	Makefile
M	api/v1alpha1/oadp_types.go
M	controllers/bsl_test.go
M	controllers/dpa_controller.go
M	controllers/nodeagent.go
M	controllers/nodeagent_test.go
M	controllers/validator.go
M	tests/e2e/backup_restore_suite_test.go
M	tests/e2e/e2e_suite_test.go
M	tests/e2e/lib/apps.go
A	tests/e2e/lib/common_helpers.go
M	tests/e2e/lib/dpa_helpers.go
A	tests/e2e/lib/virt_helpers.go
A	tests/e2e/lib/virt_storage_helpers.go
M	tests/e2e/must-gather_suite_test.go
M	tests/e2e/subscription_suite_test.go
A	tests/e2e/virt_backup_restore_suite_test.go
Falling back to patching base and 3-way merge...
CONFLICT (modify/delete): tests/e2e/virt_backup_restore_suite_test.go deleted in HEAD and modified in feat: Add golangci-lint. Version feat: Add golangci-lint of tests/e2e/virt_backup_restore_suite_test.go left in tree.
Auto-merging tests/e2e/subscription_suite_test.go
Auto-merging tests/e2e/must-gather_suite_test.go
CONFLICT (modify/delete): tests/e2e/lib/virt_storage_helpers.go deleted in HEAD and modified in feat: Add golangci-lint. Version feat: Add golangci-lint of tests/e2e/lib/virt_storage_helpers.go left in tree.
CONFLICT (modify/delete): tests/e2e/lib/virt_helpers.go deleted in HEAD and modified in feat: Add golangci-lint. Version feat: Add golangci-lint of tests/e2e/lib/virt_helpers.go left in tree.
Auto-merging tests/e2e/lib/dpa_helpers.go
CONFLICT (content): Merge conflict in tests/e2e/lib/dpa_helpers.go
CONFLICT (modify/delete): tests/e2e/lib/common_helpers.go deleted in HEAD and modified in feat: Add golangci-lint. Version feat: Add golangci-lint of tests/e2e/lib/common_helpers.go left in tree.
Auto-merging tests/e2e/lib/apps.go
Auto-merging tests/e2e/e2e_suite_test.go
CONFLICT (content): Merge conflict in tests/e2e/e2e_suite_test.go
Auto-merging tests/e2e/backup_restore_suite_test.go
Auto-merging controllers/validator.go
Auto-merging controllers/nodeagent_test.go
CONFLICT (content): Merge conflict in controllers/nodeagent_test.go
Auto-merging controllers/nodeagent.go
Auto-merging controllers/dpa_controller.go
Auto-merging controllers/bsl_test.go
Auto-merging api/v1alpha1/oadp_types.go
Auto-merging Makefile
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 feat: Add golangci-lint
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 oadp-1.3

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.

mateusoliveira43 added a commit to mateusoliveira43/oadp-operator that referenced this pull request Mar 1, 2024
* feat: Add golangci-lint

Signed-off-by: Mateus Oliveira <[email protected]>

* fixup! feat: Add golangci-lint

Signed-off-by: Mateus Oliveira <[email protected]>

* fixup! feat: Add golangci-lint

Signed-off-by: Mateus Oliveira <[email protected]>

* fixup! feat: Add golangci-lint

Signed-off-by: Mateus Oliveira <[email protected]>

* fixup! feat: Add golangci-lint

Signed-off-by: Mateus Oliveira <[email protected]>

* fixup! feat: Add golangci-lint

Signed-off-by: Mateus Oliveira <[email protected]>

* fixup! feat: Add golangci-lint

Signed-off-by: Mateus Oliveira <[email protected]>

* fixup! feat: Add golangci-lint

Signed-off-by: Mateus Oliveira <[email protected]>

* fixup! feat: Add golangci-lint

Signed-off-by: Mateus Oliveira <[email protected]>

---------

Signed-off-by: Mateus Oliveira <[email protected]>
(cherry picked from commit 76f0049)
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. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants