/
argo.go
56 lines (45 loc) · 1.14 KB
/
argo.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
package cmd
import (
"fmt"
"os"
"os/exec"
"os/signal"
"strings"
"syscall"
"github.com/spf13/cobra"
)
var argoCmd = &cobra.Command{
Use: "argo",
Short: "Port forward to Argo and show login info",
RunE: func(cmd *cobra.Command, args []string) error {
podName, err := exec.Command("kubectl", "get", "pods", "-n=argocd", "-l=app.kubernetes.io/name=argocd-server", "-o=name").Output()
if err != nil {
return err
}
password := strings.TrimSpace(string(podName))
fmt.Println("")
fmt.Println("Username: admin")
fmt.Println(fmt.Sprintf("Password: %s", password))
portForwardCmd := exec.Command("kubectl", "port-forward", "svc/argocd-server", "-n=argocd", "8080:443")
err = portForwardCmd.Start()
if err != nil {
return err
}
defer portForwardCmd.Process.Signal(syscall.SIGTERM)
fmt.Println("")
fmt.Println("Argo running at https://localhost:8080/")
fmt.Println("")
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
for range c {
fmt.Println("")
fmt.Println("Received SIGINT, cleaning up...")
fmt.Println("")
return nil
}
return nil
},
}
func init() {
rootCmd.AddCommand(argoCmd)
}