fix issue #790
parent
793ca2ba76
commit
4a82b999ab
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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{},
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
}
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
|
|
@ -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()))
|
||||
}
|
||||
|
|
@ -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")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Reference in New Issue