-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add exec support Signed-off-by: ysicing <[email protected]>
- Loading branch information
Showing
11 changed files
with
156 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.0.9 | ||
1.0.10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright (c) 2021-2022 北京渠成软件有限公司(Beijing Qucheng Software Co., Ltd. www.qucheng.com) All rights reserved. | ||
// Use of this source code is covered by the following dual licenses: | ||
// (1) Z PUBLIC LICENSE 1.2 (ZPL 1.2) | ||
// (2) Affero General Public License 3.0 (AGPL 3.0) | ||
// license that can be found in the LICENSE file. | ||
|
||
package manage | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/easysoft/qcadmin/internal/app/debug" | ||
"github.com/easysoft/qcadmin/internal/pkg/k8s" | ||
"github.com/easysoft/qcadmin/internal/pkg/util/factory" | ||
"github.com/manifoldco/promptui" | ||
"github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/labels" | ||
) | ||
|
||
func NewCmdExecApp(f factory.Factory) *cobra.Command { | ||
log := f.GetLog() | ||
app := &cobra.Command{ | ||
Use: "app", | ||
Aliases: []string{"apps"}, | ||
Short: "exec app", | ||
Args: cobra.ExactArgs(1), | ||
Example: `q exec app http://console.efbb.haogs.cn/instance-view-39.html`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
url := args[0] | ||
apidebug := log.GetLevel() == logrus.DebugLevel | ||
log.Infof("start exec app: %s", url) | ||
appdata, err := debug.GetNameByURL(url, apidebug) | ||
if err != nil { | ||
return err | ||
} | ||
k8sClient, err := k8s.NewSimpleClient() | ||
if err != nil { | ||
log.Errorf("k8s client err: %v", err) | ||
return err | ||
} | ||
ctx := context.Background() | ||
podlist, _ := k8sClient.ListPods(ctx, "default", metav1.ListOptions{ | ||
LabelSelector: labels.SelectorFromSet(map[string]string{ | ||
"release": appdata.K8Name, | ||
}).String(), | ||
}) | ||
if len(podlist.Items) < 1 { | ||
return fmt.Errorf("podnum %d, app maybe not running", len(podlist.Items)) | ||
} | ||
templates := &promptui.SelectTemplates{ | ||
Label: "{{ . }}?", | ||
Active: "\U0001F44F {{ .Name | cyan }}", | ||
Inactive: " {{ .Name | cyan }}", | ||
Selected: "\U0001F31D {{ .Name | red | cyan }}", | ||
} | ||
|
||
prompt := promptui.Select{ | ||
Label: "select pod", | ||
Items: podlist.Items, | ||
Templates: templates, | ||
Size: 5, | ||
} | ||
it, _, _ := prompt.Run() | ||
|
||
return k8sClient.ExecPodWithTTY(ctx, "default", podlist.Items[it].Name, podlist.Items[it].Spec.Containers[0].Name, []string{"/bin/sh", "-c", "sh"}) | ||
}, | ||
} | ||
return app | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters