kloudlite / kl

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

Impl/cmd expose port #205

Closed nxtcoder36 closed 7 hours ago

nxtcoder36 commented 7 hours ago

Summary by Sourcery

Add a new 'expose' command to manage port exposure in the kl-config file, including functionality to add and sync ports. Refactor the SyncProxy function to utilize the command context for Docker operations, enhancing code clarity. Clean up code by removing redundant print statements.

New Features:

Enhancements:

Chores:

sourcery-ai[bot] commented 7 hours ago

Reviewer's Guide by Sourcery

This pull request implements port exposure functionality for the Kloudlite CLI tool. It adds new commands to expose and sync ports, updates the proxy synchronization logic, and makes necessary adjustments to support these features.

Sequence diagram for SyncProxy function

sequenceDiagram
    participant User
    participant CLI as Kloudlite CLI
    participant Docker
    User->>CLI: Run expose port command
    CLI->>CLI: Create file client
    CLI->>CLI: Get current working directory
    CLI->>CLI: Get Kloudlite config file
    CLI->>CLI: Add ports to config file
    CLI->>CLI: Write updated config file
    CLI->>Docker: List existing proxy containers
    alt Existing proxy with same port hash
        CLI->>User: Return (no action needed)
    else No existing proxy or different port hash
        CLI->>Docker: Kill and remove existing proxy container
        CLI->>Docker: Create new proxy container with exposed ports
        CLI->>Docker: Start new proxy container
    end
    CLI->>User: Return success or error

Updated class diagram for ProxyConfig and client

classDiagram
    class ProxyConfig {
        +GetHash() string
        +ExposedPorts []int
        +TargetContainerPath string
    }
    class client {
        +SyncProxy(config ProxyConfig) error
        +Stop() error
        +Restart() error
        +Start() error
    }
    class KLFileType {
        +EnvVars EnvVars
        +Mounts Mounts
        +Ports []int
        +TeamName string
    }
    class fileclient {
        +New() fileclient
        +GetKlFile(path string) (KLFileType, error)
        +WriteKLFile(file KLFileType) error
    }
    ProxyConfig --> client
    KLFileType --> fileclient

File-Level Changes

Change Details Files
Implement port exposure functionality
  • Add 'expose' command with 'port' and 'sync' subcommands
  • Implement logic to add and sync exposed ports
  • Update KLFileType struct to include Ports field
  • Add SocatImage constant
cmd/expose/port.go
cmd/expose/sync.go
cmd/expose/expose.go
domain/fileclient/kl-file.go
constants/main.go
Uncomment and update SyncProxy function
  • Uncomment SyncProxy function in BoxClient interface
  • Update SyncProxy function to use c.cmd.Context()
  • Add error handling and container management logic
cmd/box/boxpkg/proxy.go
cmd/box/boxpkg/main.go
Update CLI command structure
  • Add 'expose' command to root command
  • Update 'Local Cluster' status message
clis/kl/loadsubs.go
cmd/status/status.go
Minor code improvements and cleanup
  • Remove debug print statements
  • Update error messages and logging
pkg/updater/main.go
clis/kl/update.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).