From 092f5b23d2e5dac186398cdfd774db8a33d46f3d Mon Sep 17 00:00:00 2001 From: Mariell Hoversholm Date: Wed, 13 Nov 2024 16:32:02 +0100 Subject: [PATCH] feat: output type and target in tabular format This is the `kubectl get` output. --- pkg/apis/provisioning/v0alpha1/register.go | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/pkg/apis/provisioning/v0alpha1/register.go b/pkg/apis/provisioning/v0alpha1/register.go index f6d8e4bcd46..d9342dc85c6 100644 --- a/pkg/apis/provisioning/v0alpha1/register.go +++ b/pkg/apis/provisioning/v0alpha1/register.go @@ -2,12 +2,14 @@ package v0alpha1 import ( "errors" + "fmt" "time" "github.com/grafana/grafana/pkg/apimachinery/utils" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/klog/v2" ) const ( @@ -26,15 +28,37 @@ var RepositoryResourceInfo = utils.NewResourceInfo(GROUP, VERSION, {Name: "Created At", Type: "date"}, // TODO: Add more here when I figure out the model... // I think this is just the table you get in `kubectl get`. It shouldn't deal with anything around storage. + {Name: "Type", Type: "string"}, + {Name: "Target", Type: "string"}, }, Reader: func(obj any) ([]interface{}, error) { m, ok := obj.(*Repository) if !ok { return nil, errors.New("expected Repository") } + + var typ, target string + if !m.Spec.GitHub.IsEmpty() { + typ = "github" + // TODO: Enterprise GH?? + target = fmt.Sprintf("%s/%s", m.Spec.GitHub.Owner, m.Spec.GitHub.Repository) + } else if !m.Spec.Local.IsEmpty() { + typ = "local" + target = m.Spec.Local.Path + } else if !m.Spec.S3.IsEmpty() { + typ = "s3" + // TODO: Can bucket URLs include sensitive info? + target = m.Spec.S3.Bucket + } else { + klog.InfoS("we have a repository with no known tabular converter", + "name", m.Name, "namespace", m.Namespace) + } + return []interface{}{ m.Name, m.CreationTimestamp.UTC().Format(time.RFC3339), + typ, + target, }, nil }, })