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

@@ -20,21 +20,21 @@ import (
"k8s.io/apimachinery/pkg/runtime"
)
// objectContainer is an interface for a wrapper or alias from which we
// can get a controller-runtime deserialisable value. This is used so
// that you can wrap an API type to give it other useful methods, but
// still use values of the wrapper with `client.Client`, which only
// deals with types that have been added to the schema.
type objectContainer interface {
AsClientObject() runtime.Object
// adapter is an interface for a wrapper or alias from which we can
// get a controller-runtime deserialisable value. This is used so that
// you can wrap an API type to give it other useful methods, but still
// use values of the wrapper with `client.Client`, which only deals
// with types that have been added to the schema.
type adapter interface {
asRuntimeObject() runtime.Object
}
// genericContainer is an objectContainer for any runtime.Object. Use
// this if there are no other methods needed.
type genericContainer struct {
// universalAdapter is an adapter for any runtime.Object. Use this if
// there are no other methods needed.
type universalAdapter struct {
obj runtime.Object
}
func (c genericContainer) AsClientObject() runtime.Object {
func (c universalAdapter) asRuntimeObject() runtime.Object {
return c.obj
}