Skip to content

Update project linting to adhere to golangci-lint v2 defaults#1636

Merged
Neon-White merged 1 commit intonoobaa:masterfrom
Neon-White:update-linting-to-golandci-lint-v2
Jul 4, 2025
Merged

Update project linting to adhere to golangci-lint v2 defaults#1636
Neon-White merged 1 commit intonoobaa:masterfrom
Neon-White:update-linting-to-golandci-lint-v2

Conversation

@Neon-White
Copy link
Contributor

@Neon-White Neon-White commented Jun 25, 2025

Explain the changes

1. General lint-driven refactors

  • Converted repetitive if…else chains (e.g. signature-version checks, bucket-class mapping, CSV grouping) into switch blocks for clarity and fewer conditions.
  • Swapped direct field accesses like secret.ObjectMeta.OwnerReferences and sc.ObjectMeta.Annotations for the shorter secret.OwnerReferences and sc.Annotations.

2. Errcheck fixes & cleanup

  • Replaced plain defer file.Close() (and similar) with closures that log any close-errors, unified under a new util.SafeClose helper.
  • Routed all os.Setenv calls through util.SafeSetEnv to remove repeated error-check boilerplate.

3. New helpers

  • SafeClose[T interface{ Close() error }](resource T, errorMsg string)
    Centralizes error logging on Close() failures, leveraging Go 1.18+ generics.
  • SafeSetEnv(name, value string)
    Wraps os.Setenv calls, logging any errors to keep tests and mocks clean.

4. Small goodies

  • Removed unused imports (os in several files).
  • Simplified boolean logic (return !(A || B)return !A && !B).
  • Trimmed redundant type info (e.g. var NooBaaDB = … instead of specifying *StatefulSet).

Summary by CodeRabbit

  • Refactor

    • Improved code clarity and maintainability by replacing multiple if-else chains with switch statements in various configuration and validation routines.
    • Simplified and corrected how annotations and metadata are accessed for Kubernetes resources.
    • Streamlined boolean variable assignments and variable declarations for better readability.
  • Bug Fixes

    • Enhanced error handling by introducing safer utility functions for closing resources and setting environment variables, ensuring errors are logged rather than ignored.
    • Improved handling of environment variables and resource cleanup in tests and operational flows.
  • Chores

    • Minor formatting and comment adjustments for consistency and readability.
    • Updated imports to remove unused packages.

@coderabbitai
Copy link

coderabbitai bot commented Jun 25, 2025

Walkthrough

The changes across the codebase primarily refactor conditional logic from if-else chains to switch statements, simplify and correct field accesses for Kubernetes object metadata, and standardize resource cleanup and environment variable setting by introducing utility functions (SafeClose and SafeSetEnv). Several files now use these utilities for safer error handling during resource closure and environment variable manipulation. No exported function signatures were altered, and the overall functional behavior remains unchanged.

Changes

Files/Groups Change Summary
pkg/backingstore/reconciler.go, pkg/namespacestore/reconciler.go Refactored owner reference and annotation access to use direct struct fields instead of via ObjectMeta; refactored if-else to switch statements.
pkg/bucketclass/bucketclass.go Replaced if-else chains with switch statements for namespace policy type checks.
pkg/cli/cli_test.go, pkg/cosi/cosi_cli_test.go, pkg/cosi/cosi_test.go Replaced direct os.Setenv usage with util.SafeSetEnv for environment variable setup in tests; removed unused os imports.
pkg/controller/cephcluster/cephcluster_controller.go, pkg/system/db_reconciler.go Simplified annotation access from ObjectMeta.Annotations to direct Annotations field.
pkg/cosi/cosi_bucket_class.go Refactored if-else to switch for deletion policy assignment, with unchanged logic.
pkg/cosi/provisioner.go, pkg/validations/common_bucket_validations.go Simplified boolean assignment for test environment detection; improved error handling in socket file removal.
pkg/diagnostics/analyze.go, pkg/diagnostics/collect.go, pkg/diagnostics/dbdump.go, pkg/nb/rpc_http.go Replaced direct resource/file close calls with util.SafeClose for improved error handling during cleanup.
pkg/obc/provisioner.go Changed OB endpoint field access from nested under Connection to direct under Endpoint.
pkg/olm/olm.go Refactored CRD group conditional logic from if-else to switch-case.
pkg/system/autoscaler.go Changed boolean logic in validateKeda to require both error checks to be false for a valid state.
pkg/system/phase1_verifying.go Replaced os.Setenv and direct db.Close() with util.SafeSetEnv and util.SafeClose for safer environment variable setting and resource closing.
pkg/system/phase2_creating.go Corrected field access for Kind, Name, and Annotations on Kubernetes objects.
pkg/system/phase4_configuring.go Refactored conditional logic to switch statements; corrected annotation access.
pkg/system/system.go Replaced if-else with switch for resource requirements initialization; simplified variable declaration.
pkg/util/kms/kms_ibm_kp.go, pkg/util/kms/kms_vault.go, pkg/util/kms/kms_kmip_storage.go Replaced direct environment variable setting and resource close calls with util.SafeSetEnv and util.SafeClose for improved safety/logging.
pkg/util/util.go Added generic SafeClose and SafeSetEnv utility functions; updated all direct resource close calls to use SafeClose.
pkg/validations/backingstore_validations.go Refactored if-else to switch in deletion validation logic.

