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 linters #402

Merged
merged 10 commits into from
May 30, 2024
Merged

feat: add linters #402

merged 10 commits into from
May 30, 2024

Conversation

MSevey
Copy link
Member

@MSevey MSevey commented May 29, 2024

Overview

Closes: #372

This PR:

  • adds some new Makefile commands for runner linters and formatting
  • enables lint in CI
  • fixes some of the lint errors

NOTE: the markdownlint link checker is failing on linking to /e2e because there is nothing in the directory except the subdirectory, it actually 404s. This PR will actually resolve that if it gets merged: #404

Summary by CodeRabbit

  • New Features

    • Introduced a GitHub Actions workflow for linting, including checks for Go code, YAML files, Markdown files, and Go package vulnerabilities.
  • Documentation

    • Improved the contribution guidelines for better clarity and readability.
    • Updated the README to include a hyperlink for the documentation.
  • Chores

    • Added exclusions to the .gitignore file for specific files and directories.
    • Reorganized import statements across multiple files for better code organization.
    • Updated the Makefile with new targets for various tasks like cleaning, testing, and linting.
  • Bug Fixes

    • Improved error handling in multiple test functions by changing t.Fatalf to t.Errorf.
    • Corrected the handling of time tickers in the WaitInstanceIsRunning method.

Copy link
Contributor

coderabbitai bot commented May 29, 2024

Walkthrough

The recent updates encompass a variety of improvements and additions across multiple files. These include enhanced configuration settings, new GitHub Actions workflows for linting, updated contribution guidelines, refined Makefile targets, and better error handling. Additionally, there are numerous import statement reorders and minor code adjustments to improve readability, maintainability, and functionality. The changes also address specific linting requirements and error handling improvements.

Changes

