Attempt to render deployments in xray apps

mine
Raphaël Pinson 2020-12-09 22:42:27 +01:00
parent cfa761a812
commit b025bd07e5
No known key found for this signature in database
GPG Key ID: A1AAC49E10CB2A8D
3 changed files with 46 additions and 3 deletions

1
go.mod
View File

@ -16,6 +16,7 @@ require (
github.com/derailed/tview v0.4.9
github.com/drone/envsubst v1.0.2 // indirect
github.com/fatih/color v1.10.0
github.com/fatih/structs v1.1.0
github.com/fsnotify/fsnotify v1.4.9
github.com/fvbommel/sortorder v1.0.2
github.com/gdamore/tcell v1.1.2 // indirect

2
go.sum
View File

@ -244,6 +244,8 @@ github.com/fatih/camelcase v1.0.0/go.mod h1:yN2Sb0lFhZJUdVvtELVWefmrXpuZESvPmqwo
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg=
github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjrss6TZTdY2VfCqZPbv5k3iBFa2ZQ=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=

View File

@ -7,6 +7,7 @@ import (
v1alpha1 "github.com/argoproj/argo-cd/pkg/apis/application/v1alpha1"
"github.com/derailed/k9s/internal/client"
"github.com/fatih/structs"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
@ -36,11 +37,30 @@ func (a *Application) Render(ctx context.Context, ns string, o interface{}) erro
root := NewTreeNode("argoproj.io/v1alpha1/applications", client.FQN(app.Namespace, app.Name))
ctx = context.WithValue(ctx, KeyParent, root)
var re ApplicationResource
var ar ApplicationResource
var dp Deployment
for _, res := range app.Status.Resources {
if err := re.Render(ctx, app.Namespace, res); err != nil {
return err
gvr := gvkToGvr(res.GroupVersionKind())
switch gvr.String() {
case "apps/v1/deployments":
if err := dp.Render(ctx, app.Namespace, toUnstructured(res)); err != nil {
return err
}
default:
if err := ar.Render(ctx, app.Namespace, res); err != nil {
return err
}
}
/*
if meta, ok := model.Registry[gvr.String()]; ok {
if meta.TreeRenderer != nil {
if err := meta.TreeRenderer.Render(ctx, app.Namespace, res); err != nil {
return err
}
}
}
*/
}
gvr, nsID := "v1/namespaces", client.FQN(client.ClusterScope, app.Namespace)
@ -61,3 +81,23 @@ func gvkToGvr(gvk schema.GroupVersionKind) client.GVR {
}
return client.NewGVR(gvr)
}
func toUnstructured(in interface{}) *unstructured.Unstructured {
return &unstructured.Unstructured{
Object: structs.Map(in),
}
/*
var inInterface map[string]interface{}
inrec, _ := json.Marshal(in)
json.Unmarshal(inrec, &inInterface)
// iterate through inrecs
for field, val := range inInterface {
fmt.Println("KV Pair: ", field, val)
}
return &unstructured.Unstructured{
Object: inInterface,
}
*/
}