mine
derailed 2020-07-02 22:10:16 -06:00
parent 793ca2ba76
commit 4a82b999ab
11 changed files with 49 additions and 17 deletions

View File

@ -231,6 +231,7 @@ func (a *APIClient) CheckConnectivity() bool {
a.connOK = false
return a.connOK
}
cfg.Timeout = defaultCallTimeoutDuration
client, err := kubernetes.NewForConfig(cfg)
if err != nil {
log.Error().Err(err).Msgf("Unable to connect to api server")
@ -278,8 +279,7 @@ func (a *APIClient) HasMetrics() bool {
timeout, err := time.ParseDuration(*a.config.flags.Timeout)
if err != nil {
log.Error().Err(err).Msgf("parsing duration")
return false
timeout = defaultCallTimeoutDuration
}
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

View File

@ -18,7 +18,6 @@ const (
defaultQPS = 50
defaultBurst = 50
defaultCallTimeoutDuration time.Duration = 5 * time.Second
defaultCallTimeout = "5s"
)
// Config tracks a kubernetes configuration.
@ -32,15 +31,6 @@ type Config struct {
// NewConfig returns a new k8s config or an error if the flags are invalid.
func NewConfig(f *genericclioptions.ConfigFlags) *Config {
timeout := defaultCallTimeout
if f.Timeout == nil {
f.Timeout = &timeout
} else {
_, err := time.ParseDuration(*f.Timeout)
if err != nil {
f.Timeout = &timeout
}
}
return &Config{
flags: f,
mutex: &sync.RWMutex{},

19
internal/dao/dir_test.go Normal file
View File

@ -0,0 +1,19 @@
package dao_test
import (
"context"
"testing"
"github.com/derailed/k9s/internal"
"github.com/derailed/k9s/internal/dao"
"github.com/stretchr/testify/assert"
)
func TestNewDir(t *testing.T) {
d := dao.NewDir(nil)
ctx := context.WithValue(context.Background(), internal.KeyPath, "testdata/dir")
oo, err := d.List(ctx, "")
assert.Nil(t, err)
assert.Equal(t, 2, len(oo))
}

View File

@ -127,6 +127,7 @@ func (p *Pod) Logs(path string, opts *v1.PodLogOptions) (*restclient.Request, er
if err != nil {
return nil, err
}
ns, n := client.Namespaced(path)
return dial.CoreV1().Pods(ns).GetLogs(n, opts), nil
}

0
internal/dao/testdata/dir/a.yml vendored Normal file
View File

0
internal/dao/testdata/dir/a/b.yml vendored Normal file
View File

View File

@ -161,7 +161,6 @@ func (l *Log) ClearFilter() {
// Filter filters th:e model using either fuzzy or regexp.
func (l *Log) Filter(q string) {
log.Debug().Msgf("Filter %q", q)
l.mx.Lock()
defer l.mx.Unlock()

16
internal/view/dir_test.go Normal file
View File

@ -0,0 +1,16 @@
package view_test
import (
"testing"
"github.com/derailed/k9s/internal/view"
"github.com/stretchr/testify/assert"
)
func TestDir(t *testing.T) {
v := view.NewDir("/fred")
assert.Nil(t, v.Init(makeCtx()))
assert.Equal(t, "Directory", v.Name())
assert.Equal(t, 7, len(v.Hints()))
}

View File

@ -243,13 +243,14 @@ func (l *Log) Logs() *Details {
}
// EOL tracks end of lines.
var EOL = []byte("\n")
var EOL = []byte{'\n'}
// Flush write logs to viewer.
func (l *Log) Flush(lines dao.LogItems) {
showTime := l.Indicator().showTime
log.Debug().Msgf("Flushing %d", len(lines))
ll := make([][]byte, len(lines))
lines.Render(showTime, ll)
lines.Render(l.Indicator().showTime, ll)
_, _ = l.ansiWriter.Write(EOL)
if _, err := l.ansiWriter.Write(bytes.Join(ll, EOL)); err != nil {
log.Error().Err(err).Msgf("write log failed")
}

View File

@ -66,7 +66,7 @@ func TestLogTimestamp(t *testing.T) {
l.Logs().Clear()
l.Flush(buff)
assert.Equal(t, fmt.Sprintf("%-30s %s", "ttt", "fred/blee:c1 Testing 1, 2, 3"), l.Logs().GetText(true))
assert.Equal(t, fmt.Sprintf("\n%-30s %s", "ttt", "fred/blee:c1 Testing 1, 2, 3"), l.Logs().GetText(true))
assert.Equal(t, 2, list.change)
assert.Equal(t, 2, list.clear)
assert.Equal(t, 0, list.fail)

View File

@ -11,6 +11,12 @@ import (
)
func init() {
dao.MetaAccess.RegisterMeta("dir", metav1.APIResource{
Name: "dir",
SingularName: "dir",
Kind: "Directory",
Categories: []string{"k9s"},
})
dao.MetaAccess.RegisterMeta("v1/pods", metav1.APIResource{
Name: "pods",
SingularName: "pod",