Files/Groups Change Summary
.env Added purpose note, adjusted formatting, and aligned assignment statements.
.github/workflows/knuu_testing.yml Removed unnecessary spaces in branch names.
.github/workflows/lint.yml Introduced a new GitHub Actions workflow for linting and vulnerability checks.
.gitignore Added exclusions for coverage.txt, .vscode/launch.json, */**.html, and *.idea.
.golangci.yml Added configurations for Go linting and issues exclusion.
.markdownlint.yaml Introduced configurations for Markdown linting rules.
CONTRIBUTING.md Improved readability and detailed contribution process.
Makefile Added new targets for help, clean, cover, deps, lint, fmt, vet, and updated test target.
README.md Updated a URL to a hyperlink for documentation location.
docs/architecture/... Adjusted formatting and indentation in node configuration playbook.
e2e/basic/file_test_image_cached_test.go Changed error handling message from t.Fatalf to t.Errorf.
e2e/basic/files_to_volumes_cm_test.go Simplified instanceName variable assignment.
e2e/basic/folder_test.go Reorganized import statements.
e2e/basic/folder_test_image_cached_test.go Changed error handling message from t.Fatalf to t.Errorf.
e2e/basic/main_test.go Rearranged import statements.
e2e/basic/probe_test.go Added import statement for github.com/celestiaorg/knuu/pkg/knuu.
e2e/basic/rbac_test.go Moved import statement within the import block.
pkg/builder/docker/docker.go Rearranged import statements.
pkg/builder/kaniko/kaniko.go Rearranged import statements.
pkg/builder/kaniko/kaniko_test.go Moved wg.Add(1) above goroutine creation and adjusted import statements.
pkg/builder/kaniko/utils_test.go Changed file permission settings from os.ModePerm to 0600.
pkg/container/docker.go Enhanced error handling by using the %w verb in error message formatting.
pkg/instance/bittwister.go Adjusted import order.
pkg/instance/helper.go Reorganized import statements.
pkg/instance/instance.go Replaced time.Tick with time.NewTicker for proper ticker handling.
pkg/k8s/k8s_custom_resource.go Replaced strings.ToLower with strings.EqualFold for case-insensitive comparison.
pkg/k8s/k8s_pod.go Added label PodCheckLoop to loop and modified break statement.
pkg/k8s/types.go Updated return types and parameters for several functions to use corev1 instead of v1.
pkg/knuu/instance_old.go Reordered import statements.
pkg/knuu/knuu_test.go Adjusted import statement order.
pkg/minio/minio.go Simplified expiration variable declaration.
pkg/preloader/preloader.go Adjusted import order.
pkg/system/dependencies.go Moved github.com/sirupsen/logrus import statement to be placed before other external package imports.
pkg/traefik/traefik.go Adjusted import statements for k8s and names packages.

Assessment against linked issues

Objective (Issue) Addressed Explanation
Enable golangci-lint for the repo and enable the export comment linter (#372)

Poem

In the land of code, where bunnies do roam,
They tidy the files, make the changes known.
With linting and testing, they hop through the night,
Ensuring the codebase is clean and bright.
A tweak here, a fix there, all done with care,
For a better tomorrow, they code and they share. 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Outside diff range and nitpick comments (1)
pkg/instance/helper.go (1)

Line range hint 398-398: Specify a more restrictive IP address instead of "0.0.0.0" to enhance security.

- return nil, ErrSettingBitTwisterEnv.Wrap(err)
+ if err := bt.SetEnvironmentVariable("SERVE_ADDR", fmt.Sprintf("127.0.0.1:%d", i.BitTwister.Port())); err != nil {
+     return nil, ErrSettingBitTwisterEnv.Wrap(err)
+ }
Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 74e6413 and ecc7b53.
Files selected for processing (35)
  • .env (1 hunks)
  • .github/workflows/knuu_testing.yml (1 hunks)
  • .github/workflows/lint.yml (1 hunks)
  • .gitignore (1 hunks)
  • .golangci.yml (1 hunks)
  • .markdownlint.yaml (1 hunks)
  • .yamllint.yml (1 hunks)
  • CONTRIBUTING.md (1 hunks)
  • Makefile (1 hunks)
  • README.md (1 hunks)
  • docs/architecture/adr-001-redesign-knuu-async-approach.md (1 hunks)
  • e2e/basic/file_test_image_cached_test.go (1 hunks)
  • e2e/basic/files_to_volumes_cm_test.go (2 hunks)
  • e2e/basic/folder_test.go (1 hunks)
  • e2e/basic/folder_test_image_cached_test.go (1 hunks)
  • e2e/basic/main_test.go (1 hunks)
  • e2e/basic/probe_test.go (1 hunks)
  • e2e/basic/rbac_test.go (1 hunks)
  • pkg/builder/docker/docker.go (1 hunks)
  • pkg/builder/kaniko/kaniko.go (1 hunks)
  • pkg/builder/kaniko/kaniko_test.go (2 hunks)
  • pkg/builder/kaniko/utils_test.go (1 hunks)
  • pkg/container/docker.go (1 hunks)
  • pkg/instance/bittwister.go (1 hunks)
  • pkg/instance/helper.go (1 hunks)
  • pkg/instance/instance.go (1 hunks)
  • pkg/k8s/k8s_custom_resource.go (1 hunks)
  • pkg/k8s/k8s_pod.go (2 hunks)
  • pkg/k8s/types.go (4 hunks)
  • pkg/knuu/instance_old.go (1 hunks)
  • pkg/knuu/knuu_test.go (1 hunks)
  • pkg/minio/minio.go (1 hunks)
  • pkg/preloader/preloader.go (1 hunks)
  • pkg/system/dependencies.go (1 hunks)
  • pkg/traefik/traefik.go (2 hunks)
Files skipped from review due to trivial changes (22)
  • .env
  • .github/workflows/knuu_testing.yml
  • .github/workflows/lint.yml
  • .gitignore
  • .golangci.yml
  • .markdownlint.yaml
  • .yamllint.yml
  • README.md
  • docs/architecture/adr-001-redesign-knuu-async-approach.md
  • e2e/basic/file_test_image_cached_test.go
  • e2e/basic/files_to_volumes_cm_test.go
  • e2e/basic/folder_test.go
  • e2e/basic/main_test.go
  • e2e/basic/rbac_test.go
  • pkg/builder/docker/docker.go
  • pkg/instance/bittwister.go
  • pkg/knuu/instance_old.go
  • pkg/knuu/knuu_test.go
  • pkg/minio/minio.go
  • pkg/preloader/preloader.go
  • pkg/system/dependencies.go
  • pkg/traefik/traefik.go
Additional comments not posted (24)
Makefile (1)

5-9: The additions to the Makefile are well-structured and enhance the build process. Good use of .PHONY to ensure that targets are always executed.

Also applies to: 11-16, 18-23, 25-30, 32-42, 44-50, 52-56, 58-59

e2e/basic/folder_test_image_cached_test.go (1)

40-40: Switching to t.Errorf allows the test to continue and report further errors, which is preferable in most testing scenarios.

pkg/builder/kaniko/utils_test.go (1)

25-25: Changing permissions to 0600 for directories and files in tests is a secure practice, ensuring restricted access.

Also applies to: 28-28

e2e/basic/probe_test.go (1)

Line range hint 1-1: No changes detected in this file for review.

pkg/builder/kaniko/kaniko_test.go (3)

Line range hint 16-50: The changes in the TestKanikoBuilder function look good and cover multiple scenarios effectively.


16-16: The import of the builder package is correctly placed and used within the test functions.


16-16: The import of the builder package is correctly placed and used within the test functions.

pkg/k8s/types.go (2)

20-20: The update to use corev1.ConfigMap in the CreateConfigMap function signature is correct and aligns with the updated imports.


22-29: The updates to use corev1 types in the CreateDaemonSet, CreateService, PatchService, and UpdateDaemonSet function signatures are correct and ensure consistency with the updated imports.

Also applies to: 63-63, 75-75

pkg/container/docker.go (1)

249-255: The runCommand function correctly captures stdout and stderr, and it properly formats the error message to include these details.

pkg/builder/kaniko/kaniko.go (2)

16-18: The imports in the file are correctly organized and relevant to the functionalities used in the Kaniko builder implementation.


16-18: The Kaniko builder implementation is comprehensive, covering job preparation, monitoring, and cleanup effectively. Error handling and logging are appropriately implemented.

pkg/k8s/k8s_pod.go (1)

Line range hint 109-122: The ReplacePodWithGracePeriod function is well-implemented with robust error handling and detailed logging. The use of labels for loop control improves readability and control flow.

pkg/instance/helper.go (11)

17-17: Ensure the new import github.com/celestiaorg/knuu/pkg/k8s is utilized effectively throughout the file.


18-18: Good use of conditional checks for sidecar instances in service deployment logic.


18-18: Proper implementation of service destruction logic.


18-18: Well-structured function for pod deployment with comprehensive error handling.


18-18: Effective management of pod and associated resource deletion with grace period handling.


18-18: Correct implementation of volume deployment logic.


18-18: Proper implementation of volume destruction logic.


18-18: Well-implemented function for deploying files as configmaps.


18-18: Effective implementation of file destruction logic.


18-18: Comprehensive resource deployment function with robust error handling.


18-18: Comprehensive resource destruction function with robust error handling.

pkg/instance/instance.go Show resolved Hide resolved
pkg/k8s/k8s_custom_resource.go Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between ecc7b53 and f193015.
Files selected for processing (1)
  • README.md (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • README.md

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between f193015 and 544d9c9.
Files selected for processing (3)
  • .github/workflows/lint.yml (1 hunks)
  • CONTRIBUTING.md (1 hunks)
  • Makefile (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • .github/workflows/lint.yml
  • Makefile
Additional Context Used
LanguageTool (3)
CONTRIBUTING.md (3)

Near line 37: Did you mean “either”?
Context: ...a feature, it should not have bug fixes too. This is to enable the maintainers revi...
Rule ID: NOT_TOO_EITHER


Near line 37: Possible missing preposition found.
Context: ... too. This is to enable the maintainers review your PR efficiently. 1. Commit the cha...
Rule ID: AI_HYDRA_LEO_MISSING_TO


Near line 58: Using many exclamation marks might seem excessive (in this case: 3 exclamation marks for a text that’s 2127 characters long)
Context: ...with the fix: prefix. Congratulations! You have successfully made a Pull Reque...
Rule ID: EN_EXCESSIVE_EXCLAMATION

CONTRIBUTING.md Show resolved Hide resolved
CONTRIBUTING.md Show resolved Hide resolved
tty47
tty47 previously approved these changes May 30, 2024
Copy link
Contributor

@tty47 tty47 left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks!

Copy link
Contributor

@mojtaba-esk mojtaba-esk left a comment

Choose a reason for hiding this comment

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

lgtm 🚀
left a question.

pkg/builder/kaniko/utils_test.go Outdated Show resolved Hide resolved
@MSevey MSevey requested review from tty47 and mojtaba-esk May 30, 2024 12:38
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 544d9c9 and cfc1a80.

Files selected for processing (2)
  • e2e/basic/folder_test.go (1 hunks)
  • pkg/builder/kaniko/utils_test.go (2 hunks)
Files skipped from review as they are similar to previous changes (2)
  • e2e/basic/folder_test.go
  • pkg/builder/kaniko/utils_test.go

Copy link
Contributor

@mojtaba-esk mojtaba-esk left a comment

Choose a reason for hiding this comment

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

LGTM!

@MSevey MSevey added this pull request to the merge queue May 30, 2024
Merged via the queue into main with commit 994378c May 30, 2024
6 of 8 checks passed
@MSevey MSevey deleted the sevey/enable-lints branch May 30, 2024 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider enabling golangci-lint for this repo and enable the export comment linter.
3 participants