feat: output type and target in tabular format

This is the `kubectl get` output.
This commit is contained in:
Mariell Hoversholm
2024-11-13 16:32:02 +01:00
parent 5451c4e45c
commit 092f5b23d2
@@ -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
},
})