mirror of https://github.com/fluxcd/cli-utils.git
Merge pull request #177 from mortent/PrintAdapterToApplyTask
Move the printer adapter into the ApplyTask
This commit is contained in:
commit
d246e8e8f3
|
|
@ -409,12 +409,6 @@ func (a *Applier) Run(ctx context.Context, options Options) <-chan event.Event {
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
defer close(eventChannel)
|
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
|
// This provides us with a slice of all the objects that will be
|
||||||
// applied to the cluster. This takes care of ordering resources
|
// applied to the cluster. This takes care of ordering resources
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"k8s.io/apimachinery/pkg/api/meta"
|
"k8s.io/apimachinery/pkg/api/meta"
|
||||||
"k8s.io/cli-runtime/pkg/resource"
|
"k8s.io/cli-runtime/pkg/resource"
|
||||||
"k8s.io/kubectl/pkg/cmd/apply"
|
"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/info"
|
||||||
"sigs.k8s.io/cli-utils/pkg/apply/taskrunner"
|
"sigs.k8s.io/cli-utils/pkg/apply/taskrunner"
|
||||||
"sigs.k8s.io/cli-utils/pkg/object"
|
"sigs.k8s.io/cli-utils/pkg/object"
|
||||||
|
|
@ -45,7 +46,7 @@ type applyOptions interface {
|
||||||
func (a *ApplyTask) Start(taskContext *taskrunner.TaskContext) {
|
func (a *ApplyTask) Start(taskContext *taskrunner.TaskContext) {
|
||||||
go func() {
|
go func() {
|
||||||
// Update the dry-run field on the Applier.
|
// Update the dry-run field on the Applier.
|
||||||
a.setDryRunField()
|
a.setApplyOptionsFields(taskContext.EventChannel())
|
||||||
// Set the client and mapping fields on the provided
|
// Set the client and mapping fields on the provided
|
||||||
// infos so they can be applied to the cluster.
|
// infos so they can be applied to the cluster.
|
||||||
err := a.InfoHelper.UpdateInfos(a.Objects)
|
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 {
|
if ao, ok := a.ApplyOptions.(*apply.ApplyOptions); ok {
|
||||||
ao.DryRun = a.DryRun
|
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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
// Copyright 2019 The Kubernetes Authors.
|
// Copyright 2019 The Kubernetes Authors.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
package apply
|
package task
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
// Copyright 2019 The Kubernetes Authors.
|
// Copyright 2019 The Kubernetes Authors.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
package apply
|
package task
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
Loading…
Reference in New Issue