kloudlite / kl

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

refactoring changes done #177

Closed nxtcoder36 closed 1 week ago

nxtcoder36 commented 1 week ago

Summary by Sourcery

Refactor cluster management functions to improve cluster selection and status logging. Enhance the WireGuard connection process by checking local K3s status before execution. Update Docker build tasks to support version tagging and pushing.

Enhancements:

Build:

sourcery-ai[bot] commented 1 week ago

Reviewer's Guide by Sourcery

This pull request implements several refactoring changes across multiple files, focusing on improving the cluster management, connection handling, and overall code structure. The changes include updates to the API client, modifications to the K3s implementation, enhancements to the command-line interface, and adjustments to the build process.

Sequence diagram for getK3sStatus function

sequenceDiagram
    participant Cmd
    participant FC as FileClient
    participant K3sTracker
    participant EnvClient
    participant Connect
    Cmd->>FC: GetK3sTracker()
    alt Error
        Cmd->>Cmd: Log error
        Cmd->>Cmd: Return
    end
    Cmd->>K3sTracker: Check Compute and Gateway
    alt Compute and Gateway are true
        Cmd->>Cmd: Log "Running: true"
    else
        Cmd->>Cmd: Log "Running: false"
    end
    Cmd->>K3sTracker: Check Compute
    alt Compute is true
        Cmd->>Cmd: Log "Local Cluster: ready"
    else
        Cmd->>Cmd: Log "Local Cluster: getting ready"
    end
    Cmd->>K3sTracker: Check Gateway
    alt Gateway is true
        Cmd->>Cmd: Log "Edge Gateway Connection: online"
    else
        Cmd->>Cmd: Log "Edge Gateway Connection: offline"
    end
    Cmd->>EnvClient: InsideBox()
    alt InsideBox is true
        Cmd->>Connect: Check Wireguard Connection
        alt Connection is true
            Cmd->>Cmd: Log "Edge Connection: online"
        else
            Cmd->>Cmd: Log "Edge Connection: offline"
        end
    end

Sequence diagram for startWg function

sequenceDiagram
    participant Cmd
    participant K3sClient
    participant EnvClient
    Cmd->>K3sClient: NewClient()
    alt Error
        Cmd->>Cmd: PrintError
        Cmd->>Cmd: Return
    end
    Cmd->>K3sClient: CheckK3sRunningLocally()
    alt Not Running
        Cmd->>Cmd: Return
    end
    Cmd->>EnvClient: InsideBox()
    alt Not InsideBox
        Cmd->>K3sClient: RestartWgProxyContainer()
        alt Error
            Cmd->>Cmd: PrintError
            Cmd->>Cmd: Return
        end
    end
    Cmd->>Cmd: ExecNoOutput("wg-quick down kl-vpn")
    Cmd->>K3sClient: RestartWgProxyContainer()
    Cmd->>Cmd: ExecNoOutput("wg-quick up kl-workspace-wg")
    Cmd->>Cmd: ExecNoOutput("wg-quick up kl-vpn")
    Cmd->>Cmd: Sleep(1 second)
    Cmd->>Cmd: Open "/tmp/kl/online.status"

Updated class diagram for Cluster and BYOKCluster

classDiagram
    class Cluster {
        +string DisplayName
        +string ClusterToken
        +string Name
        +time.Time LastOnlineAt
        +InstallCommand InstallCommand
        +map Metadata
    }
    class BYOKCluster {
        +string DisplayName
        +Metadata Metadata
    }
    class InstallCommand {
        +map Metadata
    }
    Cluster --> InstallCommand
    Cluster --> Metadata
    BYOKCluster --> Metadata

File-Level Changes

Change Details Files
Refactoring of cluster management and API client
  • Commented out BYOKCluster related code
  • Updated Cluster struct with new fields
  • Renamed and modified getClustersOfTeam function
  • Updated selectCluster function to use new Cluster type
  • Modified GetClusterConfig to use the updated GetClustersOfTeam function
domain/apiclient/clusters.go
domain/apiclient/k3s-local.go
domain/apiclient/impl.go
cmd/clone/env.go
Enhancements to the command-line interface
  • Added cluster status information to the status command
  • Improved error handling and output in the status command
  • Updated connection status messages
  • Modified the connect command to handle multiple scenarios
cmd/status/status.go
cmd/connect/connect.go
Updates to K3s implementation and container management
  • Added CheckK3sRunningLocally function to verify K3s container status
  • Updated K3sClient interface with new method
  • Modified startWg function to include additional checks and operations
k3s/impl.go
k3s/main.go
cmd/connect/connect.go
Build process and versioning updates
  • Modified container build and push tasks in Runfile.yml
  • Updated K3s image name to use version from flags
  • Added VERSION build argument to Docker build command
k3s/k3s-base/Runfile.yml
constants/main.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).