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

Standardise the names of types

Most commands use either a kind, or a more readable spelling of a
kind, in their output. To make this easier, this centralises the
definition of those names in one place, and lets the command
implementations choose whichever they need.

Signed-off-by: Michael Bridgen <michael@weave.works>
This commit is contained in:
Michael Bridgen
2020-12-08 15:20:41 +00:00
parent d55d185044
commit 22a5ac7f0f
19 changed files with 75 additions and 50 deletions

View File

@@ -44,8 +44,8 @@ func init() {
}
type reconcileCommand struct {
humanKind string
adapter reconcilable
names
object reconcilable
}
type reconcilable interface {
@@ -65,7 +65,7 @@ type reconcilable interface {
func (reconcile reconcileCommand) run(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return fmt.Errorf("%s name is required", reconcile.humanKind)
return fmt.Errorf("%s name is required", reconcile.kind)
}
name := args[0]
@@ -82,33 +82,33 @@ func (reconcile reconcileCommand) run(cmd *cobra.Command, args []string) error {
Name: name,
}
err = kubeClient.Get(ctx, namespacedName, reconcile.adapter.asRuntimeObject())
err = kubeClient.Get(ctx, namespacedName, reconcile.object.asRuntimeObject())
if err != nil {
return err
}
if reconcile.adapter.isSuspended() {
if reconcile.object.isSuspended() {
return fmt.Errorf("resource is suspended")
}
logger.Actionf("annotating %s %s in %s namespace", reconcile.humanKind, name, namespace)
if err := requestReconciliation(ctx, kubeClient, namespacedName, reconcile.adapter); err != nil {
logger.Actionf("annotating %s %s in %s namespace", reconcile.kind, name, namespace)
if err := requestReconciliation(ctx, kubeClient, namespacedName, reconcile.object); err != nil {
return err
}
logger.Successf("%s annotated", reconcile.humanKind)
logger.Successf("%s annotated", reconcile.kind)
lastHandledReconcileAt := reconcile.adapter.lastHandledReconcileRequest()
logger.Waitingf("waiting for %s reconciliation", reconcile.humanKind)
lastHandledReconcileAt := reconcile.object.lastHandledReconcileRequest()
logger.Waitingf("waiting for %s reconciliation", reconcile.kind)
if err := wait.PollImmediate(pollInterval, timeout,
reconciliationHandled(ctx, kubeClient, namespacedName, reconcile.adapter, lastHandledReconcileAt)); err != nil {
reconciliationHandled(ctx, kubeClient, namespacedName, reconcile.object, lastHandledReconcileAt)); err != nil {
return err
}
logger.Successf("%s reconciliation completed", reconcile.humanKind)
logger.Successf("%s reconciliation completed", reconcile.kind)
if apimeta.IsStatusConditionFalse(*reconcile.adapter.GetStatusConditions(), meta.ReadyCondition) {
return fmt.Errorf("%s reconciliation failed", reconcile.humanKind)
if apimeta.IsStatusConditionFalse(*reconcile.object.GetStatusConditions(), meta.ReadyCondition) {
return fmt.Errorf("%s reconciliation failed", reconcile.kind)
}
logger.Successf(reconcile.adapter.successMessage())
logger.Successf(reconcile.object.successMessage())
return nil
}