1
0
mirror of synced 2026-02-13 13:06:56 +00:00

Centralise adapter types

Since the generic commands tend to share a few of the methods they
need -- at least AsClientObject -- it's worth having just one wrapper
struct for each API type, and adding methods to it where necessary.

For the automation types, I put these in auto.go.

While doing this I also did some tidying:

 - I changed the name of the wrappers to `<type>Adapter`, and the
   generic adapter to `universalAdapter` (it's only needed for delete,
   so far).

 - I de-exported and renamed some interface methods e.g.,
   `exportItem`. They aren't needed outside the package.

Signed-off-by: Michael Bridgen <michael@weave.works>
This commit is contained in:
Michael Bridgen
2020-12-07 17:30:41 +00:00
parent f316aff2d3
commit 2bb09697ce
14 changed files with 167 additions and 170 deletions

View File

@@ -45,10 +45,10 @@ func init() {
}
type summarisable interface {
objectContainer
Len() int
SummariseAt(i int, includeNamespace bool) []string
Headers(includeNamespace bool) []string
adapter
len() int
summariseItem(i int, includeNamespace bool) []string
headers(includeNamespace bool) []string
}
// --- these help with implementations of summarisable
@@ -92,20 +92,20 @@ func (get getCommand) run(cmd *cobra.Command, args []string) error {
if !allNamespaces {
listOpts = append(listOpts, client.InNamespace(namespace))
}
err = kubeClient.List(ctx, get.list.AsClientObject(), listOpts...)
err = kubeClient.List(ctx, get.list.asRuntimeObject(), listOpts...)
if err != nil {
return err
}
if get.list.Len() == 0 {
if get.list.len() == 0 {
logger.Failuref("no imagerepository objects found in %s namespace", namespace)
return nil
}
header := get.list.Headers(allNamespaces)
header := get.list.headers(allNamespaces)
var rows [][]string
for i := 0; i < get.list.Len(); i++ {
row := get.list.SummariseAt(i, allNamespaces)
for i := 0; i < get.list.len(); i++ {
row := get.list.summariseItem(i, allNamespaces)
rows = append(rows, row)
}
utils.PrintTable(os.Stdout, header, rows)