From b76b6e7563e1e5074765909702ced88c91206fea Mon Sep 17 00:00:00 2001 From: Morten Torkildsen Date: Fri, 22 May 2020 14:16:38 -0700 Subject: [PATCH] Move the printer adapter into the ApplyTask --- pkg/apply/applier.go | 6 ------ pkg/apply/task/apply_task.go | 11 +++++++++-- pkg/apply/{ => task}/printer_adapter.go | 2 +- pkg/apply/{ => task}/printer_adapter_test.go | 2 +- 4 files changed, 11 insertions(+), 10 deletions(-) rename pkg/apply/{ => task}/printer_adapter.go (99%) rename pkg/apply/{ => task}/printer_adapter_test.go (98%) diff --git a/pkg/apply/applier.go b/pkg/apply/applier.go index bbe6cdd..6b7081b 100644 --- a/pkg/apply/applier.go +++ b/pkg/apply/applier.go @@ -413,12 +413,6 @@ func (a *Applier) Run(ctx context.Context, options Options) <-chan event.Event { go func() { defer close(eventChannel) - adapter := &KubectlPrinterAdapter{ - ch: eventChannel, - } - // The adapter is used to intercept what is meant to be printing - // in the ApplyOptions, and instead turn those into events. - a.ApplyOptions.ToPrinter = adapter.toPrinterFunc() // This provides us with a slice of all the objects that will be // applied to the cluster. This takes care of ordering resources diff --git a/pkg/apply/task/apply_task.go b/pkg/apply/task/apply_task.go index 6c6b02d..aa283d0 100644 --- a/pkg/apply/task/apply_task.go +++ b/pkg/apply/task/apply_task.go @@ -7,6 +7,7 @@ import ( "k8s.io/apimachinery/pkg/api/meta" "k8s.io/cli-runtime/pkg/resource" "k8s.io/kubectl/pkg/cmd/apply" + "sigs.k8s.io/cli-utils/pkg/apply/event" "sigs.k8s.io/cli-utils/pkg/apply/info" "sigs.k8s.io/cli-utils/pkg/apply/taskrunner" "sigs.k8s.io/cli-utils/pkg/object" @@ -45,7 +46,7 @@ type applyOptions interface { func (a *ApplyTask) Start(taskContext *taskrunner.TaskContext) { go func() { // Update the dry-run field on the Applier. - a.setDryRunField() + a.setApplyOptionsFields(taskContext.EventChannel()) // Set the client and mapping fields on the provided // infos so they can be applied to the cluster. err := a.InfoHelper.UpdateInfos(a.Objects) @@ -82,9 +83,15 @@ func (a *ApplyTask) sendTaskResult(taskContext *taskrunner.TaskContext, err erro } } -func (a *ApplyTask) setDryRunField() { +func (a *ApplyTask) setApplyOptionsFields(eventChannel chan event.Event) { if ao, ok := a.ApplyOptions.(*apply.ApplyOptions); ok { ao.DryRun = a.DryRun + adapter := &KubectlPrinterAdapter{ + ch: eventChannel, + } + // The adapter is used to intercept what is meant to be printing + // in the ApplyOptions, and instead turn those into events. + ao.ToPrinter = adapter.toPrinterFunc() } } diff --git a/pkg/apply/printer_adapter.go b/pkg/apply/task/printer_adapter.go similarity index 99% rename from pkg/apply/printer_adapter.go rename to pkg/apply/task/printer_adapter.go index 260b39b..810fb4f 100644 --- a/pkg/apply/printer_adapter.go +++ b/pkg/apply/task/printer_adapter.go @@ -1,7 +1,7 @@ // Copyright 2019 The Kubernetes Authors. // SPDX-License-Identifier: Apache-2.0 -package apply +package task import ( "fmt" diff --git a/pkg/apply/printer_adapter_test.go b/pkg/apply/task/printer_adapter_test.go similarity index 98% rename from pkg/apply/printer_adapter_test.go rename to pkg/apply/task/printer_adapter_test.go index 4e08498..4848188 100644 --- a/pkg/apply/printer_adapter_test.go +++ b/pkg/apply/task/printer_adapter_test.go @@ -1,7 +1,7 @@ // Copyright 2019 The Kubernetes Authors. // SPDX-License-Identifier: Apache-2.0 -package apply +package task import ( "bytes"