Skip to content
Merged

Fixes #324

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/devspace/helm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ func createNewClient(kubectlClient *kubernetes.Clientset, log log.Logger, upgrad
os.MkdirAll(repoPath, os.ModePerm)
os.MkdirAll(filepath.Dir(stableRepoCachePathAbs), os.ModePerm)

_, repoFileNotFound := os.Stat(repoFile)
if repoFileNotFound != nil {
repoFileStat, repoFileNotFound := os.Stat(repoFile)
if repoFileNotFound != nil || repoFileStat.Size() == 0 {
err = fsutil.WriteToFile([]byte(defaultRepositories), repoFile)
if err != nil {
return nil, err
Expand Down
28 changes: 2 additions & 26 deletions pkg/devspace/kubectl/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"errors"
"fmt"
"github.com/covexo/devspace/pkg/util/terminal"
"io"
"net/http"
"os"
Expand All @@ -16,7 +17,6 @@ import (
"github.com/covexo/devspace/pkg/devspace/config/configutil"
"github.com/covexo/devspace/pkg/devspace/config/v1"
"github.com/covexo/devspace/pkg/util/log"
dockerterm "github.com/docker/docker/pkg/term"
k8sv1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
Expand Down Expand Up @@ -413,7 +413,7 @@ func Exec(kubectlClient *kubernetes.Clientset, pod *k8sv1.Pod, container string,
SubResource("exec")

if tty {
t = setupTTY()
t = terminal.SetupTTY()
}

execRequest.VersionedParams(&k8sapi.PodExecOptions{
Expand Down Expand Up @@ -475,30 +475,6 @@ func Exec(kubectlClient *kubernetes.Clientset, pod *k8sv1.Pod, container string,
return stdinWriter, stdoutReader, stderrReader, nil
}

func setupTTY() term.TTY {
t := term.TTY{
Out: os.Stdout,
In: os.Stdin,
}

if !t.IsTerminalIn() {
log.Info("Unable to use a TTY - input is not a terminal or the right kind of file")

return t
}

// if we get to here, the user wants to attach stdin, wants a TTY, and In is a terminal, so we
// can safely set t.Raw to true
t.Raw = true

stdin, stdout, _ := dockerterm.StdStreams()

t.In = stdin
t.Out = stdout

return t
}

//ExecBuffered executes a command for kubernetes and returns the output and error buffers
func ExecBuffered(kubectlClient *kubernetes.Clientset, pod *k8sv1.Pod, container string, command []string) ([]byte, []byte, error) {
_, stdout, stderr, execErr := Exec(kubectlClient, pod, container, command, false, nil)
Expand Down
25 changes: 23 additions & 2 deletions pkg/util/log/loading_text.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ import (
"io"
"time"

"github.com/covexo/devspace/pkg/util/terminal"

"github.com/daviddengcn/go-colortext"
)

const waitInterval = time.Millisecond * 150

var tty = terminal.SetupTTY()

type loadingText struct {
Stream io.Writer
Message string
Expand Down Expand Up @@ -71,13 +75,30 @@ func (l *loadingText) render() {
} else {
l.Stream.Write([]byte("\r"))
}
messagePrefix := []byte("[WAIT] ")

ct.Foreground(ct.Red, false)
l.Stream.Write([]byte("[WAIT] "))
l.Stream.Write(messagePrefix)
ct.ResetColor()

timeElapsed := fmt.Sprintf("%d", (time.Now().UnixNano()-l.startTimestamp)/int64(time.Second))
l.Stream.Write([]byte(l.getLoadingChar() + " " + l.Message + " (" + timeElapsed + "s)"))
message := []byte(l.getLoadingChar() + " " + l.Message)
messageSuffix := " (" + timeElapsed + "s)"
terminalSize := tty.GetSize()
prefixLength := len(messagePrefix)
suffixLength := len(messageSuffix)

if uint16(prefixLength+len(message)+suffixLength) > terminalSize.Width {
dots := []byte("...")
maxMessageLength := terminalSize.Width - uint16(prefixLength+suffixLength+len(dots))

if maxMessageLength > 0 {
message = append(message[:maxMessageLength], dots...)
}
}
message = append(message, messageSuffix...)

l.Stream.Write(message)
}

func (l *loadingText) Stop() {
Expand Down
31 changes: 31 additions & 0 deletions pkg/util/terminal/tty.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package terminal

import (
"os"

dockerterm "github.com/docker/docker/pkg/term"
"k8s.io/kubernetes/pkg/kubectl/util/term"
)

// SetupTTY creates a term.TTY (docker)
func SetupTTY() term.TTY {
t := term.TTY{
Out: os.Stdout,
In: os.Stdin,
}

if !t.IsTerminalIn() {
return t
}

// if we get to here, the user wants to attach stdin, wants a TTY, and In is a terminal, so we
// can safely set t.Raw to true
t.Raw = true

stdin, stdout, _ := dockerterm.StdStreams()

t.In = stdin
t.Out = stdout

return t
}