kloudlite / kl

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

cluster up cmd and box ssh cmd updated #196

Closed nxtcoder36 closed 1 week ago

nxtcoder36 commented 1 week ago

Summary by Sourcery

Update the 'cluster up' and 'box ssh' commands to improve team context management and error handling. Introduce a confirmation step when switching teams and ensure the selected team is saved in the extra data file. Enhance error handling in the K3s server startup process.

Enhancements:

sourcery-ai[bot] commented 1 week ago

Reviewer's Guide by Sourcery

This pull request updates the cluster up command and box ssh command, focusing on team context switching and error handling. The changes improve the user experience by providing a prompt when switching teams and enhance error reporting across multiple files.

Sequence diagram for team context switching in Start() method

sequenceDiagram
    participant User
    participant Client
    participant FileClient
    participant Cluster
    participant APIClient

    User->>Client: Start()
    Client->>FileClient: GetExtraData()
    alt Error
        Client->>User: Return error
    end

    alt Team context switch needed
        Client->>User: Prompt for team switch
        User->>Client: Confirm switch
        Client->>FileClient: SaveExtraData()
        Client->>Cluster: StopK3sServer()
        Client->>APIClient: GetClusterConfig()
        Client->>APIClient: GetAccVPNConfig()
    end

    Client->>Client: startContainer()
    alt Error
        Client->>User: Return error
    end

User journey diagram for team context switching

journey
    title Team Context Switching
    section Start Command
      User: 5: Start command
      System: 4: Check current team
      System: 3: Prompt for team switch if needed
      User: 4: Confirm team switch
      System: 5: Save new team context
      System: 5: Stop K3s server
      System: 5: Fetch cluster and VPN config
    section Up Command
      System: 5: Start K3s server
      System: 4: Check and set team context
      System: 5: Create cluster teams
      User: 5: Receive confirmation of server start

Updated class diagram for client and related functions

classDiagram
    class client {
        +Start() error
    }
    class fileclient {
        +GetExtraData() ExtraData
        +SaveExtraData(data ExtraData) error
    }
    class cluster {
        +StopK3sServer(cmd Command) error
    }
    class apiclient {
        +GetClusterConfig(teamName string) (Config, error)
        +GetAccVPNConfig(teamName string) (Config, error)
    }

    client --> fileclient
    client --> cluster
    client --> apiclient

    class ExtraData {
        +string SelectedTeam
        +map[string]Env SelectedEnvs
    }
    class Env {
        +int SSHPort
    }

File-Level Changes

Change Details Files
Implement team context switching in box start command
  • Add logic to check and update the selected team
  • Prompt user for confirmation when switching teams
  • Stop K3s server when switching teams
  • Fetch new cluster and VPN configurations after team switch
cmd/box/boxpkg/start.go
Enhance error handling and team selection in cluster up command
  • Improve error wrapping using functions.NewE
  • Add logic to handle missing or empty extraData
  • Use selected team from extraData instead of current team
cmd/cluster/up.go
Minor updates to the use team command
  • Add options parameter to UseTeam function
  • Update log message formatting
cmd/use/account.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).