-
Notifications
You must be signed in to change notification settings - Fork 359
/
enter.go
65 lines (55 loc) · 1.89 KB
/
enter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package cmd
import (
"github.com/covexo/devspace/pkg/devspace/kubectl"
"github.com/covexo/devspace/pkg/devspace/services"
"github.com/covexo/devspace/pkg/util/log"
"github.com/spf13/cobra"
"k8s.io/client-go/kubernetes"
)
// EnterCmd is a struct that defines a command call for "enter"
type EnterCmd struct {
flags *EnterCmdFlags
kubectl *kubernetes.Clientset
}
// EnterCmdFlags are the flags available for the enter-command
type EnterCmdFlags struct {
container string
namespace string
labelSelector string
}
func init() {
cmd := &EnterCmd{
flags: &EnterCmdFlags{},
}
cobraCmd := &cobra.Command{
Use: "enter",
Short: "Enter your DevSpace",
Long: `
#######################################################
################## devspace enter #####################
#######################################################
Execute a command or start a new terminal in your
devspace:
devspace enter
devspace enter bash
devspace enter -c myContainer
devspace enter bash -n my-namespace
devspace enter bash -l release=test
#######################################################`,
Run: cmd.Run,
}
rootCmd.AddCommand(cobraCmd)
cobraCmd.Flags().StringVarP(&cmd.flags.container, "container", "c", "", "Container name within pod where to execute command")
cobraCmd.Flags().StringVarP(&cmd.flags.namespace, "namespace", "n", "", "Namespace where to select pods")
cobraCmd.Flags().StringVarP(&cmd.flags.labelSelector, "label-selector", "l", "", "Comma separated key=value selector list (e.g. release=test)")
}
// Run executes the command logic
func (cmd *EnterCmd) Run(cobraCmd *cobra.Command, args []string) {
var err error
log.StartFileLogging()
cmd.kubectl, err = kubectl.NewClient()
if err != nil {
log.Fatalf("Unable to create new kubectl client: %v", err)
}
services.StartTerminal(cmd.kubectl, cmd.flags.container, cmd.flags.labelSelector, cmd.flags.namespace, args, log.GetInstance())
}