Sequence Diagram(s)

sequenceDiagram
    participant Test as Test Code
    participant Util as util
    participant OS as OS/Resource

    Test->>Util: SafeSetEnv("VAR", "value")
    Util->>OS: Set environment variable
    OS-->>Util: Return error or success
    Util-->>Test: Log error if any

    Test->>Util: SafeClose(resource, "error message")
    Util->>OS: resource.Close()
    OS-->>Util: Return error or success
    Util-->>Test: Log error if any
Loading
sequenceDiagram
    participant Controller as Controller
    participant K8sObj as K8s Object

    Controller->>K8sObj: Access .Annotations directly
    Note right of K8sObj: Instead of .ObjectMeta.Annotations
Loading
sequenceDiagram
    participant Provisioner as Provisioner
    participant OB as ObjectBucket

    Provisioner->>OB: Access .Spec.Endpoint
    Note right of OB: Instead of .Spec.Connection.Endpoint
    OB-->>Provisioner: Return BucketName, AdditionalConfigData
Loading

These diagrams illustrate the introduction of utility functions for safer resource handling, the direct access of Kubernetes object fields, and the updated ObjectBucket endpoint access pattern.


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b5fd933 and 7b240ba.

📒 Files selected for processing (27)
  • pkg/backingstore/reconciler.go (4 hunks)
  • pkg/bucketclass/bucketclass.go (5 hunks)
  • pkg/cli/cli_test.go (1 hunks)
  • pkg/controller/cephcluster/cephcluster_controller.go (2 hunks)
  • pkg/cosi/cosi_bucket_class.go (1 hunks)
  • pkg/cosi/cosi_cli_test.go (1 hunks)
  • pkg/cosi/cosi_test.go (1 hunks)
  • pkg/cosi/provisioner.go (3 hunks)
  • pkg/diagnostics/analyze.go (2 hunks)
  • pkg/diagnostics/collect.go (1 hunks)
  • pkg/diagnostics/dbdump.go (1 hunks)
  • pkg/namespacestore/reconciler.go (1 hunks)
  • pkg/nb/rpc_http.go (1 hunks)
  • pkg/obc/provisioner.go (2 hunks)
  • pkg/olm/olm.go (1 hunks)
  • pkg/system/autoscaler.go (1 hunks)
  • pkg/system/db_reconciler.go (1 hunks)
  • pkg/system/phase1_verifying.go (2 hunks)
  • pkg/system/phase2_creating.go (4 hunks)
  • pkg/system/phase4_configuring.go (4 hunks)
  • pkg/system/system.go (2 hunks)
  • pkg/util/kms/kms_ibm_kp.go (2 hunks)
  • pkg/util/kms/kms_kmip_storage.go (4 hunks)
  • pkg/util/kms/kms_vault.go (1 hunks)
  • pkg/util/util.go (9 hunks)
  • pkg/validations/backingstore_validations.go (1 hunks)
  • pkg/validations/common_bucket_validations.go (2 hunks)
✅ Files skipped from review due to trivial changes (3)
  • pkg/diagnostics/analyze.go
  • pkg/cli/cli_test.go
  • pkg/system/phase1_verifying.go
