From b36e4d2c07ed1c852d49193025e299036706d693 Mon Sep 17 00:00:00 2001 From: yovafeng Date: Fri, 16 Jun 2023 14:35:35 +0800 Subject: [PATCH 1/3] =?UTF-8?q?minor:=20cluster=E5=91=BD=E4=BB=A4=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E4=B8=BAconsole?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/command.go | 2 +- cmd/{cluster.go => console.go} | 10 +++++----- cmd/{cluster_test.go => console_test.go} | 22 +++++++++++----------- 3 files changed, 17 insertions(+), 17 deletions(-) rename cmd/{cluster.go => console.go} (92%) rename cmd/{cluster_test.go => console_test.go} (69%) diff --git a/cmd/command.go b/cmd/command.go index 3a308d0..0330bf4 100644 --- a/cmd/command.go +++ b/cmd/command.go @@ -52,7 +52,7 @@ func NewBaseCommand() *BaseCommand { baseCmd := &BaseCommand{ command: cli.rootCmd, } - baseCmd.AddCommands(&ClusterCmd{}) + baseCmd.AddCommands(&ConsoleCmd{}) baseCmd.AddCommands(&DownloadCmd{}) baseCmd.AddCommands(&UploadCmd{}) return baseCmd diff --git a/cmd/cluster.go b/cmd/console.go similarity index 92% rename from cmd/cluster.go rename to cmd/console.go index 06391cd..ce4721d 100644 --- a/cmd/cluster.go +++ b/cmd/console.go @@ -29,23 +29,23 @@ import ( var CMDS = []string{"sh", "bash"} -type ClusterCmd struct { +type ConsoleCmd struct { BaseCommand } -func (cl *ClusterCmd) Init() { +func (cl *ConsoleCmd) Init() { cl.command = &cobra.Command{ - Use: "cluster", + Use: "console", Short: "Exec a command for a container incluster.", Long: "Exec a command for a container incluster.", RunE: func(cmd *cobra.Command, args []string) error { - return cl.runCluster(cmd, args) + return cl.runConsole(cmd, args) }, } cl.command.DisableFlagsInUseLine = true } -func (cl ClusterCmd) runCluster(cmd *cobra.Command, args []string) error { +func (cl ConsoleCmd) runConsole(cmd *cobra.Command, args []string) error { // call utils get pods pods := ListAllPods() selectpod := SelectUI(pods, "select a pod") diff --git a/cmd/cluster_test.go b/cmd/console_test.go similarity index 69% rename from cmd/cluster_test.go rename to cmd/console_test.go index 2498914..c085185 100644 --- a/cmd/cluster_test.go +++ b/cmd/console_test.go @@ -27,22 +27,22 @@ import ( "github.com/stretchr/testify/assert" ) -func TestClusterCmd_Init(t *testing.T) { +func TestConsoleCmd_Init(t *testing.T) { // Create a mock BaseCommand baseCmd := &BaseCommand{} - // Create a ClusterCmd with the mock BaseCommand - clusterCmd := &ClusterCmd{ + // Create a ConsoleCmd with the mock BaseCommand + ConsoleCmd := &ConsoleCmd{ BaseCommand: *baseCmd, } - // Call Init on the ClusterCmd - clusterCmd.Init() + // Call Init on the ConsoleCmd + ConsoleCmd.Init() - // Check that the ClusterCmd's command has the expected Use, Short, and Long fields - assert.Equal(t, "cluster", clusterCmd.command.Use) - assert.Equal(t, "Exec a command for a container incluster.", clusterCmd.command.Short) - assert.Equal(t, "Exec a command for a container incluster.", clusterCmd.command.Long) - assert.True(t, clusterCmd.command.DisableFlagsInUseLine) - assert.NotNil(t, clusterCmd.command.RunE) + // Check that the ConsoleCmd's command has the expected Use, Short, and Long fields + assert.Equal(t, "cluster", ConsoleCmd.command.Use) + assert.Equal(t, "Exec a command for a container incluster.", ConsoleCmd.command.Short) + assert.Equal(t, "Exec a command for a container incluster.", ConsoleCmd.command.Long) + assert.True(t, ConsoleCmd.command.DisableFlagsInUseLine) + assert.NotNil(t, ConsoleCmd.command.RunE) } From 8a10e8e672b2aa059ccbc339a46bc7b807cf4294 Mon Sep 17 00:00:00 2001 From: yovafeng Date: Fri, 16 Jun 2023 14:43:18 +0800 Subject: [PATCH 2/3] =?UTF-8?q?document:=20readme=E6=8F=90=E4=BE=9Bdownloa?= =?UTF-8?q?d&upload=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7a34ab9..abd994c 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,9 @@ # kconsole -kconsole 是一个用于快速进入 Kubernetes 集群容器终端的命令行工具。它使用 client-go 来获取 Kubernetes 集群中的 Pod 和容器信息,并使用 exec 命令进入容器终端。 + +kconsole 是一个用于与提高 Kubernetes 集群容器交互效率的命令行工具。它使用client-go 来与 Kubernetes 集群交互,提供快速进入容器终端、下载容器文件、上传本地文件到容器等便捷功能。 ## 使用 -要使用 kconsole 进入 Kubernetes 集群中的容器终端,请按照以下步骤操作: +以 console 子命令为例,要使用 kconsole 进入 Kubernetes 集群中的容器终端,请按照以下步骤操作: ### 1 下载 kconsole 可执行文件。 您可以从 GitHub Releases 页面 下载最新版本的 kconsole。 @@ -20,7 +21,7 @@ export PATH=$PATH:/usr/local/bin 在命令行中运行以下命令: ``` -kconsole cluster +kconsole console ``` 这将显示一个交互式菜单,列出了 Kubernetes 集群中的所有 Pod以及它们所在的namespace。 @@ -37,6 +38,13 @@ kconsole 支持以下选项: -h, --help: 显示帮助信息。 +## 子命令 +kconsole 提供以下子命令: + +console: 进入集群中的容器终端 +download: 下载集群中的容器内文件 +upload: 上传本地文件到集群中的容器 + ## 开发 如果您想要为 kconsole 做出贡献,或者想要构建自己的版本,请按照以下步骤操作: From bf5ea0c881d24dbd63846637732481703fe1de85 Mon Sep 17 00:00:00 2001 From: yovafeng Date: Fri, 16 Jun 2023 14:45:16 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/console_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/console_test.go b/cmd/console_test.go index c085185..b8210d8 100644 --- a/cmd/console_test.go +++ b/cmd/console_test.go @@ -40,7 +40,7 @@ func TestConsoleCmd_Init(t *testing.T) { ConsoleCmd.Init() // Check that the ConsoleCmd's command has the expected Use, Short, and Long fields - assert.Equal(t, "cluster", ConsoleCmd.command.Use) + assert.Equal(t, "console", ConsoleCmd.command.Use) assert.Equal(t, "Exec a command for a container incluster.", ConsoleCmd.command.Short) assert.Equal(t, "Exec a command for a container incluster.", ConsoleCmd.command.Long) assert.True(t, ConsoleCmd.command.DisableFlagsInUseLine)