Skip to content

Conversation

zach-source
Copy link

Closes akash-network/support#295

This commit addresses an issue with the provider when attempting to SSH to a lease with a shared memory mount. It also corrects a websocket protocol violation on error (encountered while debugging the SHM issue). The core issue essentially was when the lease-shell command attempted to connect, it would try to do so on a Statefulset due to detecting a volume on the deployment. Having it follow the convention of the Deploy() function let's it connect to the deployment properly.

  1. StatefulSet Detection Fix:

    • Fixed incorrect logic in ServiceStatus that was checking for any mounted storage instead of persistent storage to determine workload type
    • The bug caused services with RAM volumes to incorrectly attempt StatefulSet operations, resulting in "statefulsets.apps not found" errors
    • Now correctly checks storage.Attributes.Find(sdl.StorageAttributePersistent) to match the deployment creation logic
  2. WebSocket Error Handling in lease-shell:

    • Fixed improper error handling when ServiceStatus fails during shell operations
    • Previously used http.Error() on WebSocket connections, causing protocol violations
    • Now properly uses WebSocket writer with LeaseShellCodeFailure and logs errors
    • Prevents silent failures and improves debugging for shell access issues

Added comprehensive unit tests for StatefulSet detection logic covering:

  • Services with persistent storage (should use StatefulSet)
  • Services with non-persistent storage (should use Deployment)
  • Services with no storage (should use Deployment)

These fixes ensure proper workload type detection and improve error visibility for lease-shell operations, resolving issues with shell access to deployments using RAM volumes.

akash-network#295)

This commit addresses two critical issues in the Akash provider:

1. StatefulSet Detection Fix:
   - Fixed incorrect logic in ServiceStatus that was checking for any mounted
     storage instead of persistent storage to determine workload type
   - The bug caused services with RAM volumes to incorrectly attempt StatefulSet
     operations, resulting in "statefulsets.apps not found" errors
   - Now correctly checks storage.Attributes.Find(sdl.StorageAttributePersistent)
     to match the deployment creation logic

2. WebSocket Error Handling in lease-shell:
   - Fixed improper error handling when ServiceStatus fails during shell operations
   - Previously used http.Error() on WebSocket connections, causing protocol violations
   - Now properly uses WebSocket writer with LeaseShellCodeFailure and logs errors
   - Prevents silent failures and improves debugging for shell access issues

Added comprehensive unit tests for StatefulSet detection logic covering:
- Services with persistent storage (should use StatefulSet)
- Services with non-persistent storage (should use Deployment)
- Services with no storage (should use Deployment)

These fixes ensure proper workload type detection and improve error visibility
for lease-shell operations, resolving issues with shell access to deployments
using RAM volumes.
@zach-source zach-source requested review from boz and troian as code owners July 30, 2025 02:17
Copy link

coderabbitai bot commented Jul 30, 2025

Walkthrough

The changes update the logic for detecting whether a Kubernetes service should be treated as a Deployment or StatefulSet based on persistent storage attributes, aligning it with deployment creation logic. A new unit test verifies this behavior. Additionally, error reporting in the WebSocket shell handler is adjusted to send errors over the WebSocket connection instead of HTTP.

Changes

Cohort / File(s) Change Summary
StatefulSet Detection Logic Update
cluster/kube/client.go
Refactored the logic in ServiceStatus to detect persistent storage using Resources.Storage and the StorageAttributePersistent flag, matching deployment creation logic.
StatefulSet Detection Test
cluster/kube/client_test.go
Added TestServiceStatusStatefulSetDetection to verify correct workload type detection based on persistent storage attributes.
WebSocket Error Handling
gateway/rest/router.go
Modified leaseShellHandler to send service status errors over the WebSocket connection instead of HTTP, using a specialized WebSocket writer.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant REST Gateway
    participant KubeClient

    Client->>REST Gateway: Open WebSocket (leaseShellHandler)
    REST Gateway->>KubeClient: ServiceStatus()
    KubeClient-->>REST Gateway: Service status or error
    alt ServiceStatus error
        REST Gateway->>Client: Send failure message over WebSocket
    else Success
        REST Gateway->>Client: Proceed with shell session
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Assessment against linked issues

Objective Addressed Explanation
Ensure shell access works when shared memory (shm) is enabled and storage is marked non-persistent (#295)
Correctly detect and handle workload type (StatefulSet vs Deployment) based on persistent storage flag (#295)
Align error reporting in shell handler with WebSocket protocol when service status check fails (#295)

Poem

A rabbit hopped through code so neat,
To fix the shell with shm complete.
Now errors travel on WebSocket air,
And StatefulSets detect with care.
With tests in tow, the bug’s no more—
The cluster’s shell is safe, for sure!
🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.2.2)

Error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/product/migration-guide for migration instructions
The command is terminated due to an error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/product/migration-guide for migration instructions

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 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 17937d6 and 5f46b78.

📒 Files selected for processing (3)
  • cluster/kube/client.go (1 hunks)
  • cluster/kube/client_test.go (2 hunks)
  • gateway/rest/router.go (1 hunks)
🔇 Additional comments (3)
cluster/kube/client.go (1)

938-948: LGTM! Storage detection logic now aligns with deployment creation.

The updated logic correctly determines workload type by checking the StorageAttributePersistent attribute in Resources.Storage, which perfectly aligns with the deployment creation logic in the Deploy() method (lines 480-486). This fixes the shell access issue for deployments using non-persistent RAM volumes like SHM mounts.

Key improvements:

  • Proper distinction between persistent and non-persistent storage
  • Consistency between deployment creation and status checking logic
  • Resolves the "statefulsets.apps not found" error for RAM volume workloads
gateway/rest/router.go (1)

375-378: LGTM! WebSocket protocol violation fixed.

The error handling now correctly uses WebSocket writer instead of http.Error() on a WebSocket connection, preventing protocol violations. The implementation properly:

  • Uses LeaseShellCodeFailure for failure communication
  • Disables data encoding to send an empty message
  • Logs errors locally for debugging while preventing information leakage
  • Maintains consistency with similar error handling patterns in the same function

This resolves the WebSocket protocol errors and improves error visibility during shell operations.

cluster/kube/client_test.go (1)

692-840: Excellent comprehensive test coverage for workload type detection.

The new test function thoroughly validates the storage-based workload type detection logic with well-structured table-driven tests covering all critical scenarios:

Test Coverage:

  • ✅ Persistent storage → StatefulSet detection
  • ✅ Non-persistent storage → Deployment detection
  • ✅ No storage → Deployment detection (default)

Implementation Quality:

  • Proper use of SDL storage attribute constants
  • Realistic manifest service configurations
  • Appropriate Kubernetes workload object creation
  • Comprehensive assertions for service name and replica counts
  • Clear test case naming and structure

This test provides strong validation that the shell access fix for SHM-mounted workloads will function correctly and prevents future regressions in workload type detection logic.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 generate unit tests to generate unit tests for 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.

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.

Shell is not accessible when shm is enabled.
1 participant