describe resource fix #393

mine
derailed 2019-10-30 16:27:35 -06:00
parent ebbda14404
commit 90161d6e39
5 changed files with 33 additions and 10 deletions

1
go.sum
View File

@ -130,6 +130,7 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO
github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/imdario/mergo v0.3.7 h1:Y+UAYTZ7gDEuOfhxKWy+dvb5dRQ6rJjFSdX2HZY1/gI= github.com/imdario/mergo v0.3.7 h1:Y+UAYTZ7gDEuOfhxKWy+dvb5dRQ6rJjFSdX2HZY1/gI=
github.com/imdario/mergo v0.3.7/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= github.com/imdario/mergo v0.3.7/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/json-iterator/go v0.0.0-20180612202835-f2b4162afba3/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v0.0.0-20180612202835-f2b4162afba3/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=

View File

@ -6,6 +6,7 @@ import (
"regexp" "regexp"
"strings" "strings"
"github.com/rs/zerolog/log"
"k8s.io/apimachinery/pkg/api/meta" "k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/restmapper" "k8s.io/client-go/restmapper"
@ -48,12 +49,12 @@ func mustHomeDir() string {
// ResourceFor produces a rest mapping from a given resource. // ResourceFor produces a rest mapping from a given resource.
// Support full res name ie deployment.v1.apps. // Support full res name ie deployment.v1.apps.
func (r *RestMapper) ResourceFor(resourceArg string) (*meta.RESTMapping, error) { func (r *RestMapper) ResourceFor(resourceArg, kind string) (*meta.RESTMapping, error) {
res, err := r.resourceFor(resourceArg) res, err := r.resourceFor(resourceArg)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return r.toRESTMapping(res, resourceArg), nil return r.toRESTMapping(res, kind), nil
} }
func (r *RestMapper) resourceFor(resourceArg string) (schema.GroupVersionResource, error) { func (r *RestMapper) resourceFor(resourceArg string) (schema.GroupVersionResource, error) {
@ -72,6 +73,7 @@ func (r *RestMapper) resourceFor(resourceArg string) (schema.GroupVersionResourc
} }
fullGVR, gr := schema.ParseResourceArg(strings.ToLower(resourceArg)) fullGVR, gr := schema.ParseResourceArg(strings.ToLower(resourceArg))
log.Debug().Msgf("GVR %#v -- %#v", fullGVR, gr)
if fullGVR != nil { if fullGVR != nil {
return mapper.ResourceFor(*fullGVR) return mapper.ResourceFor(*fullGVR)
} }
@ -86,11 +88,15 @@ func (r *RestMapper) resourceFor(resourceArg string) (schema.GroupVersionResourc
return gvr, nil return gvr, nil
} }
func (*RestMapper) toRESTMapping(gvr schema.GroupVersionResource, res string) *meta.RESTMapping { func (*RestMapper) toRESTMapping(gvr schema.GroupVersionResource, kind string) *meta.RESTMapping {
return &meta.RESTMapping{ return &meta.RESTMapping{
Resource: gvr, Resource: gvr,
GroupVersionKind: schema.GroupVersionKind{Group: gvr.Group, Version: gvr.Version, Kind: res}, GroupVersionKind: schema.GroupVersionKind{
Scope: RestMapping, Group: gvr.Group,
Version: gvr.Version,
Kind: kind,
},
Scope: RestMapping,
} }
} }

View File

@ -14,7 +14,7 @@ import (
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
genericprinters "k8s.io/cli-runtime/pkg/printers" genericprinters "k8s.io/cli-runtime/pkg/printers"
"k8s.io/kubectl/pkg/describe" "k8s.io/kubectl/pkg/describe"
versioned "k8s.io/kubectl/pkg/describe/versioned" "k8s.io/kubectl/pkg/describe/versioned"
mv1beta1 "k8s.io/metrics/pkg/apis/metrics/v1beta1" mv1beta1 "k8s.io/metrics/pkg/apis/metrics/v1beta1"
) )
@ -139,7 +139,20 @@ func (b *Base) List(ns string) (Columnars, error) {
// Describe a given resource. // Describe a given resource.
func (b *Base) Describe(gvr, pa string) (string, error) { func (b *Base) Describe(gvr, pa string) (string, error) {
mapper := k8s.RestMapper{Connection: b.Connection} mapper := k8s.RestMapper{Connection: b.Connection}
mapping, err := mapper.ResourceFor(k8s.GVR(gvr).ResName()) m, err := mapper.ToRESTMapper()
if err != nil {
log.Error().Err(err).Msgf("No REST mapper for resource %s", gvr)
return "", err
}
GVR := k8s.GVR(gvr)
gvk, err := m.KindFor(GVR.AsGVR())
if err != nil {
log.Error().Err(err).Msgf("No GVK for resource %s", gvr)
return "", err
}
mapping, err := mapper.ResourceFor(GVR.ResName(), gvk.Kind)
if err != nil { if err != nil {
log.Error().Err(err).Msgf("Unable to find mapper for %s %s", gvr, pa) log.Error().Err(err).Msgf("Unable to find mapper for %s %s", gvr, pa)
return "", err return "", err

View File

@ -36,7 +36,7 @@ func (v *nodeView) sortColCmd(col int, asc bool) func(evt *tcell.EventKey) *tcel
} }
func (v *nodeView) showPods(app *appView, _, _, sel string) { func (v *nodeView) showPods(app *appView, _, _, sel string) {
showPods(app, app.Config.ActiveNamespace(), "", "spec.nodeName="+sel, v.backCmd) showPods(app, "", "", "spec.nodeName="+sel, v.backCmd)
} }
func (v *nodeView) backCmd(evt *tcell.EventKey) *tcell.EventKey { func (v *nodeView) backCmd(evt *tcell.EventKey) *tcell.EventKey {
@ -54,7 +54,6 @@ func showPods(app *appView, ns, labelSel, fieldSel string, a ui.ActionHandler) {
pv := newPodView("Pod", "v1/pods", app, list) pv := newPodView("Pod", "v1/pods", app, list)
pv.setColorerFn(podColorer) pv.setColorerFn(podColorer)
// pv.setExtraActionsFn(func(aa ui.KeyActions) {
pv.masterPage().SetActions(ui.KeyActions{ pv.masterPage().SetActions(ui.KeyActions{
tcell.KeyEsc: ui.NewKeyAction("Back", a, true), tcell.KeyEsc: ui.NewKeyAction("Back", a, true),
}) })

View File

@ -224,6 +224,7 @@ func (v *resourceView) defaultEnter(app *appView, ns, _, selection string) {
return return
} }
log.Debug().Msgf("!!!!!! NAME %s", v.list.GetName())
yaml, err := v.list.Resource().Describe(v.gvr, selection) yaml, err := v.list.Resource().Describe(v.gvr, selection)
if err != nil { if err != nil {
v.app.Flash().Errf("Describe command failed: %s", err) v.app.Flash().Errf("Describe command failed: %s", err)
@ -236,6 +237,7 @@ func (v *resourceView) defaultEnter(app *appView, ns, _, selection string) {
details.SetTextColor(v.app.Styles.FgColor()) details.SetTextColor(v.app.Styles.FgColor())
details.SetText(colorizeYAML(v.app.Styles.Views().Yaml, yaml)) details.SetText(colorizeYAML(v.app.Styles.Views().Yaml, yaml))
details.ScrollToBeginning() details.ScrollToBeginning()
v.app.SetHints(details.hints())
v.switchPage("details") v.switchPage("details")
} }
@ -266,6 +268,8 @@ func (v *resourceView) viewCmd(evt *tcell.EventKey) *tcell.EventKey {
details.SetTextColor(v.app.Styles.FgColor()) details.SetTextColor(v.app.Styles.FgColor())
details.SetText(colorizeYAML(v.app.Styles.Views().Yaml, raw)) details.SetText(colorizeYAML(v.app.Styles.Views().Yaml, raw))
details.ScrollToBeginning() details.ScrollToBeginning()
v.app.SetHints(details.hints())
v.switchPage("details") v.switchPage("details")
return nil return nil