🚧 Files skipped from review as they are similar to previous changes (24)
  • pkg/util/kms/kms_vault.go
  • pkg/diagnostics/collect.go
  • pkg/cosi/cosi_cli_test.go
  • pkg/validations/common_bucket_validations.go
  • pkg/system/db_reconciler.go
  • pkg/cosi/cosi_test.go
  • pkg/util/kms/kms_kmip_storage.go
  • pkg/namespacestore/reconciler.go
  • pkg/cosi/cosi_bucket_class.go
  • pkg/diagnostics/dbdump.go
  • pkg/bucketclass/bucketclass.go
  • pkg/system/system.go
  • pkg/cosi/provisioner.go
  • pkg/validations/backingstore_validations.go
  • pkg/controller/cephcluster/cephcluster_controller.go
  • pkg/util/kms/kms_ibm_kp.go
  • pkg/system/phase4_configuring.go
  • pkg/system/phase2_creating.go
  • pkg/obc/provisioner.go
  • pkg/backingstore/reconciler.go
  • pkg/nb/rpc_http.go
  • pkg/system/autoscaler.go
  • pkg/util/util.go
  • pkg/olm/olm.go
⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: run-core-config-map-tests
  • GitHub Check: run-azure-vault-test
  • GitHub Check: run-kms-tls-token-test
  • GitHub Check: run-kms-tls-sa-test
  • GitHub Check: run-kms-key-rotate-test
  • GitHub Check: run-hac-test
  • GitHub Check: run-cli-tests
  • GitHub Check: golangci-lint
  • GitHub Check: run-admission-test
  • GitHub Check: run-kms-kmip-test
  • GitHub Check: run-operator-tests
  • GitHub Check: run-kms-dev-test
  • GitHub Check: cnpg-deployment-test
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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>, please review it.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 using 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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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

@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: 2

🔭 Outside diff range comments (1)
pkg/system/system.go (1)

281-319: Guard against potential nil-pointer on Endpoints.Resources

Nice move to a switch, but the endpoints branch does not guarantee that sys.Spec.Endpoints.Resources is non-nil when the spec already exists.
If the user supplied only minCount/maxCount via flags (or the CR arrives from an earlier version), Resources can stay nil, leading to a panic when the code below writes to component.Requests / component.Limits.

 			case "endpoints":
 				if sys.Spec.Endpoints == nil {
 					sys.Spec.Endpoints = &nbv1.EndpointsSpec{
 						MinCount: viper.GetInt32("resources.endpoints.minCount"),
 						MaxCount: viper.GetInt32("resources.endpoints.maxCount"),
 						Resources: &corev1.ResourceRequirements{
 							Requests: corev1.ResourceList{},
 							Limits:   corev1.ResourceList{},
 						},
 					}
 				} else {
+					// Ensure Resources is initialized before dereference
+					if sys.Spec.Endpoints.Resources == nil {
+						sys.Spec.Endpoints.Resources = &corev1.ResourceRequirements{
+							Requests: corev1.ResourceList{},
+							Limits:   corev1.ResourceList{},
+						}
+					}
 					if viper.IsSet("resources.endpoints.minCount") {
 						sys.Spec.Endpoints.MinCount = viper.GetInt32("resources.endpoints.minCount")
 					}
 
 					if viper.IsSet("resources.endpoints.maxCount") {
 						sys.Spec.Endpoints.MaxCount = viper.GetInt32("resources.endpoints.maxCount")
 					}
 				}
 
 				component = sys.Spec.Endpoints.Resources
🧹 Nitpick comments (1)
pkg/system/system.go (1)

769-769: Local variable should be lower-camel for consistency

var NooBaaDB = r.NooBaaPostgresDB introduces an exported-style identifier inside a function. While valid, it trips golint/revive rules (var-naming) and is inconsistent with the rest of the file (coreApp, cnpgCluster, etc.). Consider:

noobaaDB := r.NooBaaPostgresDB

(or restore the explicit type if that was intentional).

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d4ce419 and 78ccffc.

