mirror of
https://github.com/fluxcd/flux2.git
synced 2025-10-29 15:28:04 +08:00
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:
@ -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())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user