Factor out upsert and upsertAndWait

It's a common pattern in the create commands to construct a value,
then (if not exporting it) upsert it and wait for it to
reconcile. This commit factors `upsert`, which does the update/insert
bit, and `upsertAndWait`, which does the whole thing.

Since these output messages, they are methods of `apiType` (previously
`names`), so that they have access to the name of the kind they are
operating on.

Signed-off-by: Michael Bridgen <michael@weave.works>
This commit is contained in:
Michael Bridgen
2020-12-08 18:17:36 +00:00
parent 3b9b2cbe9f
commit 0e35c209d9
23 changed files with 138 additions and 202 deletions

View File

@ -25,7 +25,7 @@ import (
// `"image repository"`), to be interpolated into output. It's
// convenient to package these up ahead of time, then the command
// implementation can pick whichever it wants to use.
type names struct {
type apiType struct {
kind, humanKind string
}
@ -47,3 +47,18 @@ type universalAdapter struct {
func (c universalAdapter) asRuntimeObject() runtime.Object {
return c.obj
}
// named is for adapters that have Name and Namespace fields, which
// are sometimes handy to get hold of. ObjectMeta implements these, so
// they shouldn't need any extra work.
type named interface {
GetName() string
GetNamespace() string
SetName(string)
SetNamespace(string)
}
func copyName(target, source named) {
target.SetName(source.GetName())
target.SetNamespace(source.GetNamespace())
}