kloudlite / kl

Kloudlite CLI Client
GNU Affero General Public License v3.0
5 stars 1 forks source link

Fix/app intercept #172

Closed nxtcoder36 closed 2 weeks ago

nxtcoder36 commented 2 weeks ago

Summary by Sourcery

Refactor the application intercept service to improve port management and error handling. Enhance the Wireguard connection verification process and update status messages for better user feedback. Fix issues related to k3s server readiness checks.

Bug Fixes:

Enhancements:

sourcery-ai[bot] commented 2 weeks ago

Reviewer's Guide by Sourcery

This pull request implements several changes to improve the functionality and reliability of the application's intercept service, K3s tracking, and VPN connection. Key modifications include refactoring the StartAppInterceptService function, updating the K3sTracker structure, improving error handling, and enhancing the overall connection status checks.

Sequence diagram for StartAppInterceptService function

sequenceDiagram
    participant Client
    participant Spinner
    participant K3sTracker
    participant FileClient
    participant Container
    Client->>Spinner: UpdateMessage("starting intercept service")
    Client->>K3sTracker: GetK3sTracker()
    K3sTracker-->>Client: k3sTracker
    Client->>FileClient: Create newPorts
    alt toStart is true
        FileClient-->>Client: Error if port is occupied
    end
    Client->>Container: runScriptInContainer()

Sequence diagram for startWg function

sequenceDiagram
    participant StartWg
    participant K3sClient
    participant EnvClient
    StartWg->>K3sClient: RestartWgProxyContainer()
    alt InsideBox is false
        K3sClient-->>StartWg: Return
    end
    StartWg->>EnvClient: CheckWireguardConnection()
    EnvClient-->>StartWg: Connection status
    alt Connection is not established
        StartWg->>EnvClient: ExecNoOutput("wg-quick down kl-workspace-wg")
        StartWg->>EnvClient: ExecNoOutput("wg-quick up kl-workspace-wg")
        StartWg->>EnvClient: Check online status
    end
    StartWg->>StartWg: Log device connected

Updated class diagram for k3sTracker structure

classDiagram
    class k3sTracker {
        bool Compute
        bool Gateway
        DeviceRouter DeviceRouter
        string LastCheckedAt
    }
    class DeviceRouter {
        string IP
        Service Service
    }
    class Service {
        Spec Spec
    }
    class Spec {
        list~Port~ Ports
    }
    class Port {
        string Name
        int Port
        string Protocol
        int TargetPort
    }
    k3sTracker --> DeviceRouter
    DeviceRouter --> Service
    Service --> Spec
    Spec --> Port

File-Level Changes

Change Details Files
Refactored StartAppInterceptService function to handle port management more efficiently
  • Added a 'toStart' boolean parameter to control whether to start or stop the intercept
  • Implemented logic to check for existing ports and handle conflicts
  • Added support for UDP and TCP protocols for each port
  • Improved error handling and readiness checks
k3s/impl.go
Updated K3sTracker structure and related functions
  • Modified K3sTracker to include more detailed information about the device router
  • Updated functions to work with the new K3sTracker structure
  • Improved error handling and readiness checks in K3s-related functions
domain/fileclient/context.go
k3s/k3s-tracker/main.go
Enhanced VPN connection and status checking
  • Implemented ChekcWireguardConnection function to verify VPN connectivity
  • Updated status command to provide more accurate connection status information
  • Improved error handling and user feedback for VPN-related operations
cmd/connect/connect.go
cmd/status/status.go
Implemented RemoveAllIntercepts function
  • Added RemoveAllIntercepts function to K3sClient interface
  • Implemented logic to remove all intercepts and clean up related resources
  • Updated relevant commands to use the new RemoveAllIntercepts function
k3s/impl.go
cmd/clone/env.go
cmd/use/env.go
Refactored and improved error handling throughout the codebase
  • Updated error messages to provide more context and clarity
  • Implemented consistent error handling patterns across multiple files
  • Added additional error checks and improved error propagation
k3s/impl.go
domain/apiclient/app.go
cmd/intercept/intercept.go

Tips and commands #### Interacting with Sourcery - **Trigger a new review:** Comment `@sourcery-ai review` on the pull request. - **Continue discussions:** Reply directly to Sourcery's review comments. - **Generate a GitHub issue from a review comment:** Ask Sourcery to create an issue from a review comment by replying to it. - **Generate a pull request title:** Write `@sourcery-ai` anywhere in the pull request title to generate a title at any time. - **Generate a pull request summary:** Write `@sourcery-ai summary` anywhere in the pull request body to generate a PR summary at any time. You can also use this command to specify where the summary should be inserted. #### Customizing Your Experience Access your [dashboard](https://app.sourcery.ai) to: - Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others. - Change the review language. - Add, remove or edit custom review instructions. - Adjust other review settings. #### Getting Help - [Contact our support team](mailto:support@sourcery.ai) for questions or feedback. - Visit our [documentation](https://docs.sourcery.ai) for detailed guides and information. - Keep in touch with the Sourcery team by following us on [X/Twitter](https://x.com/SourceryAI), [LinkedIn](https://www.linkedin.com/company/sourcery-ai/) or [GitHub](https://github.com/sourcery-ai).