📒 Files selected for processing (27)
  • pkg/backingstore/reconciler.go (4 hunks)
  • pkg/bucketclass/bucketclass.go (5 hunks)
  • pkg/cli/cli_test.go (1 hunks)
  • pkg/controller/cephcluster/cephcluster_controller.go (2 hunks)
  • pkg/cosi/cosi_bucket_class.go (1 hunks)
  • pkg/cosi/cosi_cli_test.go (1 hunks)
  • pkg/cosi/cosi_test.go (1 hunks)
  • pkg/cosi/provisioner.go (3 hunks)
  • pkg/diagnostics/analyze.go (2 hunks)
  • pkg/diagnostics/collect.go (1 hunks)
  • pkg/diagnostics/dbdump.go (1 hunks)
  • pkg/namespacestore/reconciler.go (1 hunks)
  • pkg/nb/rpc_http.go (1 hunks)
  • pkg/obc/provisioner.go (2 hunks)
  • pkg/olm/olm.go (1 hunks)
  • pkg/system/autoscaler.go (1 hunks)
  • pkg/system/db_reconciler.go (1 hunks)
  • pkg/system/phase1_verifying.go (2 hunks)
  • pkg/system/phase2_creating.go (4 hunks)
  • pkg/system/phase4_configuring.go (4 hunks)
  • pkg/system/system.go (2 hunks)
  • pkg/util/kms/kms_ibm_kp.go (2 hunks)
  • pkg/util/kms/kms_kmip_storage.go (4 hunks)
  • pkg/util/kms/kms_vault.go (1 hunks)
  • pkg/util/util.go (9 hunks)
  • pkg/validations/backingstore_validations.go (1 hunks)
  • pkg/validations/common_bucket_validations.go (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: golangci-lint
  • GitHub Check: run-cli-tests
  • GitHub Check: cnpg-deployment-test
  • GitHub Check: run-kms-dev-test
  • GitHub Check: run-operator-tests
  • GitHub Check: run-kms-key-rotate-test
  • GitHub Check: run-hac-test
  • GitHub Check: run-azure-vault-test
  • GitHub Check: run-kms-tls-sa-test
  • GitHub Check: run-admission-test
  • GitHub Check: run-kms-tls-token-test
  • GitHub Check: run-core-config-map-tests
  • GitHub Check: run-kms-kmip-test
🔇 Additional comments (44)
pkg/util/util.go (3)

2351-2367: Excellent addition of generic utility functions for safer resource handling.

The SafeClose and SafeSetEnv functions provide a consistent, safe approach to resource cleanup and environment variable setting:

  • SafeClose uses Go generics effectively to work with any closeable resource
  • Both functions log errors instead of silently ignoring them
  • This standardizes error handling patterns across the codebase

809-809: Good adoption of SafeClose for consistent resource cleanup.

The replacement of direct Close() calls with SafeClose() improves error handling by ensuring cleanup errors are logged rather than silently ignored. Each usage includes appropriate descriptive error messages.

Also applies to: 817-817, 838-838, 1394-1394, 1453-1453, 1456-1456, 1491-1491, 1510-1510


1272-1272: Minor improvements enhance code clarity.

Good changes:

  • Line 1272: Consistent lowercase in error message
  • Line 1478: ReplaceAll is more explicit than Replace with count parameter

Also applies to: 1478-1478

pkg/validations/common_bucket_validations.go (2)

44-48: Minor comment formatting improvement.

The comment indentation adjustment improves code readability.


85-85: Good simplification of boolean assignment.

The direct assignment IsExternalRPCConnection := util.IsTestEnv() || isCLI is cleaner than an if-else block and maintains the same logic.

pkg/system/autoscaler.go (1)

354-354: Good simplification of boolean logic.

Converting the logic to !meta.IsNoMatchError(err) && !runtime.IsNotRegisteredError(err) makes it clearer that validation passes when neither error condition is true.

pkg/nb/rpc_http.go (1)

48-48: Consistent adoption of SafeClose for HTTP response cleanup.

The replacement of direct Close() with SafeClose() aligns with the safer resource cleanup pattern established in this PR and ensures any errors during HTTP response body closing are properly logged.

pkg/cosi/cosi_cli_test.go (1)

19-19: LGTM! Improved error handling for environment variable setting.

The change from direct os.Setenv to util.SafeSetEnv aligns with the project's standardization effort and ensures any environment variable setting errors are properly logged during test setup.

pkg/diagnostics/collect.go (1)

119-119: LGTM! Enhanced resource cleanup with error logging.

The replacement of direct defer outfile.Close() with util.SafeClose ensures that file closure errors are properly logged with context, which is especially valuable in diagnostics collection where resource issues could indicate underlying problems.

pkg/util/kms/kms_ibm_kp.go (2)

43-43: LGTM! Standardized environment variable setting with error logging.

The change from direct os.Setenv to util.SafeSetEnv ensures that errors setting the IBM instance ID environment variable are properly logged, which aids in debugging KMS configuration issues.


71-71: LGTM! Improved error handling for sensitive configuration.

The use of util.SafeSetEnv for caching API keys ensures that environment variable setting errors are logged, which is particularly important when handling sensitive KMS credentials.

pkg/cosi/cosi_test.go (1)

23-23: LGTM! Consistent error handling for test environment setup.

The replacement of direct os.Setenv with util.SafeSetEnv maintains consistency with the project's standardized approach to environment variable setting and ensures test setup errors are properly logged.

pkg/cli/cli_test.go (1)

21-21: LGTM! Standardized test environment configuration.

The change from direct os.Setenv to util.SafeSetEnv completes the consistent application of safer environment variable handling across the CLI test suite.

pkg/util/kms/kms_vault.go (1)

163-163: Excellent error handling improvement.

Replacing the direct file.Close() call with util.SafeClose() ensures that any errors during file closure are properly logged with a descriptive message, rather than being silently ignored.

pkg/diagnostics/dbdump.go (1)

97-97: Consistent error handling improvement.

The change to use util.SafeClose() aligns with the broader pattern across the codebase to ensure file closure errors are properly logged with descriptive messages.

pkg/system/db_reconciler.go (1)

258-258: Good simplification of annotation access.

Using r.NooBaa.Annotations directly instead of r.NooBaa.ObjectMeta.Annotations is more idiomatic and concise while maintaining the same functionality.

pkg/diagnostics/analyze.go (2)

477-477: Consistent with the resource cleanup pattern.

The change to use util.SafeClose() maintains consistency with the error handling improvements applied throughout the codebase.


421-421: Good code hygiene improvement.

Removing trailing whitespace improves code cleanliness and aligns with standard linting practices.

pkg/controller/cephcluster/cephcluster_controller.go (2)

96-97: Consistent annotation access simplification.

Using bs.Annotations directly instead of bs.ObjectMeta.Annotations follows the same simplification pattern applied throughout the codebase, improving readability while maintaining functionality.


37-37: Minor formatting improvement.

The field alignment adjustment improves code readability and follows consistent formatting standards.

pkg/system/phase1_verifying.go (2)

61-62: LGTM: Standardized environment variable setting with error handling.

The replacement of direct os.Setenv calls with util.SafeSetEnv improves error handling consistency across the codebase by providing centralized error logging for environment variable operations.


236-236: LGTM: Improved database connection cleanup with error logging.

The use of util.SafeClose instead of direct defer db.Close() ensures that any errors during connection closure are properly logged with a descriptive message, enhancing debugging capabilities.

pkg/namespacestore/reconciler.go (1)

558-558: LGTM: Simplified field access improves readability.

The direct access to secret.OwnerReferences instead of secret.ObjectMeta.OwnerReferences is valid since OwnerReferences is embedded and directly accessible on Kubernetes objects. This change enhances code conciseness without functional impact.

pkg/cosi/cosi_bucket_class.go (1)

232-239: LGTM: Switch statement improves readability and maintainability.

The conversion from if-else chain to switch statement for deletion policy handling enhances code clarity and reduces cyclomatic complexity. The logic is preserved correctly with proper handling of "delete", "retain", and invalid cases.

pkg/util/kms/kms_kmip_storage.go (2)

138-138: LGTM: Enhanced error handling for connection cleanup during failures.

Replacing direct conn.Close() calls with util.SafeClose() in error paths ensures that connection closure failures are properly logged with descriptive messages, improving debugging capabilities for KMIP connection issues.

Also applies to: 144-144


276-276: LGTM: Consistent connection cleanup with error logging in deferred calls.

The use of util.SafeClose() in deferred connection cleanup ensures that any errors during connection closure are logged with meaningful context messages, maintaining consistency with the broader codebase error handling patterns.

Also applies to: 349-349, 410-410

pkg/bucketclass/bucketclass.go (2)

661-702: LGTM: Switch statement improves readability in namespace store mapping logic.

The conversion from if-else chain to switch statement for handling namespace policy types (Single, Multi, Cache) enhances code clarity and reduces cyclomatic complexity while preserving the exact same logic for determining bucket class reconciliation requirements.


753-779: LGTM: Switch statement enhances namespace bucket info creation logic.

The refactoring to use a switch statement for namespace policy type handling improves code readability and maintainability. The logic correctly preserves the behavior for creating appropriate namespace bucket configurations based on policy type (Single, Multi, Cache).

pkg/cosi/provisioner.go (3)

72-74: Excellent error handling improvement!

Adding proper error checking and logging for socket file removal is a great defensive programming practice. This prevents silent failures and provides visibility into potential issues during startup.


245-245: Clean boolean assignment simplification.

Directly assigning the result of util.IsTestEnv() is more concise and idiomatic than using an intermediate variable declaration.


286-286: Consistent boolean assignment improvement.

This matches the same simplification pattern applied elsewhere in the function, maintaining consistency.

pkg/system/phase2_creating.go (3)

376-376: Improved Kubernetes object field access patterns.

Using r.CoreApp.Kind instead of r.CoreApp.TypeMeta.Kind is more idiomatic and aligns with standard Kubernetes API patterns. This simplification improves readability while maintaining the same functionality.

Also applies to: 385-385


828-828: Corrected object name access pattern.

Using direct field access (cephObjectStoreList.Items[0].Name) instead of accessing through the embedded ObjectMeta field is the preferred and more idiomatic approach in Kubernetes APIs.


1440-1440: Simplified StorageClass annotations access.

Direct access to sc.Annotations is cleaner and more idiomatic than accessing through sc.ObjectMeta.Annotations. This change aligns with the consistent pattern applied throughout the codebase.

pkg/validations/backingstore_validations.go (1)

264-271: Excellent refactoring to switch statement.

Converting the if-else chain to a switch statement significantly improves readability while maintaining identical logic and error handling. This change aligns perfectly with the PR's goal of adhering to golangci-lint v2 standards and reducing condition complexity.

pkg/olm/olm.go (1)

745-756: Well-executed conditional logic refactoring.

The conversion from if-else chain to switch statement improves code clarity and readability while preserving the exact same logic for determining CRD ownership and requirements. This change exemplifies the consistent refactoring approach applied throughout the PR to enhance maintainability.

pkg/obc/provisioner.go (3)

397-397: LGTM! Bucket name access updated consistently.

The bucket name access has been correctly updated to use the new direct endpoint access pattern.


406-408: LGTM! Additional config data access updated consistently.

The additional config data access has been correctly updated to use the new direct endpoint access pattern, maintaining consistency with the schema changes.


394-396: Verify ObjectBucketSpec and Endpoint struct definitions for schema consistency

#!/bin/bash
# Locate the ObjectBucketSpec definition
echo "Searching for ObjectBucketSpec definition:"
rg -n "type ObjectBucketSpec" --type go

echo -e "\nSearching for Endpoint struct definition:"
rg -n "type Endpoint" --type go
pkg/system/phase4_configuring.go (3)

171-212: Excellent refactoring from if-else chain to switch statement.

The conversion from if-else if statements to a switch statement on res1.State significantly improves code readability and aligns with Go best practices. The logic flow remains identical while being more maintainable.


298-298: LGTM! Annotation access simplified correctly.

The direct access to r.NooBaa.Annotations instead of r.NooBaa.ObjectMeta.Annotations is valid and more concise, as the Annotations field is accessible directly on Kubernetes objects.


1434-1437: LGTM! Consistent annotation access pattern.

The direct access to r.DefaultBackingStore.Annotations maintains consistency with the annotation access pattern used throughout the file and is correctly implemented.

pkg/backingstore/reconciler.go (2)

309-320: Ownership-check refactor is sound

Switching to secret.OwnerReferences leverages struct embedding and removes verbosity without changing behaviour. ✅


1015-1017: Minor refactor: direct annotation access looks fine

Accessing r.BackingStore.Annotations directly eliminates redundant ObjectMeta dereference and the nil-check guards against panics.

Copy link
Member

@aayushchouhan09 aayushchouhan09 left a comment

Choose a reason for hiding this comment

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

Please squash your commits before merging. Thanks!

@Neon-White Neon-White force-pushed the update-linting-to-golandci-lint-v2 branch from 78ccffc to b5fd933 Compare July 4, 2025 10:18
Signed-off-by: Ben <belimele@redhat.com>
@Neon-White Neon-White force-pushed the update-linting-to-golandci-lint-v2 branch from b5fd933 to 7b240ba Compare July 4, 2025 10:55
@Neon-White Neon-White merged commit 8cf8e5c into noobaa:master Jul 4, 2025
16 of 17 checks passed
@Neon-White Neon-White deleted the update-linting-to-golandci-lint-v2 branch July 4, 2025 11:47
@coderabbitai coderabbitai bot mentioned this pull request Jul 15, 2025
@coderabbitai coderabbitai bot mentioned this pull request Jul 24, 2025
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants