diff --git a/internal/model/registry.go b/internal/model/registry.go index cb0948d7..9ed07953 100644 --- a/internal/model/registry.go +++ b/internal/model/registry.go @@ -207,7 +207,7 @@ var Registry = map[string]ResourceMeta{ // ArgoCD... "argoproj.io/v1alpha1/applications": { - //Renderer: &render.Application{}, + Renderer: &render.Application{}, TreeRenderer: &xray.Application{}, }, } diff --git a/internal/render/application.go b/internal/render/application.go new file mode 100644 index 00000000..01496688 --- /dev/null +++ b/internal/render/application.go @@ -0,0 +1,53 @@ +package render + +import ( + "fmt" + + "github.com/argoproj/argo-cd/pkg/apis/application/v1alpha1" + "github.com/derailed/k9s/internal/client" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + "k8s.io/apimachinery/pkg/runtime" +) + +// Application renders an ArgoCD Application to screen. +type Application struct{} + +// ColorerFunc colors a resource row. +func (Application) ColorerFunc() ColorerFunc { + return DefaultColorer +} + +// Header returns a header row. +func (Application) Header(ns string) Header { + return Header{ + HeaderColumn{Name: "NAME"}, + HeaderColumn{Name: "SYNC STATUS"}, + HeaderColumn{Name: "HEALTH STATUS"}, + HeaderColumn{Name: "REVISION"}, + HeaderColumn{Name: "AGE", Time: true, Decorator: AgeDecorator}, + } +} + +// Render renders a K8s resource to screen. +func (Application) Render(o interface{}, ns string, r *Row) error { + raw, ok := o.(*unstructured.Unstructured) + if !ok { + return fmt.Errorf("Expected Application, but got %T", o) + } + var app v1alpha1.Application + err := runtime.DefaultUnstructuredConverter.FromUnstructured(raw.Object, &app) + if err != nil { + return err + } + + r.ID = client.MetaFQN(app.ObjectMeta) + r.Fields = Fields{ + app.Name, + string(app.Status.Sync.Status), + string(app.Status.Health.Status), + string(app.Status.Sync.Revision), + toAge(app.ObjectMeta.CreationTimestamp), + } + + return nil +}