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:
@@ -45,8 +45,8 @@ func init() {
|
||||
}
|
||||
|
||||
type deleteCommand struct {
|
||||
humanKind string // the kind being deleted, lowercase and spaced e.g., "image policy"
|
||||
container objectContainer // for getting the value, and later deleting it
|
||||
humanKind string // the kind being deleted, lowercase and spaced e.g., "image policy"
|
||||
adapter adapter // for getting the value, and later deleting it
|
||||
}
|
||||
|
||||
func (del deleteCommand) run(cmd *cobra.Command, args []string) error {
|
||||
@@ -68,7 +68,7 @@ func (del deleteCommand) run(cmd *cobra.Command, args []string) error {
|
||||
Name: name,
|
||||
}
|
||||
|
||||
err = kubeClient.Get(ctx, namespacedName, del.container.AsClientObject())
|
||||
err = kubeClient.Get(ctx, namespacedName, del.adapter.asRuntimeObject())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -84,7 +84,7 @@ func (del deleteCommand) run(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
logger.Actionf("deleting %s %s in %s namespace", del.humanKind, name, namespace)
|
||||
err = kubeClient.Delete(ctx, del.container.AsClientObject())
|
||||
err = kubeClient.Delete(ctx, del.adapter.asRuntimeObject())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user