diff --git a/cmd/command/plural/plural.go b/cmd/command/plural/plural.go index 434fc7cc8..51a8e7cc1 100644 --- a/cmd/command/plural/plural.go +++ b/cmd/command/plural/plural.go @@ -54,40 +54,6 @@ func (p *Plural) getCommands() []cli.Command { Action: common.LatestVersion(common.HandleScaffold), Category: "Workspace", }, - { - Name: "watch", - Usage: "watches applications until they become ready", - ArgsUsage: "REPO", - Action: common.LatestVersion(common.InitKubeconfig(common.RequireArgs(common.HandleWatch, []string{"REPO"}))), - Category: "Debugging", - }, - { - Name: "wait", - Usage: "waits on applications until they become ready", - ArgsUsage: "REPO", - Action: common.LatestVersion(common.RequireArgs(common.HandleWait, []string{"REPO"})), - Category: "Debugging", - }, - { - Name: "info", - Usage: "generates a console dashboard for the namespace of this repo", - ArgsUsage: "REPO", - Action: common.LatestVersion(common.RequireArgs(common.HandleInfo, []string{"REPO"})), - Category: "Debugging", - }, - { - Name: "apply", - Usage: "applys the current pluralfile", - Flags: []cli.Flag{ - cli.StringFlag{ - Name: "file, f", - Usage: "pluralfile to use", - }, - }, - Action: common.LatestVersion(common.Apply), - Category: "Publishing", - }, - { Name: "readme", Aliases: []string{"b"}, diff --git a/cmd/command/vpn/vpn.go b/cmd/command/vpn/vpn.go index b7599593f..1c9bef2b6 100644 --- a/cmd/command/vpn/vpn.go +++ b/cmd/command/vpn/vpn.go @@ -23,10 +23,9 @@ import ( ) const ( - wireguardAppName = "wireguard" - wireguardNamespace = "wireguard" - wireguardServerName = "wireguard" - wireguardNotInstalledError = "wireguard is not installed. run `plural bundle list wireguard` to find the bundle to install" + wireguardAppName = "wireguard" + wireguardNamespace = "wireguard" + wireguardServerName = "wireguard" ) type Plural struct { diff --git a/pkg/common/app.go b/pkg/common/app.go index 127dbb67f..77287f691 100644 --- a/pkg/common/app.go +++ b/pkg/common/app.go @@ -7,47 +7,12 @@ import ( "github.com/pluralsh/plural-cli/pkg/up" - tm "github.com/buger/goterm" "github.com/urfave/cli" - "github.com/pluralsh/plural-cli/pkg/application" "github.com/pluralsh/plural-cli/pkg/config" - "github.com/pluralsh/plural-cli/pkg/kubernetes" "github.com/pluralsh/plural-cli/pkg/utils" - - "sigs.k8s.io/application/api/v1beta1" ) -func HandleWatch(c *cli.Context) error { - repo := c.Args().Get(0) - kubeConf, err := kubernetes.KubeConfig() - if err != nil { - return err - } - kube, err := kubernetes.Kubernetes() - if err != nil { - return err - } - - timeout := func() error { return nil } - return application.Waiter(kubeConf, repo, func(app *v1beta1.Application) (bool, error) { - tm.MoveCursor(1, 1) - application.Print(kube.GetClient(), app) - application.Flush() - return false, nil - }, timeout) -} - -func HandleWait(c *cli.Context) error { - repo := c.Args().Get(0) - kubeConf, err := kubernetes.KubeConfig() - if err != nil { - return err - } - - return application.Wait(kubeConf, repo) -} - func HandleInfo(c *cli.Context) error { repo := c.Args().Get(0) conf := config.Read() diff --git a/pkg/proxy/database.go b/pkg/proxy/database.go deleted file mode 100644 index e018640fd..000000000 --- a/pkg/proxy/database.go +++ /dev/null @@ -1,67 +0,0 @@ -package proxy - -import ( - "fmt" - "os" - "os/exec" - "time" - - "github.com/pluralsh/plural-cli/pkg/kubernetes/portforward" - "github.com/pluralsh/plural-cli/pkg/utils" - "github.com/pluralsh/plural-operator/apis/platform/v1alpha1" -) - -type postgres struct { - Proxy *v1alpha1.Proxy - Pwd string -} - -type dbConnection interface { - Connect(namespace string) error -} - -func buildConnection(secret string, proxy *v1alpha1.Proxy) (dbConnection, error) { - switch proxy.Spec.DbConfig.Engine { - case "postgres": - return &postgres{Pwd: secret, Proxy: proxy}, nil - default: - return nil, fmt.Errorf("Unsupported engine %s", proxy.Spec.DbConfig.Engine) - } -} - -func (pg *postgres) Connect(namespace string) error { - err := portForward(namespace, pg.Proxy, pg.Proxy.Spec.DbConfig.Port) - if err != nil { - return err - } - - utils.Highlight("Wait a bit while the port-forward boots up\n") - time.Sleep(5 * time.Second) - cmd := exec.Command("psql", fmt.Sprintf("host=127.0.0.1 sslmode=allow user=%s dbname=%s", pg.Proxy.Spec.Credentials.User, pg.Proxy.Spec.DbConfig.Name)) - cmd.Env = os.Environ() - cmd.Env = append(cmd.Env, fmt.Sprintf("PGPASSWORD=%s", pg.Pwd)) - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - cmd.Stdin = os.Stdin - return cmd.Run() -} - -func portForward(namespace string, proxy *v1alpha1.Proxy, port int32) error { - errorChan := make(chan error, 1) - stopChan, readyChan := make(chan struct{}, 1), make(chan struct{}) - var err error - go func() { - err = portforward.PortForward(namespace, proxy.Spec.Target, []string{fmt.Sprint(port)}, stopChan, readyChan) - errorChan <- err - }() - - select { - case <-readyChan: - break - case <-errorChan: - close(stopChan) - close(errorChan) - break - } - return err -} diff --git a/pkg/proxy/proxy.go b/pkg/proxy/proxy.go deleted file mode 100644 index 18582c1b0..000000000 --- a/pkg/proxy/proxy.go +++ /dev/null @@ -1,47 +0,0 @@ -package proxy - -import ( - "fmt" - - "github.com/pluralsh/plural-cli/pkg/kubernetes" - "github.com/pluralsh/plural-cli/pkg/utils" - "github.com/pluralsh/plural-operator/apis/platform/v1alpha1" -) - -func List(kube kubernetes.Kube, namespace string) (*v1alpha1.ProxyList, error) { - return kube.ProxyList(namespace) -} - -func Print(l *v1alpha1.ProxyList) error { - headers := []string{"Name", "Type", "Target"} - return utils.PrintTable[v1alpha1.Proxy](l.Items, headers, func(p v1alpha1.Proxy) ([]string, error) { - return []string{p.Name, string(p.Spec.Type), p.Spec.Target}, nil - }) -} - -func Exec(kube kubernetes.Kube, namespace string, name string) error { - proxy, err := kube.Proxy(namespace, name) - if err != nil { - return err - } - - t := proxy.Spec.Type - switch t { - case v1alpha1.Db: - secret, err := fetchSecret(namespace, kube, proxy.Spec.Credentials) - if err != nil { - return err - } - conn, err := buildConnection(secret, proxy) - if err != nil { - return err - } - return conn.Connect(namespace) - case v1alpha1.Sh: - return execShell(namespace, proxy) - case v1alpha1.Web: - return execWeb(namespace, proxy, kube) - default: - return fmt.Errorf("Unhandled proxy type %s", t) - } -} diff --git a/pkg/proxy/secret.go b/pkg/proxy/secret.go deleted file mode 100644 index 40289ec6a..000000000 --- a/pkg/proxy/secret.go +++ /dev/null @@ -1,55 +0,0 @@ -package proxy - -import ( - "fmt" - - "github.com/pluralsh/plural-cli/pkg/kubernetes" - "github.com/pluralsh/plural-operator/apis/platform/v1alpha1" - - v1 "k8s.io/api/core/v1" -) - -type UserCredentials struct { - User string - Password string -} - -func fetchSecret(namespace string, k kubernetes.Kube, creds *v1alpha1.Credentials) (string, error) { - secret, err := k.Secret(namespace, creds.Secret) - if err != nil { - return "", err - } - - val, ok := secret.Data[creds.Key] - if !ok { - return "", fmt.Errorf("Could not find credential key") - } - - return string(val), nil -} - -func fetchUserPassword(secret *v1.Secret, creds *v1alpha1.Credentials) (user *UserCredentials, err error) { - pwd, ok := secret.Data[creds.Key] - if !ok { - err = fmt.Errorf("Could not find password key") - return - } - - username := creds.User - if creds.UserKey != "" { - uname, ok := secret.Data[creds.UserKey] - if !ok { - err = fmt.Errorf("Could not find password key") - return - } - username = string(uname) - } - - if username == "" { - err = fmt.Errorf("No username found") - return - } - - user = &UserCredentials{User: username, Password: string(pwd)} - return -} diff --git a/pkg/proxy/shell.go b/pkg/proxy/shell.go deleted file mode 100644 index 6941446f9..000000000 --- a/pkg/proxy/shell.go +++ /dev/null @@ -1,18 +0,0 @@ -package proxy - -import ( - "github.com/pluralsh/plural-cli/pkg/kubernetes/exec" - "github.com/pluralsh/plural-operator/apis/platform/v1alpha1" -) - -func execShell(namespace string, proxy *v1alpha1.Proxy) error { - shell := proxy.Spec.ShConfig - var rest []string - if len(shell.Command) > 0 { - rest = append([]string{shell.Command}, shell.Args...) - } else { - rest = []string{"/bin/sh"} - } - - return exec.Exec(namespace, proxy.Spec.Target, rest) -} diff --git a/pkg/proxy/web.go b/pkg/proxy/web.go deleted file mode 100644 index 1cb2ebc45..000000000 --- a/pkg/proxy/web.go +++ /dev/null @@ -1,56 +0,0 @@ -package proxy - -import ( - "fmt" - "time" - - "github.com/pluralsh/plural-cli/pkg/kubernetes" - "github.com/pluralsh/plural-cli/pkg/utils" - "github.com/pluralsh/plural-operator/apis/platform/v1alpha1" -) - -func execWeb(namespace string, proxy *v1alpha1.Proxy, kube kubernetes.Kube) error { - config := proxy.Spec.WebConfig - err := portForward(namespace, proxy, config.Port) - if err != nil { - return err - } - - utils.Highlight("Wait a bit while the port-forward boots up\n\n") - time.Sleep(5 * time.Second) - - if err := printCredentials(proxy, namespace, kube); err != nil { - return err - } - fmt.Printf("\nVisit http://localhost:%d%s\n", config.Port, config.Path) - if _, err := utils.ReadLine("Press enter to close the proxy"); err != nil { - return err - } - return nil -} - -func printCredentials(proxy *v1alpha1.Proxy, namespace string, kube kubernetes.Kube) error { - creds := proxy.Spec.Credentials - if creds == nil { - return nil - } - - secret, err := kube.Secret(namespace, creds.Secret) - if err != nil { - return err - } - user, err := fetchUserPassword(secret, creds) - if err != nil { - return err - } - - highlightedEntry("Username", user.User) - highlightedEntry("Password", user.Password) - - return nil -} - -func highlightedEntry(label, value string) { - utils.Highlight(label + ": ") - fmt.Println(value) -}